Archived
1
0
Fork 0

par(md): use space instead of \s

This commit is contained in:
Dmitriy Pleshevskiy 2022-06-13 23:44:16 +03:00
parent 7c1d876b36
commit ac60fc50bf
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 12 additions and 16 deletions

View file

@ -1,6 +1,6 @@
test-w: test-w:
deno test --watch deno test --allow-read --watch
test: test:
deno test deno test

View file

@ -293,22 +293,18 @@ Deno.test({
// Doc // Doc
Deno.test({ Deno.test({
name: "should parse all document", name: "should parse all document from file",
fn: () => { fn: () => {
const par = new MarkdownParser(); const par = new MarkdownParser();
const content = `\ assertEquals(
# What is Lorem Ipsum? ren.render(par.parse(Deno.readTextFileSync("test_data/doc_01.md"))),
"<h1>What is Lorem Ipsum?</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><ul><li>Sed in orci non lorem luctus dictum ac vel justo.</li><li>Nunc non leo vel dolor fringilla imperdiet.</li><li>Proin finibus ipsum quis molestie porta.</li></ul>",
Lorem Ipsum is simply dummy text of the printing and typesetting industry. );
- Sed in orci non lorem luctus dictum ac vel justo.
- Nunc non leo vel dolor fringilla imperdiet.
- Proin finibus ipsum quis molestie porta.`;
assertEquals( assertEquals(
ren.render(par.parse(content)), ren.render(par.parse(Deno.readTextFileSync("test_data/doc_02.md"))),
"<h1>What is Lorem Ipsum?</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><ul><li>Sed in orci non lorem luctus dictum ac vel justo.</li><li>Nunc non leo vel dolor fringilla imperdiet.</li><li>Proin finibus ipsum quis molestie porta.</li></ul>", "<h1>What is Lorem Ipsum?</h1><ul><li>Sed in orci non lorem luctus dictum ac vel justo.</li><li>Nunc non leo vel dolor fringilla imperdiet.</li><li>Proin finibus ipsum quis molestie porta.</li></ul>",
); );
}, },
}); });

View file

@ -2,12 +2,12 @@ import { AnyNode, Elem, Fragment, TextNode } from "../core/node.ts";
import { isNil, Nilable } from "../core/utils.ts"; import { isNil, Nilable } from "../core/utils.ts";
import { Parser } from "./types.ts"; import { Parser } from "./types.ts";
const RE_EMPTY_LINE = /^[ \t]*\r?\n/; const RE_EMPTY_LINE = /^[ ]*\r?\n/;
const RE_OPEN_ATX_HEADING = /^\s{0,3}(#{1,6})(\s|$)/; const RE_OPEN_ATX_HEADING = /^[ ]{0,3}(#{1,6})([ ]|$)/;
const RE_CLOSE_ATX_HEADING = /(^|\s+)#*\s*$/; const RE_CLOSE_ATX_HEADING = /(^|[ ]+)#*[ ]*$/;
const RE_LIST_ITEM = /^\s{0,3}([-+*])(\s|$)/; const RE_LIST_ITEM = /^[ ]{0,3}([-+*])([ ]|$)/;
// TODO: make better regex for destination // TODO: make better regex for destination
const RE_LINK = /\[([\s\S]*?)]\((?:([^\s]*)|<(.+?)>)(?: ('|")(.+?)\4)?\)/; const RE_LINK = /\[([\s\S]*?)]\((?:([^\s]*)|<(.+?)>)(?: ('|")(.+?)\4)?\)/;