Skip to content

Commit edd4175

Browse files
committed
fix(editor): Add syntax highlighting in code blocks
Fixes: #3618 Also only load core highlight JS package in EditorFactory.js (required for syntax highlighting in plaintext editing). This reduces the size ofr compiled editor.js by almost 1MB. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 6964ef4 commit edd4175

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/EditorFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import 'proxy-polyfill'
2626

2727
import { Editor } from '@tiptap/core'
2828
import { lowlight } from 'lowlight/lib/core.js'
29-
import hljs from 'highlight.js'
29+
import hljs from 'highlight.js/lib/core'
3030

3131
import { logger } from './helpers/logger.js'
3232
import { Mention, PlainText, RichText } from './extensions/index.js'

src/components/Editor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ export default {
803803
.text-editor__wrapper {
804804
@import './../../css/prosemirror';
805805
806-
&:not(.is-rich-editor) .ProseMirror {
806+
.ProseMirror {
807807
pre {
808808
background-color: var(--color-main-background);
809809

src/extensions/RichText.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import { Extension } from '@tiptap/core'
24+
import { lowlight } from 'lowlight'
2425

2526
/* eslint-disable import/no-named-as-default */
2627
import History from '@tiptap/extension-history'
@@ -86,7 +87,9 @@ export default Extension.create({
8687
Blockquote,
8788
CharacterCount,
8889
Code,
89-
CodeBlock,
90+
CodeBlock.configure({
91+
lowlight,
92+
}),
9093
BulletList,
9194
HorizontalRule,
9295
OrderedList,

src/nodes/CodeBlock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import TiptapCodeBlock from '@tiptap/extension-code-block'
1+
import TiptapCodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
22
import { defaultMarkdownSerializer } from '@tiptap/pm/markdown'
33

4-
const CodeBlock = TiptapCodeBlock.extend({
4+
const CodeBlock = TiptapCodeBlockLowlight.extend({
55

66
parseHTML() {
77
return [

0 commit comments

Comments
 (0)