Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-13 00:09:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-13 00:09:53 +0300
commitb6f17c69925beded921017fa049385de715553ba (patch)
tree5f8b2a5fbc6b1e779b7421ceddd219065e65fec9 /app/assets/javascripts/content_editor
parent0ba11d8461a2b091d37bb6308d85e74f2b133803 (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/extensions/sourcemap.js10
-rw-r--r--app/assets/javascripts/content_editor/services/hast_to_prosemirror_converter.js6
-rw-r--r--app/assets/javascripts/content_editor/services/markdown_serializer.js12
-rw-r--r--app/assets/javascripts/content_editor/services/remark_markdown_deserializer.js5
-rw-r--r--app/assets/javascripts/content_editor/services/serialization_helpers.js10
5 files changed, 30 insertions, 13 deletions
diff --git a/app/assets/javascripts/content_editor/extensions/sourcemap.js b/app/assets/javascripts/content_editor/extensions/sourcemap.js
index 87118074462..618f17b1c5e 100644
--- a/app/assets/javascripts/content_editor/extensions/sourcemap.js
+++ b/app/assets/javascripts/content_editor/extensions/sourcemap.js
@@ -9,6 +9,7 @@ import FootnoteDefinition from './footnote_definition';
import Heading from './heading';
import HardBreak from './hard_break';
import HorizontalRule from './horizontal_rule';
+import HTMLNodes from './html_nodes';
import Image from './image';
import Italic from './italic';
import Link from './link';
@@ -51,13 +52,22 @@ export default Extension.create({
TableCell.name,
TableHeader.name,
TableRow.name,
+ ...HTMLNodes.map((htmlNode) => htmlNode.name),
],
attributes: {
+ /**
+ * The reason to add a function that returns an empty
+ * string in these attributes is indicate that these
+ * attributes shouldn’t be rendered in the ProseMirror
+ * view.
+ */
sourceMarkdown: {
default: null,
+ renderHTML: () => '',
},
sourceMapKey: {
default: null,
+ renderHTML: () => '',
},
},
},
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 2c462cdde91..6859ebc2c5a 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
@@ -570,11 +570,7 @@ export const createProseMirrorDocFromMdastTree = ({
const factory = findFactory(hastNode, ancestors, proseMirrorNodeFactories);
if (!factory) {
- throw new Error(
- `Hast node of type "${
- hastNode.tagName || hastNode.type
- }" not supported by this converter. Please, provide an specification.`,
- );
+ return SKIP;
}
const parent = findParent(ancestors, factory.parent);
diff --git a/app/assets/javascripts/content_editor/services/markdown_serializer.js b/app/assets/javascripts/content_editor/services/markdown_serializer.js
index c7e05072927..c1c7af6b1af 100644
--- a/app/assets/javascripts/content_editor/services/markdown_serializer.js
+++ b/app/assets/javascripts/content_editor/services/markdown_serializer.js
@@ -170,12 +170,6 @@ const defaultSerializerConfig = {
[HardBreak.name]: preserveUnchanged(renderHardBreak),
[Heading.name]: preserveUnchanged(defaultMarkdownSerializer.nodes.heading),
[HorizontalRule.name]: preserveUnchanged(defaultMarkdownSerializer.nodes.horizontal_rule),
- ...HTMLNodes.reduce((serializers, htmlNode) => {
- return {
- ...serializers,
- [htmlNode.name]: (state, node) => renderHTMLNode(htmlNode.options.tagName)(state, node),
- };
- }, {}),
[Image.name]: preserveUnchanged(renderImage),
[ListItem.name]: preserveUnchanged(defaultMarkdownSerializer.nodes.list_item),
[OrderedList.name]: preserveUnchanged(renderOrderedList),
@@ -202,6 +196,12 @@ const defaultSerializerConfig = {
[Text.name]: defaultMarkdownSerializer.nodes.text,
[Video.name]: renderPlayable,
[WordBreak.name]: (state) => state.write('<wbr>'),
+ ...HTMLNodes.reduce((serializers, htmlNode) => {
+ return {
+ ...serializers,
+ [htmlNode.name]: (state, node) => renderHTMLNode(htmlNode.options.tagName)(state, node),
+ };
+ }, {}),
},
};
diff --git a/app/assets/javascripts/content_editor/services/remark_markdown_deserializer.js b/app/assets/javascripts/content_editor/services/remark_markdown_deserializer.js
index da10c684b0b..8c99dc157e6 100644
--- a/app/assets/javascripts/content_editor/services/remark_markdown_deserializer.js
+++ b/app/assets/javascripts/content_editor/services/remark_markdown_deserializer.js
@@ -88,6 +88,11 @@ const factorySpecs = {
selector: (hastNode, ancestors) =>
hastNode.tagName === 'input' && isTaskItem(ancestors[ancestors.length - 1]),
},
+ div: {
+ type: 'block',
+ selector: 'div',
+ wrapInParagraph: true,
+ },
table: {
type: 'block',
selector: 'table',
diff --git a/app/assets/javascripts/content_editor/services/serialization_helpers.js b/app/assets/javascripts/content_editor/services/serialization_helpers.js
index 88f5192af77..7d5e718b41c 100644
--- a/app/assets/javascripts/content_editor/services/serialization_helpers.js
+++ b/app/assets/javascripts/content_editor/services/serialization_helpers.js
@@ -5,6 +5,8 @@ const defaultAttrs = {
th: { colspan: 1, rowspan: 1, colwidth: null },
};
+const defaultIgnoreAttrs = ['sourceMarkdown', 'sourceMapKey'];
+
const ignoreAttrs = {
dd: ['isTerm'],
dt: ['isTerm'],
@@ -101,13 +103,17 @@ function htmlEncode(str = '') {
.replace(/"/g, '&#34;');
}
+const shouldIgnoreAttr = (tagName, attrKey, attrValue) =>
+ ignoreAttrs[tagName]?.includes(attrKey) ||
+ defaultIgnoreAttrs.includes(attrKey) ||
+ defaultAttrs[tagName]?.[attrKey] === attrValue;
+
export function openTag(tagName, attrs) {
let str = `<${tagName}`;
str += Object.entries(attrs || {})
.map(([key, value]) => {
- if ((ignoreAttrs[tagName] || []).includes(key) || defaultAttrs[tagName]?.[key] === value)
- return '';
+ if (shouldIgnoreAttr(tagName, key, value)) return '';
return ` ${key}="${htmlEncode(value?.toString())}"`;
})