| | |
| | | removeHugoShortcode: boolean |
| | | /** Replace <figure/> with ![]() */ |
| | | replaceFigureWithMdImg: boolean |
| | | |
| | | /** Replace org latex fragments with $ and $$ */ |
| | | replaceOrgLatex: boolean |
| | | } |
| | | |
| | | const defaultOptions: Options = { |
| | |
| | | removePredefinedAnchor: true, |
| | | removeHugoShortcode: true, |
| | | replaceFigureWithMdImg: true, |
| | | replaceOrgLatex: true, |
| | | } |
| | | |
| | | const relrefRegex = new RegExp(/\[([^\]]+)\]\(\{\{< relref "([^"]+)" >\}\}\)/, "g") |
| | | const predefinedHeadingIdRegex = new RegExp(/(.*) {#(?:.*)}/, "g") |
| | | const hugoShortcodeRegex = new RegExp(/{{(.*)}}/, "g") |
| | | const figureTagRegex = new RegExp(/< ?figure src="(.*)" ?>/, "g") |
| | | // \\\\\( -> matches \\( |
| | | // (.+?) -> Lazy match for capturing the equation |
| | | // \\\\\) -> matches \\) |
| | | const inlineLatexRegex = new RegExp(/\\\\\((.+?)\\\\\)/, "g") |
| | | // (?:\\begin{equation}|\\\\\(|\\\\\[) -> start of equation |
| | | // ([\s\S]*?) -> Matches the block equation |
| | | // (?:\\\\\]|\\\\\)|\\end{equation}) -> end of equation |
| | | const blockLatexRegex = new RegExp( |
| | | /(?:\\begin{equation}|\\\\\(|\\\\\[)([\s\S]*?)(?:\\\\\]|\\\\\)|\\end{equation})/, |
| | | "g", |
| | | ) |
| | | // \$\$[\s\S]*?\$\$ -> Matches block equations |
| | | // \$.*?\$ -> Matches inline equations |
| | | const quartzLatexRegex = new RegExp(/\$\$[\s\S]*?\$\$|\$.*?\$/, "g") |
| | | |
| | | /** |
| | | * ox-hugo is an org exporter backend that exports org files to hugo-compatible |
| | |
| | | return `` |
| | | }) |
| | | } |
| | | |
| | | if (opts.replaceOrgLatex) { |
| | | src = src.toString() |
| | | src = src.replaceAll(inlineLatexRegex, (value, ...capture) => { |
| | | const [eqn] = capture |
| | | return `$${eqn}$` |
| | | }) |
| | | src = src.replaceAll(blockLatexRegex, (value, ...capture) => { |
| | | const [eqn] = capture |
| | | return `$$${eqn}$$` |
| | | }) |
| | | |
| | | // ox-hugo escapes _ as \_ |
| | | src = src.replaceAll(quartzLatexRegex, (value) => { |
| | | return value.replaceAll("\\_", "_") |
| | | }) |
| | | } |
| | | return src |
| | | }, |
| | | } |