Skip to content

Commit

Permalink
feat(hiccup-markdown): update char escapes & inline format nesting rules
Browse files Browse the repository at this point in the history
- allow nested kbd/sub/sup elements
- update char escape rules for inline code, codeblocks, custom blocks & meta blocks
- update __trimBody() helper to remove isolate trailing WS
- add/update tests
  • Loading branch information
postspectacular committed Mar 7, 2023
1 parent 00a19d2 commit 2fde69b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 31 deletions.
67 changes: 39 additions & 28 deletions packages/hiccup-markdown/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Downloaded @ 2023-03-06T12:44:14.677Z
// Source: https://demo.thi.ng/umbrella/parse-playground/#ldoPEUROTDE6IDxETkw-KyA9PiBkaXNjYXJkIDsKRE5MMjogPE5MPnsyLH0gOwpsYnI6ICdcXCchIDxOTD4hIDsKZXNjOiAnXFwnISAoJ18nIHwgJyonIHwgJ2AnIHwgJ34nIHwgJzonIHwgJy0nIHwgJzwnIHwgJz4nIHwgJ1snIHwgJ10nIHwgJygnIHwgJyknIHwgJ3snIHwgJ30nKSA7CmlubGluZWRlbGltOiAoIiFbIiB8ICdbJyB8ICIqKiIgfCAnXycgfCAnYCcgfCAnPCcgfCAifn4iIHwgIiA6IiB8IDxsYnI-KSA7CmRlbGltOiAoPGlubGluZWRlbGltPiB8IDxETkwyPikgOwpkZWxpbTE6ICg8aW5saW5lZGVsaW0-IHwgPE5MPikgOwplYm9keTogKDxlc2M-fC4pIDsKYm9keTogPGVib2R5Pig_LTxkZWxpbT4hKSA9PiBqb2luIDsKYm9keTE6IDxlYm9keT4oPy08ZGVsaW0xPiEpID0-IGpvaW4gOwoKY29tbWVudDogIjwhLS0iISAuKD8rIi0tPiIpID0-IGRpc2NhcmQgOwp3aWtpcmVmOiAiW1siISA8ZWJvZHk-KD8rIl1dIiEpID0-IGpvaW4gOwpmbnJlZjogIlteIiEgPGxhYmVsPiA7CmZub3RlOiA8TFNUQVJUPiAiW14iISA8Zm5sYWJlbD4gPFdTMT4gPH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0gfX19ClNvIFtbc21pbGVfZm9vMTJdXSDwn5iNIHdoYXQncyBbdGhpc10oLi90aGlzLm1kKVteMl0gdGhlbjoKCkEgW2xpbmsgX3dpdGggKipuZXN0ZWQgfn5mb3JtYXR-fioqIGFuZCBgcmVmZXJlbmNlYF9dW3JlZnJlZl0uLi4KCmBgYHRzIHRhbmdsZTpubyBsbjp5ZXMKY29uc3QgcmUgPSAvW1xuXHJdKy9nOwovLyB0aGUgZW5kCmBgYAoKMS4gZm9vCiAgNC4gYmFyCiAgICAgYmF6IGFuZCBzbyBvbgogICAgIG11bHRpbGluZQoyLiBbIF0gdGFzawozLiBbeF0gKipkb25lKioKCj4gYmxvY2txdW90ZQo-IG11bHRpbGluZSB0b29cCj4-IG5lc3RlZAo-Pj4gbGV2ZWwgMwo-IC0tIHNvdXJjZQoKfCBmb28gfCBiYXIgfAp8Oi06fC06fAp8IFtbcmVmIzIyXV0gfCBgb25gICoqb2ZmKiogfAoKW15hYmNdOiBGb28gX2Jhcl8gYmF6CgpbXjJdOiBUT0RPCgpbcmVmcmVmXTogaHR0cDovL3RoaS5uZy8KW2Zvb106IC4vZm9vLm1kI2JhcgoK2VA8IS0tCmlnbm9yZQptdWx0aWxpbmUKLS0-CgoxMS4gYWJjCiAgLSB4eXoKMjEuIHh4eAogIGEuIGZvbwogICAgYi4gYmFyCjMxLiB5eXkKCtlSfCBjb2wxIHwgY29sMiB8CnwgLS0tLSB8IC0tLS06fAp8IDxrYmQ-Q3RybDwva2JkPiB8IDxzdXA-Ujwvc3VwPiBgW1thYmNcfGlkXV1gIHwKCrkqKjp3YXJuOiBhYmMKZGVmIDpvazoqKgoK2Ug-IGxpbmUxCj4-ICoqbGluZSAyKipcCj4-IGxpbmUgMmEKPj4gbGluZSAyYgo-PiAKPj4gbGluZSAyYwo-Pj4gbGluZSAzCgo

import type { Fn3, IObjectOf, Primitive } from "@thi.ng/api";
import { peek } from "@thi.ng/arrays/peek";
Expand Down Expand Up @@ -28,13 +28,20 @@ export const GRAMMAR = defGrammar(`
DNL1: <DNL>+ => discard ;
DNL2: <NL>{2,} ;
lbr: '\\\\'! <NL>! ;
esc: '\\\\'! ('_' | '*' | '\`' | '~' | ':' | '-' | '<' | '>' | '[' | ']' | '(' | ')' | '{' | '}') ;
inlinedelim: ("![" | '[' | "**" | '_' | '\`' | '<' | "~~" | " :" | <lbr>) ;
delim: (<inlinedelim> | <DNL2>) ;
delim1: (<inlinedelim> | <NL>) ;
esc: '\\\\'! ('_' | '*' | '\`' | '~' | ':' | '-' | '<' | '>' | '[' | ']' | '(' | ')' | '{' | '}' | '#' | '.' | '|' | '\\\\') ;
cesc: '\\\\'! ('\`'| '\\\\') ;
cbesc: '\\\\'! '\`' ;
cuesc: '\\\\'! ':' ;
mesc: '\\\\'! '}' ;
idelim: ("![" | '[' | "**" | '_' | '\`' | '<' | "~~" | " :" | <lbr>) ;
delim: (<idelim> | <DNL2>) ;
ebody: (<esc>|.) ;
cbody: (<cesc>|.) ;
cbbody: (<cbesc>|.) ;
cubody: (<cuesc>|.) ;
mbody: (<mesc>|.) ;
body: <ebody>(?-<delim>!) => join ;
body1: <ebody>(?-<delim1>!) => join ;
ibody: <ebody>(?-<idelim>!) => join ;
comment: "<!--"! .(?+"-->") => discard ;
wikiref: "[["! <ebody>(?+"]]"!) => join ;
Expand All @@ -47,14 +54,14 @@ link: '['! <linklabel> '('! <target> ;
linkref: '['! <linklabel> '['! <label> ;
linkdef: <LSTART> '['! <label> ':'! <WS1> <ldtarget> ;
ldtarget: <ebody>(?+<DNL1>) => join ;
linklabel: (<img> | <bold> | <italic> | <strike> | <code> | <emoji> | <linkbody>)* ']'! ;
linklabel: (<img> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <linkbody>)* ']'! ;
linkdelim: ("![" | '[' | "**" | '_' | "~~" | '\`' | ']') ;
linkbody: <ebody>(?-<linkdelim>!) => join ;
img: "!["! <label> '('! <target> ;
bold: "**"! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <italic> | <strike> | <code> | <emoji> | <body1>)* "**"! ;
italic: '_'! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <strike> | <code> | <emoji> | <body1>)* '_'! ;
strike: "~~"! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <italic> | <code> | <emoji> | <body1>)* "~~"! ;
code: '\`'! <ebody>(?+'\`'!) => join ;
bold: "**"! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <ibody>)* "**"! ;
italic: '_'! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <ibody>)* '_'! ;
strike: "~~"! (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <italic> | <code> | <emoji> | <kbd> | <sub> | <sup> | <ibody>)* "~~"! ;
code: '\`'! <cbody>(?+'\`'!) => join ;
kbd: "<kbd>"! <ebody>(?+"</kbd>"!) => join ;
sub: "<sub>"! <ebody>(?+"</sub>"!) => join ;
sup: "<sup>"! <ebody>(?+"</sup>"!) => join ;
Expand All @@ -63,10 +70,10 @@ para: (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <italic> | <s
hdlevel: '#'+ => count ;
hdid: "{#"! (<ALPHA_NUM> | '-')+ '}'! => join ;
hddelim: (<delim1> | "{#") ;
hddelim: (<idelim> | <NL> | "{#") ;
hdbody: <ebody>(?-<hddelim>!) => join ;
hd: <LSTART> <hdlevel> <WS0>
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <kbd> | <sub> | <sup> | <emoji> | <hdbody>)* <hdid>? <DNL1> ;
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <hdbody>)* <hdid>? <DNL1> ;
lilevel: ' '* => count ;
olid: (<ALPHA>+|<DIGIT>+) => join ;
Expand All @@ -76,34 +83,36 @@ lidelim: (<delim> | <ulinit> | <olinit>) ;
libody: <ebody>(?-<lidelim>!) => join ;
todo: '['! [ xX] ']'! <WS1> => hoistR ;
ulitem: <LSTART> <lilevel> "- "! <todo>?
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <libody> )* <DNL> ;
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <libody> )* <DNL> ;
olitem: <LSTART> <lilevel> <olid> ". "! <todo>?
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <libody> )* <DNL> ;
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <libody> )* <DNL> ;
list: (<ulitem> | <olitem>)+ <DNL1> ;
cbdelim: <LSTART> "\`\`\`"! ;
codeblock: <cbdelim>! <codemeta> <codebody> <DNL1> ;
codemeta: .(?+<NL>!) => join ;
codebody: <ebody>(?+<cbdelim>) => join ;
codebody: <cbbody>(?+<cbdelim>) => join ;
customdelim: <LSTART> ":::"! ;
customblock: <customdelim>! <custommeta> <custombody> <DNL1> ;
cudelim: <LSTART> ":::"! ;
customblock: <cudelim>! <custommeta> <custombody> <DNL1> ;
custommeta: .(?+<NL>!) => join ;
custombody: <ebody>(?+<customdelim>) => join ;
custombody: <cubody>(?+<cudelim>) => join ;
metablock: <LSTART> "{{{"! <metabody> <DNL1> ;
metabody: <ebody>(?+<metaend>!) => join ;
metabody: <mbody>(?+<metaend>!) => join ;
metaend: "}}}" <LEND> ;
bqlevel: '>'+ => count ;
bqdelim: (<idelim> | <NL>) ;
bqbody: <ebody>(?-<bqdelim>!) => join ;
bqline: <LSTART> <bqlevel> ' '?!
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <bqlbr> | <body1>)* <DNL> ;
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <bqlbr> | <bqbody>)* <DNL> ;
bqlbr: '\\\\'!(?-<DNL>) ;
bquote: <bqline>+ <DNL1> ;
tdelim: (<inlinedelim> | '|' ) ;
tdelim: (<idelim> | '|' ) ;
tbody: <ebody>(?-<tdelim>!) => join ;
tcell: <WS0> (<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <tbody> )* '|'! ;
tcell: <WS0> (<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <kbd> | <sub> | <sup> | <tbody> )* '|'! ;
trow: <LSTART> '|'! <tcell>(?+<DNL>) ;
table: <trow>+ <DNL1> ;
Expand Down Expand Up @@ -311,10 +320,11 @@ export const transformScope: Fn3<
return x.id;
},
{
body1: "body",
bqbody: "body",
bqlbr: "lbr",
bqline: "repeat0",
hdbody: "body",
ibody: "body",
label: "body",
libody: "body",
linkbody: "body",
Expand Down Expand Up @@ -435,9 +445,6 @@ export const transformScope: Fn3<
__collect(acc, ctx.tags.emoji(ctx, result));
},

esc: (scope, ctx, acc) =>
acc.push(__escape(ctx, scope.children![0].result)),

fnote: ({ children }, ctx) => {
const body: any[] = [];
const id = children![0].result;
Expand Down Expand Up @@ -727,6 +734,10 @@ const __listItemAttribs = (scope?: ParseScope<string>): TodoAttribs =>
/** @internal */
const __trimBody = (body: any[]) => {
if (body.length === 1 && isString(body[0])) body[0] = body[0].trim();
else {
const last = peek(body);
if (isString(last) && /^\s+$/.test(last)) body.pop();
}
return body;
};

Expand Down
Loading

0 comments on commit 2fde69b

Please sign in to comment.