Skip to content

Commit be4a2ca

Browse files
committed
refactor: update to fast toc parser
1 parent 4aaae84 commit be4a2ca

File tree

3 files changed

+21
-1372
lines changed

3 files changed

+21
-1372
lines changed

lib/utils/toc.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { transform } = require('@technote-space/doctoc')
1+
const { generateToc : generateTocUtils } = require('@davidwells/md-utils')
22
const { removeLeadingAndTrailingLineBreaks, escapeRegexString } = require('./regex')
33
const { findMinIndent } = require('./text')
44
const { readFile } = require('./fs')
@@ -75,8 +75,11 @@ async function generateToc({
7575
// separator: '<span>|</span>',
7676
// footer: 'end',
7777
}
78-
const t = await transform(contents, tocOptions)
79-
let outputText = t.wrappedToc || ''
78+
79+
const tocObject = generateTocUtils(contents)
80+
81+
// let outputText = t.wrappedToc || ''
82+
let outputText = tocObject.text || ''
8083

8184
if (debugFileMatch) {
8285
console.log('before firsth1 removal', outputText)
@@ -247,7 +250,9 @@ async function generateToc({
247250
// console.log('single', single)
248251
const subItems = outputText.match(findSubToc)
249252
if (subItems) {
250-
const items = subItems[0].replace(single, '').split('\n')
253+
const items = subItems[0]
254+
.replace(single, '')
255+
.split('\n')
251256
.filter(Boolean)
252257
// console.log('items', items)
253258
const finalItems = items // .slice(1, items.length)
@@ -277,7 +282,6 @@ ${outputText
277282
278283
</details>`
279284
}
280-
281285
return outputText.replace(removeLeadingAndTrailingLineBreaks, '')
282286
}
283287

0 commit comments

Comments
 (0)