Compare commits

...

2 commits

Author SHA1 Message Date
Ajay Bura
a430c0dfd7 remove paragraph from markdown 2022-10-22 16:31:26 +05:30
Ajay Bura
e850d48fc3 Fix #898, #897 2022-10-11 20:07:26 +05:30

View file

@ -82,12 +82,22 @@ const plainRules = {
},
newline: {
...defaultRules.newline,
match: blockRegex(/^ *\n/),
plain: () => '\n',
html: () => '<br>',
},
paragraph: {
...defaultRules.paragraph,
plain: (node, output, state) => `${output(node.content, state)}\n\n`,
html: (node, output, state) => htmlTag('p', output(node.content, state)),
match: (source, 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: {
...defaultRules.escape,
@ -101,9 +111,7 @@ const plainRules = {
text: {
...defaultRules.text,
match: anyScopeRegex(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]| *\n|\w+:\S|$)/),
plain: (node, _, state) => (state.kind === 'edit'
? node.content.replace(/(\*|_|!\[|\[|\|\||\$\$?)/g, '\\$1')
: node.content),
plain: (node) => node.content,
},
};
@ -138,7 +146,15 @@ const markdownRules = {
},
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: {
...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 plainHtmlOut = outputFor(plainRules, 'html');
const mdParser = parserFor(markdownRules);
const mdParser = parserFor(markdownRules, { disableAutoBlockNewlines: true });
const mdPlainOut = outputFor(markdownRules, 'plain');
const mdHtmlOut = outputFor(markdownRules, 'html');