mdast#YAML TypeScript Examples
The following examples show how to use
mdast#YAML.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From dendron with GNU Affero General Public License v3.0 | 7 votes |
/**
* Extract frontmatter tags from note
* @param body
* @returns
*/
static extractFMTags(body: string) {
let parsed: ReturnType<typeof parseFrontmatter> | undefined;
const noteAST = MDUtilsV5.procRemarkParse(
{ mode: ProcMode.NO_DATA },
{}
).parse(body);
visit(noteAST, [DendronASTTypes.FRONTMATTER], (frontmatter: YAML) => {
parsed = parseFrontmatter(frontmatter);
return false; // stop traversing, there is only one frontmatter
});
if (parsed) {
return getFrontmatterTags(parsed);
} else {
return [];
}
}
Example #2
Source File: yaml.ts From dendron with GNU Affero General Public License v3.0 | 6 votes |
/** Get the mapping items (`key: value`) from the frontmatter. */
export function parseFrontmatter(frontmatter: YAML | string) {
const parsed = yamlparse(
_.isString(frontmatter) ? frontmatter : frontmatter.value
);
const mapping = (parsed.children[0]?.children[1]?.children[0] as Mapping)
?.children;
return mapping;
}
Example #3
Source File: utils.ts From dendron with GNU Affero General Public License v3.0 | 6 votes |
static isYAML(node: Node): node is YAML {
return node.type === DendronASTTypes.YAML;
}