forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost.js
More file actions
30 lines (27 loc) · 1005 Bytes
/
post.js
File metadata and controls
30 lines (27 loc) · 1005 Bytes
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 = '</a>\r?\n'
const blankLine = '\\s*?[\r\n]*'
const startNextLine = '[^\\S\r\n]*?[-\\*] <a'
const blankLineInList = new RegExp(`(${endLine})${blankLine}(${startNextLine})`, 'mg')
export function processLiquidPost(template) {
template = cleanUpListEmptyLines(template)
template = cleanUpExtraEmptyLines(template)
return template
}
function cleanUpListEmptyLines(template) {
// 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) {
// 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
}