2022-04-05 15:02:17 +00:00
|
|
|
import { expect, test } from "@jest/globals";
|
|
|
|
import { parse } from "../../common/tree";
|
2022-04-09 12:28:41 +00:00
|
|
|
import {
|
|
|
|
addParentPointers,
|
|
|
|
collectNodesMatching,
|
|
|
|
findParentMatching,
|
|
|
|
nodeAtPos,
|
|
|
|
removeParentPointers,
|
|
|
|
renderMarkdown,
|
|
|
|
replaceNodesMatching
|
|
|
|
} from "./tree";
|
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-04-04 09:51:41 +00:00
|
|
|
test("Run a Node sandbox", async () => {
|
|
|
|
let mdTree = parse(mdTest1);
|
|
|
|
addParentPointers(mdTree);
|
|
|
|
// console.log(JSON.stringify(mdTree, null, 2));
|
|
|
|
let wikiLink = nodeAtPos(mdTree, mdTest1.indexOf("Wiki Page"))!;
|
|
|
|
expect(wikiLink.type).toBe("WikiLink");
|
|
|
|
expect(
|
|
|
|
findParentMatching(wikiLink, (n) => n.type === "BulletList")
|
|
|
|
).toBeDefined();
|
|
|
|
|
|
|
|
let allTodos = collectNodesMatching(mdTree, (n) => n.type === "Task");
|
|
|
|
expect(allTodos.length).toBe(2);
|
|
|
|
|
|
|
|
// Render back into markdown should be equivalent
|
2022-04-04 13:25:07 +00:00
|
|
|
expect(renderMarkdown(mdTree)).toBe(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",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log(JSON.stringify(mdTree, null, 2));
|
|
|
|
let mdTree3 = parse(mdTest3);
|
|
|
|
console.log(JSON.stringify(mdTree3, null, 2));
|
2022-04-04 09:51:41 +00:00
|
|
|
});
|