diff --git a/common/syscalls/markdown.ts b/common/syscalls/markdown.ts index 17475fe1..5c5a5f65 100644 --- a/common/syscalls/markdown.ts +++ b/common/syscalls/markdown.ts @@ -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); + }, }; } diff --git a/plug-api/syscalls/markdown.ts b/plug-api/syscalls/markdown.ts index fa14614a..e5f4e5cf 100644 --- a/plug-api/syscalls/markdown.ts +++ b/plug-api/syscalls/markdown.ts @@ -9,3 +9,12 @@ import type { ParseTree } from "../lib/tree.ts"; export function parseMarkdown(text: string): Promise { 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 { + return syscall("markdown.renderParseTree", tree); +}