1
0
silverbullet/plugs/core/markdown.ts
2022-04-01 17:07:08 +02:00

24 lines
660 B
TypeScript

import mdParser from "../../webapp/parser";
import { getText } from "plugos-silverbullet-syscall/editor";
export async function renderMD() {
let text = await getText();
let tree = mdParser.parser.parse(text);
let slicesToRemove: [number, number][] = [];
tree.iterate({
enter(type, from, to): false | void {
switch (type.name) {
case "Comment":
slicesToRemove.push([from, to]);
return false;
}
},
});
// console.log("output peices", JSON.stringify(tree));
slicesToRemove.reverse().forEach(([from, to]) => {
text = text.slice(0, from) + text.slice(to);
});
console.log("Clean md", text);
}