support for stripping off frontmatter
This commit is contained in:
2
src/bin/strip-frontmatter.ts
Normal file
2
src/bin/strip-frontmatter.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
console.log('strip-frontmatter');
|
18
src/frontmatter.ts
Normal file
18
src/frontmatter.ts
Normal 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 };
|
||||
}
|
@@ -1,2 +1,3 @@
|
||||
|
||||
export * from './render';
|
||||
export { process_frontmatter } from './frontmatter';
|
||||
export { render_markdown_to_html, MarkdownExtension, MarkdownOptions } from './render';
|
||||
|
Reference in New Issue
Block a user