remove paragraph from markdown
This commit is contained in:
parent
e850d48fc3
commit
a430c0dfd7
1 changed files with 16 additions and 7 deletions
|
@ -82,13 +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,
|
||||||
match: blockRegex(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)+\n/),
|
match: (source, state) => {
|
||||||
plain: (node, output, state) => `${output(node.content, state)}\n`,
|
const endMatch = blockRegex(/^([^\n]*)\n*$/);
|
||||||
html: (node, output, state) => htmlTag('p', output(node.content, state)),
|
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,
|
||||||
|
@ -141,10 +150,10 @@ const markdownRules = {
|
||||||
parse: (capture, parse, state) => {
|
parse: (capture, parse, state) => {
|
||||||
const content = capture[0].replace(/^ *> ?/gm, '');
|
const content = capture[0].replace(/^ *> ?/gm, '');
|
||||||
return {
|
return {
|
||||||
content: parse(`${content}\n`, state), // TODO: remove /n after fixing paragraph
|
content: parse(`${content}`, state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
plain: (node, output, state) => `> ${output(node.content, state).trim().replace(/\n/g, '\n> ')}`,
|
plain: (node, output, state) => `> ${output(node.content, state).trim().replace(/\n/g, '\n> ')}\n`,
|
||||||
html: (node, output, state) => htmlTag('blockquote', output(node.content, state)),
|
html: (node, output, state) => htmlTag('blockquote', output(node.content, state)),
|
||||||
},
|
},
|
||||||
list: {
|
list: {
|
||||||
|
@ -499,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