import {parser as cmParser, GFM, Subscript, Superscript, Emoji} from "../dist/index.js" import {compareTree} from "./compare-tree.js" import {SpecParser} from "./spec.js" const parser = cmParser.configure([GFM, Subscript, Superscript, Emoji]) const specParser = new SpecParser(parser, { __proto__: null as any, Th: "Strikethrough", tm: "StrikethroughMark", TB: "Table", TH: "TableHeader", TR: "TableRow", TC: "TableCell", tb: "TableDelimiter", T: "Task", t: "TaskMarker", Sub: "Subscript", sub: "SubscriptMark", Sup: "Superscript", sup: "SuperscriptMark", ji: "Emoji" }) function test(name: string, spec: string, p = parser) { it(name, () => { let {tree, doc} = specParser.parse(spec, name) compareTree(p.parse(doc), tree) }) } describe("Extension", () => { test("Tables (example 198)", ` {TB:{TH:{tb:|} {TC:foo} {tb:|} {TC:bar} {tb:|}} {tb:| --- | --- |} {TR:{tb:|} {TC:baz} {tb:|} {TC:bim} {tb:|}}}`) test("Tables (example 199)", ` {TB:{TH:{tb:|} {TC:abc} {tb:|} {TC:defghi} {tb:|}} {tb::-: | -----------:} {TR:{TC:bar} {tb:|} {TC:baz}}}`) test("Tables (example 200)", ` {TB:{TH:{tb:|} {TC:f{Esc:\\|}oo} {tb:|}} {tb:| ------ |} {TR:{tb:|} {TC:b {C:{c:\`}\\|{c:\`}} az} {tb:|}} {TR:{tb:|} {TC:b {St:{e:**}{Esc:\\|}{e:**}} im} {tb:|}}}`) test("Tables (example 201)", ` {TB:{TH:{tb:|} {TC:abc} {tb:|} {TC:def} {tb:|}} {tb:| --- | --- |} {TR:{tb:|} {TC:bar} {tb:|} {TC:baz} {tb:|}}} {Q:{q:>} {P:bar}}`) test("Tables (example 202)", ` {TB:{TH:{tb:|} {TC:abc} {tb:|} {TC:def} {tb:|}} {tb:| --- | --- |} {TR:{tb:|} {TC:bar} {tb:|} {TC:baz} {tb:|}} {TR:{TC:bar}}} {P:bar}`) test("Tables (example 203)", ` {P:| abc | def | | --- | | bar |}`) test("Tables (example 204)", ` {TB:{TH:{tb:|} {TC:abc} {tb:|} {TC:def} {tb:|}} {tb:| --- | --- |} {TR:{tb:|} {TC:bar} {tb:|}} {TR:{tb:|} {TC:bar} {tb:|} {TC:baz} {tb:|} {TC:boo} {tb:|}}}`) test("Tables (example 205)", ` {TB:{TH:{tb:|} {TC:abc} {tb:|} {TC:def} {tb:|}} {tb:| --- | --- |}}`) test("Tables (in blockquote)", ` {Q:{q:>} {TB:{TH:{tb:|} {TC:one} {tb:|} {TC:two} {tb:|}} {q:>} {tb:| --- | --- |} {q:>} {TR:{tb:|} {TC:123} {tb:|} {TC:456} {tb:|}}} {q:>} {q:>} {P:Okay}}`) test("Tables (empty header)", ` {TB:{TH:{tb:|} {tb:|} {tb:|}} {tb:| :-: | :-: |} {TR:{tb:|} {TC:One} {tb:|} {TC:Two} {tb:|}}}`) test("Tables (end paragraph)", ` {P:Hello} {TB:{TH:{tb:|} {TC:foo} {tb:|} {TC:bar} {tb:|}} {tb:| --- | --- |} {TR:{tb:|} {TC:baz} {tb:|} {TC:bim} {tb:|}}}`) test("Tables (invalid tables don't end paragraph)", ` {P:Hello | abc | def | | --- | | bar |}`) test("Task list (example 279)", ` {BL:{LI:{l:-} {T:{t:[ ]} foo}} {LI:{l:-} {T:{t:[x]} bar}}}`) test("Task list (example 280)", ` {BL:{LI:{l:-} {T:{t:[x]} foo} {BL:{LI:{l:-} {T:{t:[ ]} bar}} {LI:{l:-} {T:{t:[x]} baz}}}} {LI:{l:-} {T:{t:[ ]} bim}}}`) test("Autolink (example 622)", ` {P:{URL:www.commonmark.org}}`) test("Autolink (example 623)", ` {P:Visit {URL:www.commonmark.org/help} for more information.}`) test("Autolink (example 624)", ` {P:Visit {URL:www.commonmark.org}.} {P:Visit {URL:www.commonmark.org/a.b}.}`) test("Autolink (example 625)", ` {P:{URL:www.google.com/search?q=Markup+(business)}} {P:{URL:www.google.com/search?q=Markup+(business)}))} {P:({URL:www.google.com/search?q=Markup+(business)})} {P:({URL:www.google.com/search?q=Markup+(business)}}`) test("Autolink (example 626)", ` {P:{URL:www.google.com/search?q=(business))+ok}}`) test("Autolink (example 627)", ` {P:{URL:www.google.com/search?q=commonmark&hl=en}} {P:{URL:www.google.com/search?q=commonmark}{Entity:&hl;}}`) test("Autolink (example 628)", ` {P:{URL:www.commonmark.org/he} No quote, no ^sup^} {P:No setext either ===}`, parser.configure({remove: ["Superscript", "Blockquote", "SetextHeading"]})) test("Autolink (.co.uk)", ` {P:{URL:www.blah.co.uk/path}}`) test("Autolink (email .co.uk)", ` {P:{URL:foo@bar.co.uk}}`) test("Autolink (http://www.foo-bar.com/)", ` {P:{URL:http://www.foo-bar.com/}}`) test("Autolink (exclude underscores)", ` {P:http://www.foo_/ http://foo_.com}`) test("Autolink (in image)", ` {P:{Im:{L:![}Link: {URL:http://foo.com/}{L:]}{L:(}{URL:x.jpg}{L:)}}}`) })