fix: parser regexp for special character (#439)

This commit is contained in:
boojack 2022-11-10 20:38:14 +08:00 committed by GitHub
parent a313a9bb31
commit 9866702850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 12 deletions

View file

@ -1,3 +1,4 @@
/* eslint-disable no-irregular-whitespace */
import { describe, expect, test } from "@jest/globals";
import { unescape } from "lodash-es";
import { marked } from ".";
@ -170,4 +171,17 @@ text below the table
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);
}
});
});

View file

@ -1,6 +1,6 @@
import { escape } from "lodash";
export const BLOCKQUOTE_REG = /^>\s+([\S ]+)(\n?)/;
export const BLOCKQUOTE_REG = /^>\s+(.+)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(BLOCKQUOTE_REG);

View file

@ -1,7 +1,7 @@
import { marked } from "..";
import Link from "./Link";
export const BOLD_REG = /\*\*([\S ]+?)\*\*/;
export const BOLD_REG = /\*\*(.+?)\*\*/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(BOLD_REG);

View file

@ -1,7 +1,7 @@
import { marked } from "..";
import Link from "./Link";
export const BOLD_EMPHASIS_REG = /\*\*\*([\S ]+?)\*\*\*/;
export const BOLD_EMPHASIS_REG = /\*\*\*(.+?)\*\*\*/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(BOLD_EMPHASIS_REG);

View file

@ -1,7 +1,7 @@
import { inlineElementParserList } 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 matchResult = rawStr.match(DONE_LIST_REG);

View file

@ -1,7 +1,7 @@
import { marked } from "..";
import Link from "./Link";
export const EMPHASIS_REG = /\*([\S ]+?)\*/;
export const EMPHASIS_REG = /\*(.+?)\*/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(EMPHASIS_REG);

View file

@ -1,6 +1,6 @@
import { escape } from "lodash-es";
export const INLINE_CODE_REG = /`([\S ]+?)`/;
export const INLINE_CODE_REG = /`(.+?)`/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(INLINE_CODE_REG);

View file

@ -1,6 +1,6 @@
import { escape } from "lodash-es";
export const MARK_REG = /@\[([\S ]+?)\]\((\S+?)\)/;
export const MARK_REG = /@\[(.+?)\]\((\S+?)\)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(MARK_REG);

View file

@ -1,7 +1,7 @@
import { inlineElementParserList } 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 matchResult = rawStr.match(ORDERED_LIST_REG);

View file

@ -1,7 +1,7 @@
import { inlineElementParserList } from ".";
import { marked } from "..";
export const PARAGRAPH_REG = /^([\S ]*)(\n?)/;
export const PARAGRAPH_REG = /^(.*)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(PARAGRAPH_REG);

View file

@ -1,6 +1,6 @@
import { escape } from "lodash-es";
export const PLAIN_TEXT_REG = /([\S ]+)/;
export const PLAIN_TEXT_REG = /(.+)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(PLAIN_TEXT_REG);

View file

@ -2,7 +2,7 @@ import { escape } from "lodash-es";
import { inlineElementParserList } from ".";
import { marked } from "..";
export const TODO_LIST_REG = /^- \[ \] ([\S ]+)(\n?)/;
export const TODO_LIST_REG = /^- \[ \] (.+)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(TODO_LIST_REG);

View file

@ -2,7 +2,7 @@ import { escape } from "lodash-es";
import { inlineElementParserList } from ".";
import { marked } from "..";
export const UNORDERED_LIST_REG = /^[*-] ([\S ]+)(\n?)/;
export const UNORDERED_LIST_REG = /^[*-] (.+)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(UNORDERED_LIST_REG);