Skip to content

Commit

Permalink
fix(editor): Add syntax highlighting in code blocks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mejo- committed Jul 28, 2023
1 parent 6964ef4 commit edd4175
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/EditorFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'proxy-polyfill'

import { Editor } from '@tiptap/core'
import { lowlight } from 'lowlight/lib/core.js'
import hljs from 'highlight.js'
import hljs from 'highlight.js/lib/core'

import { logger } from './helpers/logger.js'
import { Mention, PlainText, RichText } from './extensions/index.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ export default {
.text-editor__wrapper {
@import './../../css/prosemirror';
&:not(.is-rich-editor) .ProseMirror {
.ProseMirror {
pre {
background-color: var(--color-main-background);
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import { Extension } from '@tiptap/core'
import { lowlight } from 'lowlight'

/* eslint-disable import/no-named-as-default */
import History from '@tiptap/extension-history'
Expand Down Expand Up @@ -86,7 +87,9 @@ export default Extension.create({
Blockquote,
CharacterCount,
Code,
CodeBlock,
CodeBlock.configure({
lowlight,
}),
BulletList,
HorizontalRule,
OrderedList,
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TiptapCodeBlock from '@tiptap/extension-code-block'
import TiptapCodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
import { defaultMarkdownSerializer } from '@tiptap/pm/markdown'

const CodeBlock = TiptapCodeBlock.extend({
const CodeBlock = TiptapCodeBlockLowlight.extend({

parseHTML() {
return [
Expand Down

0 comments on commit edd4175

Please sign in to comment.