@@ -6,6 +6,7 @@ const walk = require('walk-sync')
66const frontmatter = require ( '../../lib/read-frontmatter' )
77const getDocumentType = require ( '../../lib/get-document-type' )
88const languages = require ( '../../lib/languages' )
9+ const extendedMarkdownTags = Object . keys ( require ( '../../lib/liquid-tags/extended-markdown' ) . tags )
910
1011const linkString = / { % [ ^ } ] * ?l i n k .* ? ( \/ .* ?) ? % } / m
1112const linksArray = new RegExp ( linkString . source , 'gm' )
@@ -73,13 +74,19 @@ indexFiles
7374 }
7475
7576 // Remove the Table of Contents section and leave any body text before it.
76- const newContent = content
77+ let newContent = content
7778 . replace ( / ^ # * ? T a b l e o f c o n t e n t s [ \s \S ] * / im, '' )
7879 . replace ( '<div hidden>' , '' )
7980 . replace ( linksArray , '' )
81+
82+ const linesArray = newContent
8083 . split ( '\n' )
81- . filter ( line => / \S / . test ( line ) )
82- . join ( '\n' )
84+
85+ const newLinesArray = linesArray
86+ . filter ( ( line , index ) => / \S / . test ( line ) || ( extendedMarkdownTags . find ( tag => ( linesArray [ index - 1 ] && linesArray [ index - 1 ] . includes ( tag ) ) || ( linesArray [ index + 1 ] && linesArray [ index + 1 ] . includes ( tag ) ) ) ) )
87+ . filter ( line => ! / ^ < ! - - \s + ?- - > $ / m. test ( line ) )
88+
89+ newContent = newLinesArray . join ( '\n' )
8390
8491 // Index files should no longer have body content, so we write an empty string
8592 fs . writeFileSync ( indexFile , frontmatter . stringify ( newContent , data , { lineWidth : 10000 } ) )
0 commit comments