support for stripping off frontmatter

This commit is contained in:
2023-04-29 17:19:34 -07:00
parent 8c33dd7a1a
commit a26588835b
6 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
console.log('strip-frontmatter');

18
src/frontmatter.ts Normal file
View File

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

View File

@@ -1,2 +1,3 @@
export * from './render';
export { process_frontmatter } from './frontmatter';
export { render_markdown_to_html, MarkdownExtension, MarkdownOptions } from './render';