@rtdui/editor
Version:
React rich text editor based on tiptap
52 lines (49 loc) • 1.48 kB
JavaScript
'use client';
import { CodeBlock } from '@tiptap/extension-code-block';
import { ProseMirrorShikiPlugin } from './prosemirror-shiki-plugin.mjs';
const CodeBlockShiki = CodeBlock.extend({
addOptions() {
return {
...this.parent?.(),
defaultLanguage: null,
defaultTheme: "one-dark-pro",
HTMLAttributes: {
class: "shiki",
style: "background-color:#282c34;color:#abb2bf;"
}
};
},
addAttributes() {
return {
language: {
default: this.options.defaultLanguage,
parseHTML: (element) => {
const { languageClassPrefix } = this.options;
const classNames = [
...element.firstElementChild?.classList || []
];
const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
const language = languages[0];
return language ?? this.options.defaultLanguage;
},
renderHTML: (attributes) => {
return {
"data-language": attributes.language
};
}
}
};
},
addProseMirrorPlugins() {
return [
...this.parent?.() || [],
ProseMirrorShikiPlugin({
name: this.name,
defaultLanguage: this.options.defaultLanguage,
defaultTheme: this.options.defaultTheme
})
];
}
});
export { CodeBlockShiki };
//# sourceMappingURL=code-block-shiki.mjs.map