gitlab-org--gitlab-foss/app/assets/javascripts/content_editor/extensions/code_block_highlight.js

27 lines
654 B
JavaScript
Raw Normal View History

import { CodeBlockLowlight } from '@tiptap/extension-code-block-lowlight';
import * as lowlight from 'lowlight';
const extractLanguage = (element) => element.getAttribute('lang');
export default CodeBlockLowlight.extend({
isolating: true,
addAttributes() {
return {
language: {
default: null,
parseHTML: (element) => extractLanguage(element),
},
class: {
// eslint-disable-next-line @gitlab/require-i18n-strings
default: 'code highlight',
},
};
},
renderHTML({ HTMLAttributes }) {
return ['div', ['pre', HTMLAttributes, ['code', {}, 0]]];
},
}).configure({
lowlight,
});