mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2025-12-20 12:58:48 +00:00
Extract compile function to another file
This commit is contained in:
14
src/lang/utils/functions.js
Normal file
14
src/lang/utils/functions.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const compile = require("pug").compile
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
*/
|
||||
function pug(text) {
|
||||
let lines = text.split("\n")
|
||||
while (lines[0] === "") lines.shift()
|
||||
const indentLevel = lines[0].match(/^\t*/)[0].length
|
||||
lines = lines.map(l => l.replace(new RegExp(`^\\t{0,${indentLevel}}`), ""))
|
||||
return compile(lines.join("\n"))
|
||||
}
|
||||
|
||||
module.exports.pug = pug
|
||||
Reference in New Issue
Block a user