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 <jonas@freesources.org>
  • Loading branch information
mejo- committed Jul 28, 2023
1 parent a573d74 commit 85399cc
Show file tree
Hide file tree
Showing 4 changed files with 9 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
6 changes: 5 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 @@ -59,6 +60,7 @@ import TrailingNode from './../nodes/TrailingNode.js'
import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
import { translate as t } from '@nextcloud/l10n'


Check failure on line 63 in src/extensions/RichText.js

View workflow job for this annotation

GitHub Actions / eslint

More than 1 blank line not allowed
export default Extension.create({
name: 'RichText',

Expand Down Expand Up @@ -86,7 +88,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 85399cc

Please sign in to comment.