Reimplement as a tokenizer with GFM parity

This commit is contained in:
gsb
2026-04-30 07:09:19 +00:00
parent 005db2f431
commit d41716c8b2
28 changed files with 4798 additions and 1398 deletions
+9 -6
View File
@@ -1,6 +1,8 @@
import { ribbit } from './setup';
const r = ribbit();
const lib = ribbit();
const spacePattern = / /g;
const macros = [
{
@@ -11,7 +13,7 @@ const macros = [
name: 'npc',
toHTML: ({ keywords }: any) => {
const name = keywords.join(' ');
return '<a href="/NPC/' + name.replace(/ /g, '') + '">' + name + '</a>';
return '<a href="/NPC/' + name.replace(spacePattern, '') + '">' + name + '</a>';
},
},
{
@@ -24,9 +26,9 @@ const macros = [
},
];
const h = new r.HopDown({ macros });
const H = (md: string) => h.toHTML(md);
const M = (html: string) => h.toMarkdown(html);
const converter = new lib.HopDown({ macros });
const H = (md: string) => converter.toHTML(md);
const M = (html: string) => converter.toMarkdown(html);
describe('Macros', () => {
describe('self-closing', () => {
@@ -61,7 +63,8 @@ describe('Macros', () => {
it('keyword stripped from data-keywords', () => {
const html = H('@style(box verbatim\ncontent\n)');
expect(html).toContain('data-keywords="box"');
expect(html).not.toMatch(/data-keywords="[^"]*verbatim/);
const verbatimKeywordPattern = /data-keywords="[^"]*verbatim/;
expect(html).not.toMatch(verbatimKeywordPattern);
});
});