diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-17 21:10:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-17 21:10:35 +0300 |
commit | 4484c8523126ee1de864bbcac43c706252d580be (patch) | |
tree | 5dff926e0deb8d55ce79c7c563f8fa7b1706a128 /app/assets/javascripts/content_editor | |
parent | 20dbd96076a6d09d20a9ac3caa1f35506d82340b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/content_editor')
3 files changed, 84 insertions, 0 deletions
diff --git a/app/assets/javascripts/content_editor/extensions/reference.js b/app/assets/javascripts/content_editor/extensions/reference.js new file mode 100644 index 00000000000..5f4484af9c8 --- /dev/null +++ b/app/assets/javascripts/content_editor/extensions/reference.js @@ -0,0 +1,78 @@ +import { Node } from '@tiptap/core'; + +export default Node.create({ + name: 'reference', + + inline: true, + + group: 'inline', + + atom: true, + + addAttributes() { + return { + className: { + default: null, + parseHTML: (element) => { + return { + className: element.className, + }; + }, + }, + referenceType: { + default: null, + parseHTML: (element) => { + return { + referenceType: element.dataset.referenceType, + }; + }, + }, + originalText: { + default: null, + parseHTML: (element) => { + return { + originalText: element.dataset.original, + }; + }, + }, + href: { + default: null, + parseHTML: (element) => { + return { + href: element.getAttribute('href'), + }; + }, + }, + text: { + default: null, + parseHTML: (element) => { + return { + text: element.textContent, + }; + }, + }, + }; + }, + + parseHTML() { + return [ + { + tag: 'a.gfm:not([data-link=true])', + priority: 51, + }, + ]; + }, + + renderHTML({ node }) { + return [ + 'a', + { + class: node.attrs.className, + href: node.attrs.href, + 'data-reference-type': node.attrs.referenceType, + 'data-original': node.attrs.originalText, + }, + node.attrs.text, + ]; + }, +}); diff --git a/app/assets/javascripts/content_editor/services/create_content_editor.js b/app/assets/javascripts/content_editor/services/create_content_editor.js index 4bb4d55a816..8997960203a 100644 --- a/app/assets/javascripts/content_editor/services/create_content_editor.js +++ b/app/assets/javascripts/content_editor/services/create_content_editor.js @@ -23,6 +23,7 @@ import ListItem from '../extensions/list_item'; import Loading from '../extensions/loading'; import OrderedList from '../extensions/ordered_list'; import Paragraph from '../extensions/paragraph'; +import Reference from '../extensions/reference'; import Strike from '../extensions/strike'; import Subscript from '../extensions/subscript'; import Superscript from '../extensions/superscript'; @@ -82,6 +83,7 @@ export const createContentEditor = ({ Loading, OrderedList, Paragraph, + Reference, Strike, Subscript, Superscript, diff --git a/app/assets/javascripts/content_editor/services/markdown_serializer.js b/app/assets/javascripts/content_editor/services/markdown_serializer.js index 80ad3e15a42..df4d31c3d7f 100644 --- a/app/assets/javascripts/content_editor/services/markdown_serializer.js +++ b/app/assets/javascripts/content_editor/services/markdown_serializer.js @@ -19,6 +19,7 @@ import Link from '../extensions/link'; import ListItem from '../extensions/list_item'; import OrderedList from '../extensions/ordered_list'; import Paragraph from '../extensions/paragraph'; +import Reference from '../extensions/reference'; import Strike from '../extensions/strike'; import Subscript from '../extensions/subscript'; import Superscript from '../extensions/superscript'; @@ -91,6 +92,9 @@ const defaultSerializerConfig = { [ListItem.name]: defaultMarkdownSerializer.nodes.list_item, [OrderedList.name]: defaultMarkdownSerializer.nodes.ordered_list, [Paragraph.name]: defaultMarkdownSerializer.nodes.paragraph, + [Reference.name]: (state, node) => { + state.write(node.attrs.originalText || node.attrs.text); + }, [Table.name]: (state, node) => { state.renderContent(node); }, |