File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { parseDocument } from 'htmlparser2'
2
2
import { AnyNode , Document } from 'domhandler'
3
+ import { findAll } from 'domutils'
3
4
4
5
import { FileSpec , FileSpecType , TocFileSpec } from './types'
5
6
import { createMetadataExtractor } from './meta'
@@ -62,6 +63,13 @@ class TocContentExtractor implements ContentExtractor {
62
63
export async function extract ( contents : string , spec : FileSpec , headerRoot ?: AnyNode ) : Promise < ExtractedFile > {
63
64
const extractor = new TocContentExtractor ( spec )
64
65
const doc = parseDocument ( contents )
66
+
67
+ // We do not support headers > 3 so
68
+ // Traverse all Document's childrent and replace all h4-h6 with paragraphs
69
+ findAll ( ( n ) => [ 'h4' , 'h5' , 'h6' ] . includes ( n . tagName ) , doc . childNodes ) . forEach ( ( node ) => {
70
+ node . name = 'p'
71
+ } )
72
+
65
73
return extractor . extract ( doc , headerRoot )
66
74
}
67
75
You can’t perform that action at this time.
0 commit comments