Skip to content

Commit

Permalink
feat(hiccup-markdown): update parse grammar
Browse files Browse the repository at this point in the history
- char escapes now usable in almost all situs
  (excl. metadata for code/custom blocks)
- add support for these HTML tags:
  - comments `<!-- ... -->`
  - `<sub>` / `<sup>`
- add tests
  • Loading branch information
postspectacular committed Mar 6, 2023
1 parent 8342900 commit e0be40a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 30 deletions.
64 changes: 34 additions & 30 deletions packages/hiccup-markdown/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Downloaded @ 2023-03-05T09:08:51.082Z
// Source: https://demo.thi.ng/umbrella/parse-playground/#ldoNwUROTDE6IDxETkw-KyA9PiBkaXNjYXJkIDsKRE5MMjogPE5MPnsyLH0gOwpsYnI6ICdcXCchIDxOTD4hIDsKZXNjOiAnXFwnISAoICc8JyB8ICdbJyB8ICdfJyB8ICcqJyB8ICdgJyB8ICd-JyB8ICc6JyApIDsKaW5saW5lZGVsaW06ICggIiFbIiB8ICdbJyB8ICIqKiIgfCAnXycgfCAnYCcgfCAnPCcgfCAnXFwnIHwgIn5-IiB8ICIgOiIgfCA8bGJyPiApIDsKZGVsaW06ICggPGlubGluZWRlbGltPiB8IDxETkwyPiApIDsKZGVsaW0xOiAoIDxpbmxpbmVkZWxpbT4gfCA8Tkw-ICkgOwpib2R5OiAuKD8tPGRlbGltPiEpID0-IGpvaW4gOwpib2R5MTogLig_LTxkZWxpbTE-ISkgPT4gam9pbiA7Cgp3aWtpcmVmOiAiW1siISAuKD8rIl1dIiEpID0-IGpvaW4gOwpmbnJlZjogIlteIiEgPGxhYmVsPiA7CmZub3RlOiA8TFNUQVJUPiAiW14iISA8Zm5sYWJlbD4gPFdTMT4gPHBhcmE-IDsKZm5sYWJlbDogLig_KyJdOiIhKSA9PiBqb2luIDsKbGFiZWw6IC4oPysnXSchKSA9PiBqb2luIDsKdGFyZ2V0OiAuKD8rJyknISkgPT4gam9pbiA7Cmxpbms6ICdbJyEgPGxpb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teMl0gdGhlbjoKCkEgW2xpbmsgX3dpdGggKipuZXN0ZWQgfn5mb3JtYXR-fioqIGFuZCBgcmVmZXJlbmNlYF9dW3JlZnJlZl0uLi4KCmBgYHRzIHRhbmdsZTpubyBsbjp5ZXMKY29uc3QgZm9vID0gNDI7Ci8vIHRoZSBlbmQKYGBgCgoxLiBmb28KICA0LiBiYXIKICAgICBiYXogYW5kIHNvIG9uCiAgICAgbXVsdGlsaW5lCjIuIFsgXSB0YXNrCjMuIFt4XSAqKmRvbmUqKgoKPiBibG9ja3F1b3RlCj4gbXVsdGlsaW5lIHRvb1wKPj4gbmVzdGVkCj4-PiBsZXZlbCAzCj4gLS0gc291cmNlCgp8IGZvbyB8IGJhciB8Cnw6LXwtOnwKfCBbW3JlZiMyMl1dIHwgYG9uYCAqKm9mZioqIHwKClteYWJjXTogRm9vIF9iYXJfIGJhegoKW14yXTogVE9ETwoKW3JlZnJlZl06IGh0dHA6Ly90aGkubmcvCltmb29dOiAuL2Zvby5tZCNiYXIKCtlQPCEtLQppZ25vcmUKbXVsdGlsaW5lCi0tPgoKMTEuIGFiYwogIC0geHl6CjIxLiB4eHgKICAxLiBmb28KICAgIDEuIGJhcgozMS4geXl5CgrZVj4gKipsZXZlbCAxYSoqCj4-IGxldmVsIDJhCj4-IGxldmVsIDJiCj4KPiBsZXZlbCAxYgoKWyoqZm9vKipdKGJhcikKCioqIVtmb29dKGJhcikqKgoK

import type { Fn3, IObjectOf, Primitive } from "@thi.ng/api";
import { peek } from "@thi.ng/arrays/peek";
Expand Down Expand Up @@ -28,48 +28,52 @@ export const GRAMMAR = defGrammar(`
DNL1: <DNL>+ => discard ;
DNL2: <NL>{2,} ;
lbr: '\\\\'! <NL>! ;
esc: '\\\\'! ( '<' | '[' | '_' | '*' | '\`' | '~' | ':' ) ;
inlinedelim: ( "![" | '[' | "**" | '_' | '\`' | '<' | '\\\\' | "~~" | " :" | <lbr> ) ;
delim: ( <inlinedelim> | <DNL2> ) ;
delim1: ( <inlinedelim> | <NL> ) ;
body: .(?-<delim>!) => join ;
body1: .(?-<delim1>!) => join ;
wikiref: "[["! .(?+"]]"!) => join ;
esc: '\\\\'! ('_' | '*' | '\`' | '~' | ':' | '-' | '<' | '>' | '[' | ']' | '(' | ')' | '{' | '}') ;
inlinedelim: ("![" | '[' | "**" | '_' | '\`' | '<' | "~~" | " :" | <lbr>) ;
delim: (<inlinedelim> | <DNL2>) ;
delim1: (<inlinedelim> | <NL>) ;
ebody: (<esc>|.) ;
body: <ebody>(?-<delim>!) => join ;
body1: <ebody>(?-<delim1>!) => join ;
comment: "<!--"! .(?+"-->") => discard ;
wikiref: "[["! <ebody>(?+"]]"!) => join ;
fnref: "[^"! <label> ;
fnote: <LSTART> "[^"! <fnlabel> <WS1> <para> ;
fnlabel: .(?+"]:"!) => join ;
label: .(?+']'!) => join ;
target: .(?+')'!) => join ;
fnlabel: <ebody>(?+"]:"!) => join ;
label: <ebody>(?+']'!) => join ;
target: <ebody>(?+')'!) => join ;
link: '['! <linklabel> '('! <target> ;
linkref: '['! <linklabel> '['! <label> ;
linkdef: <LSTART> '['! <label> ':'! <WS1> <ldtarget> ;
ldtarget: .(?+<DNL1>) => join ;
ldtarget: <ebody>(?+<DNL1>) => join ;
linklabel: (<img> | <bold> | <italic> | <strike> | <code> | <emoji> | <linkbody>)* ']'! ;
linkdelim: ( "![" | '[' | "**" | '_' | "~~" | '\`' | ']') ;
linkbody: .(?-<linkdelim>!) => join ;
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: '\`'! .(?+'\`'!) => join ;
kbd: "<kbd>"! .(?+"</kbd>"!) => join ;
code: '\`'! <ebody>(?+'\`'!) => join ;
kbd: "<kbd>"! <ebody>(?+"</kbd>"!) => join ;
sub: "<sub>"! <ebody>(?+"</sub>"!) => join ;
sup: "<sup>"! <ebody>(?+"</sup>"!) => join ;
emoji: ' '? ':'! (<ALPHA_NUM> | '+' | '-')(?+':'!) => join ;
para: (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <italic> | <strike> | <code> | <kbd> | <emoji> | <lbr> | <esc> | <body>)* <DNL2>! ;
para: (<wikiref> | <img> | <fnref> | <linkref> | <link> | <bold> | <italic> | <strike> | <code> | <kbd> | <sub> | <sup> | <emoji> | <lbr> | <comment> | <body>)* <DNL2>! ;
hdlevel: '#'+ => count ;
hdid: "{#"! (<ALPHA_NUM> | '-')+ '}'! => join ;
hddelim: ( <delim1> | "{#" ) ;
hdbody: .(?-<hddelim>!) => join ;
hddelim: (<delim1> | "{#") ;
hdbody: <ebody>(?-<hddelim>!) => join ;
hd: <LSTART> <hdlevel> <WS0>
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <hdbody> )* <hdid>? <DNL1> ;
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <kbd> | <sub> | <sup> | <emoji> | <hdbody>)* <hdid>? <DNL1> ;
lilevel: ' '* => count ;
uint: <DIGIT>+ => int ;
ulid: <DNL> <WS0> '-'! ;
olid: <DNL> <WS0> <DIGIT>+! '.'! ;
lidelim: ( <delim> | <ulid> | <olid> ) ;
libody: .(?-<lidelim>!) => join ;
lidelim: (<delim> | <ulid> | <olid>) ;
libody: <ebody>(?-<lidelim>!) => join ;
todo: '['! [ xX] ']'! <WS1> => hoistR ;
ulitem: <LSTART> <lilevel> "- "! <todo>?
(<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <libody> )* <DNL> ;
Expand All @@ -80,15 +84,15 @@ list: (<ulitem> | <olitem>)+ <DNL1> ;
cbdelim: <LSTART> "\`\`\`"! ;
codeblock: <cbdelim>! <codemeta> <codebody> <DNL1> ;
codemeta: .(?+<NL>!) => join ;
codebody: .(?+<cbdelim>) => join ;
codebody: <ebody>(?+<cbdelim>) => join ;
customdelim: <LSTART> ":::"! ;
customblock: <customdelim>! <custommeta> <custombody> <DNL1> ;
custommeta: .(?+<NL>!) => join ;
custombody: .(?+<customdelim>) => join ;
custombody: <ebody>(?+<customdelim>) => join ;
metablock: <LSTART> "{{{"! <metabody> <DNL1> ;
metabody: .(?+<metaend>!) => join ;
metabody: <ebody>(?+<metaend>!) => join ;
metaend: "}}}" <LEND> ;
bqlevel: '>'+ => count ;
Expand All @@ -98,14 +102,14 @@ bqlbr: '\\\\'!(?-<DNL>) ;
bquote: <bqline>+ <DNL1> ;
tdelim: (<inlinedelim> | '|' ) ;
tbody: .(?-<tdelim>!) => join ;
tbody: <ebody>(?-<tdelim>!) => join ;
tcell: <WS0> (<wikiref> | <img> | <fnref> | <link> | <bold> | <italic> | <strike> | <code> | <emoji> | <tbody> )* '|'! ;
trow: <LSTART> '|'! <tcell>(?+<DNL>) ;
table: <trow>+ <DNL1> ;
hr: "--" '-'+ <DNL1> => join ;
main: <WS0> (<hd> | <list> | <bquote> | <codeblock> | <customblock> | <metablock> | <table> | <hr> | <fnote> | <linkdef> | <para>)* ;
main: <WS0> (<hd> | <list> | <bquote> | <codeblock> | <customblock> | <metablock> | <table> | <hr> | <fnote> | <linkdef> | <comment> | <para> )* ;
`);

export const DEFAULT_TAG_TRANSFORMS: TagTransforms = {
Expand Down Expand Up @@ -647,7 +651,7 @@ export const transformScope: Fn3<

wikiref: (scope, ctx, acc) => {
const [id, label] = scope.result.split("|");
__collect(acc, ctx.tags.wikiref(ctx, id, label));
__collect(acc, ctx.tags.wikiref(ctx, id.trim(), label?.trim()));
},
}
);
Expand Down
56 changes: 56 additions & 0 deletions packages/hiccup-markdown/test/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,62 @@ group("parse", {
]);
},

"escape in hd": () => {
check("# a\\*\\*bc", [["h1", { id: "abc" }, "a**bc"]]);
},

"escape in para": () => {
check("a \\`bc\\`", [["p", {}, "a `bc`"]]);
},

"escape in inline fmt": () => {
check("**a\\_bc**", [["p", {}, ["strong", {}, "a_bc"]]]);
check("_a\\**bc_", [["p", {}, ["em", {}, "a**bc"]]]);
},

"escape in link": () => {
check(`[a\\_bc](d\\(ef\\) "with\\_esc")`, [
["p", {}, ["a", { href: "d(ef)", title: "with_esc" }, "a_bc"]],
]);
},

"escape in wikiref": () => {
check(`[[ a\\[bc\\]]]`, [
[
"p",
{},
[
"a",
{
class: "wikiref",
href: "a%5Bbc%5D",
},
"a[bc]",
],
],
]);
check(`[[ a\\[bc\\]| Title ]]`, [
[
"p",
{},
[
"a",
{
class: "wikiref",
href: "a%5Bbc%5D",
},
"Title",
],
],
]);
},

"escape in list": () => {
check(`- a\\_bc\n\\- d\\[ef\\]`, [
["ul", {}, ["li", {}, "a_bc\n- d[ef]"]],
]);
},

footnotes: () => {
check(
`abc[^2] def[^1]
Expand Down

0 comments on commit e0be40a

Please sign in to comment.