2021-06-08 01:23:25 +05:30
|
|
|
import { CodeBlockLowlight } from '@tiptap/extension-code-block-lowlight';
|
2021-09-04 01:27:46 +05:30
|
|
|
import * as lowlight from 'lowlight';
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const extractLanguage = (element) => element.getAttribute('lang');
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
export default CodeBlockLowlight.extend({
|
2021-06-08 01:23:25 +05:30
|
|
|
addAttributes() {
|
2021-04-29 21:17:54 +05:30
|
|
|
return {
|
2021-09-04 01:27:46 +05:30
|
|
|
language: {
|
|
|
|
default: null,
|
|
|
|
parseHTML: (element) => {
|
|
|
|
return {
|
|
|
|
language: extractLanguage(element),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
class: {
|
|
|
|
default: 'code highlight js-syntax-highlight',
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
};
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return ['pre', HTMLAttributes, ['code', {}, 0]];
|
|
|
|
},
|
|
|
|
}).configure({
|
|
|
|
lowlight,
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|