mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 16:42:17 +03:00
0fa0068f6a
refs https://github.com/TryGhost/Ghost/issues/9623 - adds `parserPlugins` option with array of parser plugins that read node values and convert them when pasting - converts `<br>` to a soft-break atom for line breaks - removes leading newlines from text nodes to avoid leading spaces in the render output (common when pasting MD with line breaks)
28 lines
809 B
JavaScript
28 lines
809 B
JavaScript
// mobiledoc by default ignores <BR> tags but we have a custom SoftReturn atom
|
|
export function brToSoftBreakAtom(node, builder, {addMarkerable, nodeFinished}) {
|
|
if (node.nodeType !== 1 || node.tagName !== 'BR') {
|
|
return;
|
|
}
|
|
|
|
let softReturn = builder.createAtom('soft-return');
|
|
addMarkerable(softReturn);
|
|
|
|
nodeFinished();
|
|
}
|
|
|
|
// leading newlines in text nodes will add a space to the beginning of the text
|
|
// which doesn't render correctly if we're replacing <br> with SoftReturn atoms
|
|
// after parsing text as markdown to html
|
|
export function removeLeadingNewline(node) {
|
|
if (node.nodeType !== 3 || node.nodeName !== '#text') {
|
|
return;
|
|
}
|
|
|
|
node.nodeValue = node.nodeValue.replace(/^\n/, '');
|
|
}
|
|
|
|
export default [
|
|
brToSoftBreakAtom,
|
|
removeLeadingNewline,
|
|
];
|