fix: parser regexp for special character (#439)
This commit is contained in:
parent
a313a9bb31
commit
9866702850
13 changed files with 26 additions and 12 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-irregular-whitespace */
|
||||||
import { describe, expect, test } from "@jest/globals";
|
import { describe, expect, test } from "@jest/globals";
|
||||||
import { unescape } from "lodash-es";
|
import { unescape } from "lodash-es";
|
||||||
import { marked } from ".";
|
import { marked } from ".";
|
||||||
|
|
@ -170,4 +171,17 @@ text below the table
|
||||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
test("parse full width space", () => {
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
markdown: ` line1
|
||||||
|
line2`,
|
||||||
|
want: `<p> line1</p>
|
||||||
|
<p> line2</p>`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
for (const t of tests) {
|
||||||
|
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { escape } from "lodash";
|
import { escape } from "lodash";
|
||||||
|
|
||||||
export const BLOCKQUOTE_REG = /^>\s+([\S ]+)(\n?)/;
|
export const BLOCKQUOTE_REG = /^>\s+(.+)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(BLOCKQUOTE_REG);
|
const matchResult = rawStr.match(BLOCKQUOTE_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
import Link from "./Link";
|
import Link from "./Link";
|
||||||
|
|
||||||
export const BOLD_REG = /\*\*([\S ]+?)\*\*/;
|
export const BOLD_REG = /\*\*(.+?)\*\*/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(BOLD_REG);
|
const matchResult = rawStr.match(BOLD_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
import Link from "./Link";
|
import Link from "./Link";
|
||||||
|
|
||||||
export const BOLD_EMPHASIS_REG = /\*\*\*([\S ]+?)\*\*\*/;
|
export const BOLD_EMPHASIS_REG = /\*\*\*(.+?)\*\*\*/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(BOLD_EMPHASIS_REG);
|
const matchResult = rawStr.match(BOLD_EMPHASIS_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { inlineElementParserList } from ".";
|
import { inlineElementParserList } from ".";
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
|
|
||||||
export const DONE_LIST_REG = /^- \[x\] ([\S ]+)(\n?)/;
|
export const DONE_LIST_REG = /^- \[x\] (.+)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(DONE_LIST_REG);
|
const matchResult = rawStr.match(DONE_LIST_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
import Link from "./Link";
|
import Link from "./Link";
|
||||||
|
|
||||||
export const EMPHASIS_REG = /\*([\S ]+?)\*/;
|
export const EMPHASIS_REG = /\*(.+?)\*/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(EMPHASIS_REG);
|
const matchResult = rawStr.match(EMPHASIS_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { escape } from "lodash-es";
|
import { escape } from "lodash-es";
|
||||||
|
|
||||||
export const INLINE_CODE_REG = /`([\S ]+?)`/;
|
export const INLINE_CODE_REG = /`(.+?)`/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(INLINE_CODE_REG);
|
const matchResult = rawStr.match(INLINE_CODE_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { escape } from "lodash-es";
|
import { escape } from "lodash-es";
|
||||||
|
|
||||||
export const MARK_REG = /@\[([\S ]+?)\]\((\S+?)\)/;
|
export const MARK_REG = /@\[(.+?)\]\((\S+?)\)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(MARK_REG);
|
const matchResult = rawStr.match(MARK_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { inlineElementParserList } from ".";
|
import { inlineElementParserList } from ".";
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
|
|
||||||
export const ORDERED_LIST_REG = /^(\d+)\. ([\S ]+)(\n?)/;
|
export const ORDERED_LIST_REG = /^(\d+)\. (.+)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(ORDERED_LIST_REG);
|
const matchResult = rawStr.match(ORDERED_LIST_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { inlineElementParserList } from ".";
|
import { inlineElementParserList } from ".";
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
|
|
||||||
export const PARAGRAPH_REG = /^([\S ]*)(\n?)/;
|
export const PARAGRAPH_REG = /^(.*)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(PARAGRAPH_REG);
|
const matchResult = rawStr.match(PARAGRAPH_REG);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { escape } from "lodash-es";
|
import { escape } from "lodash-es";
|
||||||
|
|
||||||
export const PLAIN_TEXT_REG = /([\S ]+)/;
|
export const PLAIN_TEXT_REG = /(.+)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(PLAIN_TEXT_REG);
|
const matchResult = rawStr.match(PLAIN_TEXT_REG);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { escape } from "lodash-es";
|
||||||
import { inlineElementParserList } from ".";
|
import { inlineElementParserList } from ".";
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
|
|
||||||
export const TODO_LIST_REG = /^- \[ \] ([\S ]+)(\n?)/;
|
export const TODO_LIST_REG = /^- \[ \] (.+)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(TODO_LIST_REG);
|
const matchResult = rawStr.match(TODO_LIST_REG);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { escape } from "lodash-es";
|
||||||
import { inlineElementParserList } from ".";
|
import { inlineElementParserList } from ".";
|
||||||
import { marked } from "..";
|
import { marked } from "..";
|
||||||
|
|
||||||
export const UNORDERED_LIST_REG = /^[*-] ([\S ]+)(\n?)/;
|
export const UNORDERED_LIST_REG = /^[*-] (.+)(\n?)/;
|
||||||
|
|
||||||
const renderer = (rawStr: string): string => {
|
const renderer = (rawStr: string): string => {
|
||||||
const matchResult = rawStr.match(UNORDERED_LIST_REG);
|
const matchResult = rawStr.match(UNORDERED_LIST_REG);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue