Expose render parse tree (#1032)

pull/1039/head
jcgurango 2024-08-15 17:45:46 +08:00 committed by GitHub
parent 46f94a9881
commit 9b88a8d694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import type { SysCallMapping } from "../../lib/plugos/system.ts";
import { parse } from "../markdown_parser/parse_tree.ts";
import type { ParseTree } from "../../plug-api/lib/tree.ts";
import { type ParseTree, renderToText } from "../../plug-api/lib/tree.ts";
import { extendedMarkdownLanguage } from "../markdown_parser/parser.ts";
export function markdownSyscalls(): SysCallMapping {
@ -8,5 +8,8 @@ export function markdownSyscalls(): SysCallMapping {
"markdown.parseMarkdown": (_ctx, text: string): ParseTree => {
return parse(extendedMarkdownLanguage, text);
},
"markdown.renderParseTree": (_ctx, tree: ParseTree): string => {
return renderToText(tree);
},
};
}

View File

@ -9,3 +9,12 @@ import type { ParseTree } from "../lib/tree.ts";
export function parseMarkdown(text: string): Promise<ParseTree> {
return syscall("markdown.parseMarkdown", text);
}
/**
* Renders a ParseTree to markdown.
* @param tree the parse tree
* @returns the rendered markdown of a passed parse tree
*/
export function renderParseTree(tree: ParseTree): Promise<string> {
return syscall("markdown.renderParseTree", tree);
}