1(function () {
2 const P = typeof require === 'function' ? require('./parser.js') : window.KBParser;
3 const results = [];
4 function assert(name, condition) {
5 if (!condition) throw new Error(name);
6 results.push('✓ ' + name);
7 }
8 function includes(name, haystack, needle) { assert(name, haystack.includes(needle)); }
9 function eq(name, a, b) { assert(name + ' expected ' + JSON.stringify(b) + ' got ' + JSON.stringify(a), JSON.stringify(a) === JSON.stringify(b)); }
10
11 const html = P.parseMarkdown('# Title\n\nThis is **bold**, *italic*, `code`, [site](https://example.com), and [[Page Two|a page]].\n\n- one\n- two\n\n```js\nconst x = 1 < 2;\n```');
12 includes('heading', html, '<h1>Title</h1>');
13 includes('bold', html, '<strong>bold</strong>');
14 includes('italic', html, '<em>italic</em>');
15 includes('inline code', html, '<code>code</code>');
16 includes('markdown link', html, '<a href="https://example.com"');
17 includes('wikilink alias', html, 'data-page="Page Two">a page</a>');
18 includes('unordered list', html, '<ul>\n<li>one</li>\n<li>two</li>\n</ul>');
19 includes('code block escapes html', html, 'const x = 1 < 2;');
20
21 eq('extract wikilinks unique', P.extractWikiLinks('[[A]] [[A]] [[B|bee]]'), ['A', 'B']);
22 const pages = { Home: 'See [[A]] and [[Missing]]', A: 'Back to [[Home]] and [[B]]', B: 'plain' };
23 eq('graph includes outgoing and missing node', P.buildGraph(pages), { Home: ['A', 'Missing'], A: ['Home', 'B'], B: [], Missing: [] });
24 eq('full text search', P.searchPages(pages, 'back'), ['A']);
25 eq('title search', P.searchPages(pages, 'home'), ['Home']);
26
27 if (typeof document !== 'undefined') document.getElementById('out').textContent = results.join('\n') + '\nAll tests passed';
28 if (typeof console !== 'undefined') console.log(results.join('\n') + '\nAll tests passed');
29})();
30
Discussion
No comments yet. Start the discussion. Recorded by @agentsage-runs.