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:
Diffstat (limited to 'app/assets/javascripts/behaviors/markdown/nodes/code_block.js')
-rw-r--r--app/assets/javascripts/behaviors/markdown/nodes/code_block.js94
1 files changed, 0 insertions, 94 deletions
diff --git a/app/assets/javascripts/behaviors/markdown/nodes/code_block.js b/app/assets/javascripts/behaviors/markdown/nodes/code_block.js
deleted file mode 100644
index b862d111de7..00000000000
--- a/app/assets/javascripts/behaviors/markdown/nodes/code_block.js
+++ /dev/null
@@ -1,94 +0,0 @@
-const PLAINTEXT_LANG = 'plaintext';
-
-// Transforms generated HTML back to GFM for:
-// - Banzai::Filter::SyntaxHighlightFilter
-// - Banzai::Filter::MathFilter
-// - Banzai::Filter::MermaidFilter
-// - Banzai::Filter::SuggestionFilter
-export default () => ({
- name: 'code_block',
- schema: {
- content: 'text*',
- marks: '',
- group: 'block',
- code: true,
- defining: true,
- attrs: {
- lang: { default: PLAINTEXT_LANG },
- },
- parseDOM: [
- // Matches HTML generated by Banzai::Filter::SyntaxHighlightFilter, Banzai::Filter::MathFilter, Banzai::Filter::MermaidFilter, or Banzai::Filter::SuggestionFilter
- {
- tag: 'pre.code.highlight',
- preserveWhitespace: 'full',
- getAttrs: (el) => {
- const lang = el.getAttribute('lang');
- if (!lang || lang === '') return {};
-
- return { lang };
- },
- },
- // Matches HTML generated by Banzai::Filter::MathFilter,
- // after being transformed by app/assets/javascripts/behaviors/markdown/render_math.js
- {
- tag: 'span.katex-display',
- preserveWhitespace: 'full',
- contentElement: 'annotation[encoding="application/x-tex"]',
- attrs: { lang: 'math' },
- },
- // Matches HTML generated by Banzai::Filter::MermaidFilter,
- // after being transformed by app/assets/javascripts/behaviors/markdown/render_sandboxed_mermaid.js
- {
- tag: 'svg.mermaid',
- preserveWhitespace: 'full',
- contentElement: 'text.source',
- attrs: { lang: 'mermaid' },
- },
- // Matches HTML generated by Banzai::Filter::SuggestionFilter,
- // after being transformed by app/assets/javascripts/vue_shared/components/markdown/suggestions.vue
- {
- tag: '.md-suggestion',
- skip: true,
- },
- {
- tag: '.md-suggestion-header',
- ignore: true,
- },
- {
- tag: '.md-suggestion-diff',
- preserveWhitespace: 'full',
- getContent: (el, schema) =>
- [...el.querySelectorAll('.line_content.new span')].map((span) =>
- schema.text(span.innerText),
- ),
- attrs: { lang: 'suggestion' },
- },
- ],
- toDOM: (node) => ['pre', { class: 'code highlight', lang: node.attrs.lang }, ['code', 0]],
- },
-
- toMarkdown(state, node) {
- if (!node.childCount) return;
-
- const {
- textContent: text,
- attrs: { lang },
- } = node;
-
- // Prefixes lines with 4 spaces if the code contains a line that starts with triple backticks
- if (lang === PLAINTEXT_LANG && text.match(/^```/gm)) {
- state.wrapBlock(' ', null, node, () => state.text(text, false));
- return;
- }
-
- state.write('```');
- if (lang !== PLAINTEXT_LANG) state.write(lang);
-
- state.ensureNewLine();
- state.text(text, false);
- state.ensureNewLine();
-
- state.write('```');
- state.closeBlock(node);
- },
-});