diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-21 03:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-21 03:08:43 +0300 |
commit | 92ea86691a2a6b3df4b36c7ff00001410303a701 (patch) | |
tree | 9b3764b56303c9b65e17007c589a297775834b28 /scripts/lib | |
parent | 991c66333dc7bdb0fd6f7a0b7f7bdf8383285975 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/glfm/render_wysiwyg_html_and_json.js | 112 |
1 files changed, 1 insertions, 111 deletions
diff --git a/scripts/lib/glfm/render_wysiwyg_html_and_json.js b/scripts/lib/glfm/render_wysiwyg_html_and_json.js index 58b440d7ab2..ed8bfdb4638 100644 --- a/scripts/lib/glfm/render_wysiwyg_html_and_json.js +++ b/scripts/lib/glfm/render_wysiwyg_html_and_json.js @@ -1,117 +1,7 @@ import fs from 'fs'; -import { DOMSerializer } from 'prosemirror-model'; import jsYaml from 'js-yaml'; -// TODO: DRY up duplication with spec/frontend/content_editor/services/markdown_serializer_spec.js -// See https://gitlab.com/groups/gitlab-org/-/epics/7719#plan -import Blockquote from '~/content_editor/extensions/blockquote'; -import Bold from '~/content_editor/extensions/bold'; -import BulletList from '~/content_editor/extensions/bullet_list'; -import Code from '~/content_editor/extensions/code'; -import CodeBlockHighlight from '~/content_editor/extensions/code_block_highlight'; -import DescriptionItem from '~/content_editor/extensions/description_item'; -import DescriptionList from '~/content_editor/extensions/description_list'; -import Details from '~/content_editor/extensions/details'; -import DetailsContent from '~/content_editor/extensions/details_content'; -import Division from '~/content_editor/extensions/division'; -import Emoji from '~/content_editor/extensions/emoji'; -import Figure from '~/content_editor/extensions/figure'; -import FigureCaption from '~/content_editor/extensions/figure_caption'; -import FootnoteDefinition from '~/content_editor/extensions/footnote_definition'; -import FootnoteReference from '~/content_editor/extensions/footnote_reference'; -import FootnotesSection from '~/content_editor/extensions/footnotes_section'; -import HardBreak from '~/content_editor/extensions/hard_break'; -import Heading from '~/content_editor/extensions/heading'; -import HorizontalRule from '~/content_editor/extensions/horizontal_rule'; -import Image from '~/content_editor/extensions/image'; -import InlineDiff from '~/content_editor/extensions/inline_diff'; -import Italic from '~/content_editor/extensions/italic'; -import Link from '~/content_editor/extensions/link'; -import ListItem from '~/content_editor/extensions/list_item'; -import OrderedList from '~/content_editor/extensions/ordered_list'; -import Strike from '~/content_editor/extensions/strike'; -import Table from '~/content_editor/extensions/table'; -import TableCell from '~/content_editor/extensions/table_cell'; -import TableHeader from '~/content_editor/extensions/table_header'; -import TableRow from '~/content_editor/extensions/table_row'; -import TaskItem from '~/content_editor/extensions/task_item'; -import TaskList from '~/content_editor/extensions/task_list'; -import createMarkdownDeserializer from '~/content_editor/services/remark_markdown_deserializer'; -import { createTestEditor } from 'jest/content_editor/test_utils'; import { setTestTimeout } from 'jest/__helpers__/timeout'; - -const tiptapEditor = createTestEditor({ - extensions: [ - Blockquote, - Bold, - BulletList, - Code, - CodeBlockHighlight, - DescriptionItem, - DescriptionList, - Details, - DetailsContent, - Division, - Emoji, - FootnoteDefinition, - FootnoteReference, - FootnotesSection, - Figure, - FigureCaption, - HardBreak, - Heading, - HorizontalRule, - Image, - InlineDiff, - Italic, - Link, - ListItem, - OrderedList, - Strike, - Table, - TableCell, - TableHeader, - TableRow, - TaskItem, - TaskList, - ], -}); - -async function renderMarkdownToHTMLAndJSON(markdown, schema, deserializer) { - let prosemirrorDocument; - try { - const { document } = await deserializer.deserialize({ schema, content: markdown }); - prosemirrorDocument = document; - } catch (e) { - const errorMsg = `Error - check implementation:\n${e.message}`; - return { - html: errorMsg, - json: errorMsg, - }; - } - - const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment( - prosemirrorDocument.content, - ); - const htmlString = documentFragment.firstChild.outerHTML; - - const json = prosemirrorDocument.toJSON(); - const jsonString = JSON.stringify(json, null, 2); - return { html: htmlString, json: jsonString }; -} - -function renderHtmlAndJsonForAllExamples(markdownExamples) { - const { schema } = tiptapEditor; - const deserializer = createMarkdownDeserializer(); - const exampleNames = Object.keys(markdownExamples); - - return exampleNames.reduce(async (promisedExamples, exampleName) => { - const markdown = markdownExamples[exampleName]; - const htmlAndJson = await renderMarkdownToHTMLAndJSON(markdown, schema, deserializer); - const examples = await promisedExamples; - examples[exampleName] = htmlAndJson; - return examples; - }, Promise.resolve({})); -} +import { renderHtmlAndJsonForAllExamples } from 'jest/content_editor/render_html_and_json_for_all_examples'; /* eslint-disable no-undef */ jest.mock('~/emoji'); |