diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-26 18:08:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-26 18:08:29 +0300 |
commit | cac0926ddbef9d1505c2a23ccad60fd47c7d050a (patch) | |
tree | ef6808933314a104d004528f7c84716dc472d93a /app/assets/javascripts/content_editor | |
parent | afd476d5fd62d31c7e0b7509691fa18e632a60df (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/content_editor')
-rw-r--r-- | app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js b/app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js index 067965f53eb..9f8505416ba 100644 --- a/app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js +++ b/app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js @@ -63,10 +63,12 @@ function maybeMerge(a, b) { function createSourceMapAttributes(hastNode, source) { const { position } = hastNode; - return { - sourceMapKey: `${position.start.offset}:${position.end.offset}`, - sourceMarkdown: source.substring(position.start.offset, position.end.offset), - }; + return position.end + ? { + sourceMapKey: `${position.start.offset}:${position.end.offset}`, + sourceMarkdown: source.substring(position.start.offset, position.end.offset), + } + : {}; } /** @@ -252,11 +254,19 @@ const createProseMirrorNodeFactories = (schema, proseMirrorFactorySpecs, source) const factories = { root: { selector: 'root', - handle: (state, hastNode) => state.openNode(schema.topNodeType, hastNode, {}), + handle: (state, hastNode) => + state.openNode( + schema.topNodeType, + hastNode, + {}, + { + wrapTextInParagraph: true, + }, + ), }, text: { selector: 'text', - handle: (state, hastNode) => { + handle: (state, hastNode, parent) => { const { factorySpec } = state.top; if (/^\s+$/.test(hastNode.value)) { @@ -264,7 +274,7 @@ const createProseMirrorNodeFactories = (schema, proseMirrorFactorySpecs, source) } if (factorySpec.wrapTextInParagraph === true) { - state.openNode(schema.nodeType('paragraph')); + state.openNode(schema.nodeType('paragraph'), hastNode, getAttrs({}, parent, [], source)); state.addText(schema, hastNode.value); state.closeNode(); } else { |