Commit 91244b0f authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch 'remove-content-editor-code-blocks-from-copy-to-code' into 'master'

Fix infinite loop in Content Editor codeblocks

See merge request gitlab-org/gitlab!77965
parents 72b27b3f 2fe3c884
......@@ -29,7 +29,7 @@ class CopyCodeButton extends HTMLElement {
}
function addCodeButton() {
[...document.querySelectorAll('pre.code.js-syntax-highlight')]
[...document.querySelectorAll('pre.code.js-syntax-highlight:not(.content-editor-code-block)')]
.filter((el) => el.attr('lang') !== 'mermaid')
.filter((el) => !el.closest('.js-markdown-code'))
.forEach((el) => {
......
......@@ -20,7 +20,7 @@ export default {
};
</script>
<template>
<node-view-wrapper class="gl-relative code highlight" as="pre">
<node-view-wrapper class="content-editor-code-block gl-relative code highlight" as="pre">
<span
data-testid="frontmatter-label"
class="gl-absolute gl-top-0 gl-right-3"
......
......@@ -19,7 +19,14 @@ export default CodeBlockLowlight.extend({
};
},
renderHTML({ HTMLAttributes }) {
return ['div', ['pre', HTMLAttributes, ['code', {}, 0]]];
return [
'pre',
{
...HTMLAttributes,
class: `content-editor-code-block ${HTMLAttributes.class}`,
},
['code', {}, 0],
];
},
}).configure({
lowlight,
......
......@@ -26,6 +26,11 @@ describe('content/components/wrappers/frontmatter', () => {
expect(wrapper.findComponent(NodeViewWrapper).classes()).toContain('gl-relative');
});
it('adds content-editor-code-block class to the pre element', () => {
createWrapper();
expect(wrapper.findComponent(NodeViewWrapper).classes()).toContain('content-editor-code-block');
});
it('renders a node-view-content as a code element', () => {
createWrapper();
......
......@@ -36,4 +36,10 @@ describe('content_editor/extensions/code_block_highlight', () => {
expect(editorHtmlOutput.classList.toString()).toContain('code highlight js-syntax-highlight');
});
it('adds content-editor-code-block class to the pre element', () => {
const editorHtmlOutput = parseHTML(tiptapEditor.getHTML()).querySelector('pre');
expect(editorHtmlOutput.classList.toString()).toContain('content-editor-code-block');
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment