1
0
silverbullet/plugs/core/markdown.ts

24 lines
660 B
TypeScript
Raw Normal View History

2022-03-28 13:25:05 +00:00
import mdParser from "../../webapp/parser";
2022-04-01 15:07:08 +00:00
import { getText } from "plugos-silverbullet-syscall/editor";
2022-03-28 13:25:05 +00:00
export async function renderMD() {
2022-04-01 15:07:08 +00:00
let text = await getText();
2022-03-28 13:25:05 +00:00
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);
}