This commit is contained in:
James Brumond 2023-04-29 17:24:14 -07:00
parent a26588835b
commit cee1d41d6f
Signed by: james
GPG Key ID: 24BA25B8B303B023
4 changed files with 4 additions and 4 deletions

0
bin/strip-frontmatter Normal file → Executable file
View File

0
bin/strip-frontmatter.js Normal file → Executable file
View File

View File

@ -107,8 +107,8 @@ const options: MarkdownOptions = {
```bash ```bash
./bin/markdown2html \ ./bin/markdown2html \
--katex-macro '\foobar' '\text{foo}' '\text{bar}' \ --katex-macro '\foobar' '\text{foo} + \text{bar}' \
--katex-macro '\bazqux' '\text{baz}' '\text{qux}' --katex-macro '\bazqux' '\text{baz} + \text{qux}'
``` ```

View File

@ -1,7 +1,7 @@
import * as yaml from 'yaml'; import * as yaml from 'yaml';
export function process_frontmatter(document: string) { export function process_frontmatter(document: string, parse = true) {
if (! document.startsWith('---\n')) { if (! document.startsWith('---\n')) {
return { return {
frontmatter: null, frontmatter: null,
@ -12,7 +12,7 @@ export function process_frontmatter(document: string) {
const endIndex = document.slice(3).indexOf('\n---\n') + 3; const endIndex = document.slice(3).indexOf('\n---\n') + 3;
const frontmatterYaml = document.slice(3, endIndex); const frontmatterYaml = document.slice(3, endIndex);
const markdown = document.slice(endIndex + 4); const markdown = document.slice(endIndex + 4);
const frontmatter = yaml.parse(frontmatterYaml); const frontmatter = parse ? frontmatterYaml : yaml.parse(frontmatterYaml);
return { frontmatter, markdown }; return { frontmatter, markdown };
} }