2022-10-14 13:11:33 +00:00
|
|
|
// import { parse } from "./parse_tree.ts";
|
2022-04-09 12:28:41 +00:00
|
|
|
import {
|
|
|
|
addParentPointers,
|
|
|
|
collectNodesMatching,
|
|
|
|
findParentMatching,
|
|
|
|
nodeAtPos,
|
|
|
|
removeParentPointers,
|
2022-04-11 18:34:09 +00:00
|
|
|
renderToText,
|
2022-04-29 16:54:27 +00:00
|
|
|
replaceNodesMatching,
|
2022-10-10 12:50:21 +00:00
|
|
|
} from "./tree.ts";
|
2022-12-14 19:04:20 +00:00
|
|
|
import wikiMarkdownLang from "../../common/markdown_parser/parser.ts";
|
2022-10-14 13:11:33 +00:00
|
|
|
import { assertEquals, assertNotEquals } from "../../test_deps.ts";
|
2022-12-14 19:04:20 +00:00
|
|
|
import { parse } from "../../common/markdown_parser/parse_tree.ts";
|
2022-04-04 09:51:41 +00:00
|
|
|
|
|
|
|
const mdTest1 = `
|
|
|
|
# Heading
|
|
|
|
## Sub _heading_ cool
|
|
|
|
|
|
|
|
Hello, this is some **bold** text and *italic*. And [a link](http://zef.me).
|
|
|
|
|
|
|
|
%% My comment here
|
|
|
|
%% And second line
|
|
|
|
|
|
|
|
And an @mention
|
|
|
|
|
|
|
|
http://zef.plus
|
|
|
|
|
|
|
|
- This is a list [[PageLink]]
|
|
|
|
- With another item
|
|
|
|
- TODOs:
|
|
|
|
- [ ] A task that's not yet done
|
|
|
|
- [x] Hello
|
|
|
|
- And a _third_ one [[Wiki Page]] yo
|
|
|
|
`;
|
|
|
|
|
|
|
|
const mdTest2 = `
|
|
|
|
Hello
|
|
|
|
|
|
|
|
* Item 1
|
|
|
|
*
|
|
|
|
|
|
|
|
Sup`;
|
|
|
|
|
2022-04-09 12:28:41 +00:00
|
|
|
const mdTest3 = `
|
|
|
|
\`\`\`yaml
|
|
|
|
name: something
|
|
|
|
\`\`\`
|
|
|
|
`;
|
|
|
|
|
2022-12-14 19:04:20 +00:00
|
|
|
Deno.test("Test parsing", () => {
|
2022-04-11 18:34:09 +00:00
|
|
|
const lang = wikiMarkdownLang([]);
|
2022-11-18 15:04:37 +00:00
|
|
|
const mdTree = parse(lang, mdTest1);
|
2022-04-04 09:51:41 +00:00
|
|
|
addParentPointers(mdTree);
|
|
|
|
// console.log(JSON.stringify(mdTree, null, 2));
|
2022-11-18 15:04:37 +00:00
|
|
|
const wikiLink = nodeAtPos(mdTree, mdTest1.indexOf("Wiki Page"))!;
|
|
|
|
assertEquals(wikiLink.type, "WikiLinkPage");
|
2022-10-10 12:50:21 +00:00
|
|
|
assertNotEquals(
|
|
|
|
findParentMatching(wikiLink, (n) => n.type === "BulletList"),
|
|
|
|
null,
|
|
|
|
);
|
2022-04-04 09:51:41 +00:00
|
|
|
|
2022-11-18 15:04:37 +00:00
|
|
|
const allTodos = collectNodesMatching(mdTree, (n) => n.type === "Task");
|
2022-10-10 12:50:21 +00:00
|
|
|
assertEquals(allTodos.length, 2);
|
2022-04-04 09:51:41 +00:00
|
|
|
|
|
|
|
// Render back into markdown should be equivalent
|
2022-10-10 12:50:21 +00:00
|
|
|
assertEquals(renderToText(mdTree), mdTest1);
|
2022-04-04 09:51:41 +00:00
|
|
|
|
2022-04-09 12:28:41 +00:00
|
|
|
removeParentPointers(mdTree);
|
|
|
|
replaceNodesMatching(mdTree, (n) => {
|
|
|
|
if (n.type === "Task") {
|
|
|
|
return {
|
|
|
|
type: "Tosk",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2023-05-23 18:53:53 +00:00
|
|
|
// console.log(JSON.stringify(mdTree, null, 2));
|
2022-04-11 18:34:09 +00:00
|
|
|
let mdTree3 = parse(lang, mdTest3);
|
2023-05-23 18:53:53 +00:00
|
|
|
// console.log(JSON.stringify(mdTree3, null, 2));
|
2022-04-04 09:51:41 +00:00
|
|
|
});
|