1
0
silverbullet/plugs/core/markdown.ts

24 lines
656 B
TypeScript
Raw Normal View History

2022-03-28 13:25:05 +00:00
import { syscall } from "../lib/syscall";
import mdParser from "../../webapp/parser";
export async function renderMD() {
let text = await syscall("editor.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));
2022-03-28 13:25:05 +00:00
slicesToRemove.reverse().forEach(([from, to]) => {
text = text.slice(0, from) + text.slice(to);
});
console.log("Clean md", text);
}