Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"remark-parse": "^11.0.0",
"unified": "^11.0.5",
"unist-builder": "^4.0.0",
"unist-util-map": "^4.0.0",
"unist-util-parents": "^3.0.0",
"vitepress": "^1.6.3",
"vitepress-plugin-pagefind": "^0.4.13",
Expand Down
50 changes: 28 additions & 22 deletions util/generate_man.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import remarkMan from 'remark-man'
import remarkParse from 'remark-parse'
import { unified } from 'unified'
import { u } from 'unist-builder'
import { map } from 'unist-util-map'
import { parents } from 'unist-util-parents'
import { SKIP, visit } from 'unist-util-visit'

Expand Down Expand Up @@ -155,27 +154,34 @@ const processDovecotMdPre = () => {
return tree => {
/* Go through and replace Dovecot markdown items with man-friendly
* textual equivalents. */
return map(tree, (para) => {
visit(para, 'text', (node, index, para) => {
/* if the text contains at least one tag, we need to convert
* this into an array of children that replace the parent's children. */
var result;
var newChildren = []
var pos = 0;
while ((result = includesDM.exec(node.value))) {
const pre = node.value.substr(pos, result.index - pos)
pos = result.index + result[0].length
if (pre != "")
newChildren.push({type: 'text', value: pre})
newChildren.push(...DovecotMd(result[1]))
}
if (newChildren.length != 0) {
if (pos < node.value.length)
newChildren.push({type: 'text', value: node.value.substr(pos)})
para.children = newChildren
}
})
return para
visit(tree, 'text', (node, index, parent) => {
if (!parent) return

/* If the text contains at least one tag, we need to convert
* this into an array of children that replace the parent's
* children. */
let result
const newChildren = []
let pos = 0

/* Check if there are any matches first to avoid unnecessary
* work. */
if (!includesDM.test(node.value)) return
includesDM.lastIndex = 0

while ((result = includesDM.exec(node.value))) {
const pre = node.value.substr(pos, result.index - pos)
pos = result.index + result[0].length
if (pre != "")
newChildren.push({type: 'text', value: pre})
newChildren.push(...DovecotMd(result[1]))
}
if (newChildren.length != 0) {
if (pos < node.value.length)
newChildren.push({type: 'text', value: node.value.substr(pos)})
parent.children.splice(index, 1, ...newChildren)
return [SKIP, index + newChildren.length]
}
})
}
}
Expand Down