-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathpost.ts
More file actions
30 lines (27 loc) · 1.06 KB
/
post.ts
File metadata and controls
30 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// used below to remove extra newlines in TOC lists
const endLine: string = '</a>\r?\n'
const blankLine: string = '\\s*?[\r\n]*'
const startNextLine: string = '[^\\S\r\n]*?[-\\*] <a'
const blankLineInList: RegExp = new RegExp(`(${endLine})${blankLine}(${startNextLine})`, 'mg')
export function processLiquidPost(template: string): string {
template = cleanUpListEmptyLines(template)
template = cleanUpExtraEmptyLines(template)
return template
}
function cleanUpListEmptyLines(template: string): string {
// clean up empty lines in TOC lists left by unrendered list items (due to productVersions)
// for example, remove the blank line here:
// - <a>foo</a>
//
// - <a>bar</a>
if (template.includes('</a>')) {
template = template.replace(blankLineInList, '$1$2')
}
return template
}
function cleanUpExtraEmptyLines(template: string): string {
// this removes any extra newlines left by (now resolved) liquid
// statements so that extra space doesn't mess with list numbering
template = template.replace(/(\r?\n){3}/g, '\n\n')
return template
}