Skip to content

Commit

Permalink
Add prepare myst script
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Jun 7, 2024
1 parent 0b1a335 commit 77dc6c4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions paper/prepare-myst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-expect-error
import { parse, stringify } from "jsr:@std/yaml";

let [frontMatter, raw] = Deno.readTextFileSync("paper.md")
.replace("---", "")
.split("---");

let data = parse(frontMatter);
// biome-ignore lint/performance/noDelete: <explanation>
delete data["affiliations"];
// biome-ignore lint/performance/noDelete: <explanation>
delete data["authors"];
// biome-ignore lint/performance/noDelete: <explanation>
delete data["tags"];
// biome-ignore lint/performance/noDelete: <explanation>
delete data["date"];

let markdown = raw
// Replace markdown images with myst images
.replace(/!\[(.*?)\]\((.*?)\)/g, (_, alt: string, filepath: string) => {
let [content, labelPart] = alt.split("\\label{");
let label = labelPart.split("}")[0];
return `\n
:::{figure} ${filepath}
:label: ${label}
${content}
:::
`;
})
// Replace markdown links with myst links
.replace("# Summary", "# Overview");

Deno.writeTextFileSync(
"main.md",
`\
---
${stringify(data)}
---
${markdown}`,
);

0 comments on commit 77dc6c4

Please sign in to comment.