update: markdown parser

This commit is contained in:
yanmao 2022-01-07 15:10:10 +08:00
parent c587b0997e
commit 0d34ca84f6
8 changed files with 16 additions and 14 deletions

View File

@ -234,7 +234,7 @@ export default class<
if (!isEngine(this.editor) || !this.markdown || !node.isText()) return;
const text = node.text();
if (!text) return;
const reg = /```/;
const reg = /`{3,}/;
const match = reg.exec(text);
return {
reg,
@ -287,7 +287,7 @@ export default class<
let isCode: boolean = false;
let mode = 'text';
rows.forEach((row) => {
let match = /^(.*)```(\s)*$/.exec(row);
let match = /^(.*)`{3,}(\s)*$/.exec(row);
if (match && isCode) {
nodes.push(match[1]);
newText += createCodeblock(nodes, mode) + '\n';
@ -296,7 +296,7 @@ export default class<
nodes = [];
return;
}
match = /^```(.*)/.exec(row);
match = /^`{3,}(.*)/.exec(row);
if (match) {
isCode = true;
mode =

View File

@ -234,7 +234,7 @@ export default class<
if (!isEngine(this.editor) || !this.markdown || !node.isText()) return;
const text = node.text();
if (!text) return;
const reg = /```/;
const reg = /`{3,}/;
const match = reg.exec(text);
return {
reg,
@ -287,7 +287,7 @@ export default class<
let isCode: boolean = false;
let mode = 'text';
rows.forEach((row) => {
let match = /^(.*)```(\s)*$/.exec(row);
let match = /^(.*)`{3,}(\s)*$/.exec(row);
if (match && isCode) {
nodes.push(match[1]);
newText += createCodeblock(nodes, mode) + '\n';
@ -296,7 +296,7 @@ export default class<
nodes = [];
return;
}
match = /^```(.*)/.exec(row);
match = /^`{3,}(.*)/.exec(row);
if (match) {
isCode = true;
mode =

View File

@ -407,7 +407,9 @@ export default class<T extends HeadingOptions> extends BlockPlugin<T> {
if (enableTypes && enableTypes.indexOf(`h${codeLength}`) < 0) {
newText += match[2] + match[3];
} else
newText += `<h${codeLength}>${match[3].trim()}</h${codeLength}>\n`;
newText +=
match[1] +
`<h${codeLength}>${match[3].trim()}</h${codeLength}>\n`;
}
newText += textNode.textContent;

View File

@ -103,8 +103,8 @@ export default class<T extends HrOptions = HrOptions> extends Plugin<T> {
const cardNode = card.replaceNode($(regNode), 'hr');
regNode.remove();
newText += cardNode.get<Element>()?.outerHTML + '\n';
// match[1] 把之前的换行符补上
newText += match[1] + cardNode.get<Element>()?.outerHTML + '\n';
}
newText += textNode.textContent;
node.text(newText);

View File

@ -152,7 +152,7 @@ export default class<T extends OrderedListOptions> extends ListPlugin<T> {
return listNode.get<Element>()?.outerHTML;
};
const text = node.text();
let newText = '';
let newText = match[1] || '';
const rows = text.split(/\n|\r\n/);
let nodes: Array<string> = [];
let indent = 0;

View File

@ -121,11 +121,11 @@ export default class<T extends QuoteOptions> extends BlockPlugin<T> {
pasteMarkdown(node: NodeInterface) {
const result = this.checkMarkdown(node);
if (!result) return;
const { reg, match } = result;
const { match } = result;
if (!match) return;
const text = node.text();
let newText = '';
let newText = match[1] || '';
const rows = text.split(/\n|\r\n/);
let nodes: Array<string> = [];
rows.forEach((row) => {

View File

@ -261,7 +261,7 @@ export default class<
return listNode.get<Element>()?.outerHTML;
};
const text = node.text();
let newText = '';
let newText = match[1] || '';
const rows = text.split(/\n|\r\n/);
let nodes: Array<string> = [];
let indent = 0;

View File

@ -155,7 +155,7 @@ export default class<T extends UnorderedlistOptions> extends ListPlugin<T> {
return listNode.get<Element>()?.outerHTML;
};
const text = node.text();
let newText = '';
let newText = match[1] || '';
const rows = text.split(/\n|\r\n/);
let nodes: Array<string> = [];
let indent = 0;