Skip to content

Commit

Permalink
Dynamic URLs with Jekyll syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Apr 10, 2024
1 parent 2d92d85 commit 0229311
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
const filter = require("pandoc-filter");

filter.stdio(function ({ t, c }, format, meta) {
/* Links with dynamic target: Edit this page [here](--editurl) */
if (t === "Link" && c[2][0].startsWith("--")) {
c[2][0] = meta[c[2][0].substring(2)].c;
return filter.Link(...c);
}
/* Links to other converted documents */
if (t === "Link" && !/^https?:\/\//.test(c[2][0])) {
c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html");
if (t === "Link") {
c[2][0] = c[2][0].replace(/{{(.*?)}}/g, function (m, p) {
return meta[p]?.c || m;
});
if (!/^https?:\/\//.test(c[2][0]))
c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html");
return filter.Link(...c);
}
});
3 changes: 3 additions & 0 deletions lib/pandoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { spawn } = require("child_process");

function pandoc({ stdin, stdout }, options = {}) {
var header = options.header || "";
delete options.header;
var footer = options.footer || "";
delete options.footer;
var mermaidOptions = { startOnLoad: false, ...options.mermaid };
Expand All @@ -26,6 +28,7 @@ function pandoc({ stdin, stdout }, options = {}) {
console.error(err.toString());
});
proc.stdout.pipe(stdout);
proc.stdin.write(header);
stdin
.on("end", function () {
proc.stdin.end(`
Expand Down

0 comments on commit 0229311

Please sign in to comment.