Compare commits
2 commits
dev
...
fix/markdo
Author | SHA1 | Date | |
---|---|---|---|
|
a430c0dfd7 | ||
|
e850d48fc3 |
1 changed files with 24 additions and 8 deletions
|
@ -82,12 +82,22 @@ const plainRules = {
|
||||||
},
|
},
|
||||||
newline: {
|
newline: {
|
||||||
...defaultRules.newline,
|
...defaultRules.newline,
|
||||||
|
match: blockRegex(/^ *\n/),
|
||||||
plain: () => '\n',
|
plain: () => '\n',
|
||||||
|
html: () => '<br>',
|
||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
...defaultRules.paragraph,
|
...defaultRules.paragraph,
|
||||||
plain: (node, output, state) => `${output(node.content, state)}\n\n`,
|
match: (source, state) => {
|
||||||
html: (node, output, state) => htmlTag('p', output(node.content, state)),
|
const endMatch = blockRegex(/^([^\n]*)\n*$/);
|
||||||
|
if (endMatch) {
|
||||||
|
state.end = true;
|
||||||
|
return endMatch(source, state);
|
||||||
|
}
|
||||||
|
return blockRegex(/^([^\n]*)\n?/)(source, state);
|
||||||
|
},
|
||||||
|
plain: (node, output, state) => `${output(node.content, state)}${state.end ? '' : '\n'}`,
|
||||||
|
html: (node, output, state) => `${output(node.content, state)}${state.end ? '' : '<br>'}`,
|
||||||
},
|
},
|
||||||
escape: {
|
escape: {
|
||||||
...defaultRules.escape,
|
...defaultRules.escape,
|
||||||
|
@ -101,9 +111,7 @@ const plainRules = {
|
||||||
text: {
|
text: {
|
||||||
...defaultRules.text,
|
...defaultRules.text,
|
||||||
match: anyScopeRegex(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]| *\n|\w+:\S|$)/),
|
match: anyScopeRegex(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]| *\n|\w+:\S|$)/),
|
||||||
plain: (node, _, state) => (state.kind === 'edit'
|
plain: (node) => node.content,
|
||||||
? node.content.replace(/(\*|_|!\[|\[|\|\||\$\$?)/g, '\\$1')
|
|
||||||
: node.content),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,7 +146,15 @@ const markdownRules = {
|
||||||
},
|
},
|
||||||
blockQuote: {
|
blockQuote: {
|
||||||
...defaultRules.blockQuote,
|
...defaultRules.blockQuote,
|
||||||
plain: (node, output, state) => `> ${output(node.content, state).trim().replace(/\n/g, '\n> ')}\n\n`,
|
match: blockRegex(/^( *>[^\n]+(\n *>+[^\n]+)*\n?)+/),
|
||||||
|
parse: (capture, parse, state) => {
|
||||||
|
const content = capture[0].replace(/^ *> ?/gm, '');
|
||||||
|
return {
|
||||||
|
content: parse(`${content}`, state),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
plain: (node, output, state) => `> ${output(node.content, state).trim().replace(/\n/g, '\n> ')}\n`,
|
||||||
|
html: (node, output, state) => htmlTag('blockquote', output(node.content, state)),
|
||||||
},
|
},
|
||||||
list: {
|
list: {
|
||||||
...defaultRules.list,
|
...defaultRules.list,
|
||||||
|
@ -492,11 +508,11 @@ function render(content, state, plainOut, htmlOut) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const plainParser = parserFor(plainRules);
|
const plainParser = parserFor(plainRules, { disableAutoBlockNewlines: true });
|
||||||
const plainPlainOut = outputFor(plainRules, 'plain');
|
const plainPlainOut = outputFor(plainRules, 'plain');
|
||||||
const plainHtmlOut = outputFor(plainRules, 'html');
|
const plainHtmlOut = outputFor(plainRules, 'html');
|
||||||
|
|
||||||
const mdParser = parserFor(markdownRules);
|
const mdParser = parserFor(markdownRules, { disableAutoBlockNewlines: true });
|
||||||
const mdPlainOut = outputFor(markdownRules, 'plain');
|
const mdPlainOut = outputFor(markdownRules, 'plain');
|
||||||
const mdHtmlOut = outputFor(markdownRules, 'html');
|
const mdHtmlOut = outputFor(markdownRules, 'html');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue