debian-mirror-gitlab/app/assets/javascripts/content_editor/extensions/code_block_highlight.js
2021-10-27 15:23:28 +05:30

27 lines
647 B
JavaScript

import { CodeBlockLowlight } from '@tiptap/extension-code-block-lowlight';
import * as lowlight from 'lowlight';
const extractLanguage = (element) => element.getAttribute('lang');
export default CodeBlockLowlight.extend({
addAttributes() {
return {
language: {
default: null,
parseHTML: (element) => {
return {
language: extractLanguage(element),
};
},
},
class: {
default: 'code highlight js-syntax-highlight',
},
};
},
renderHTML({ HTMLAttributes }) {
return ['pre', HTMLAttributes, ['code', {}, 0]];
},
}).configure({
lowlight,
});