Skip to content

Commit 45a410f

Browse files
authored
Merge pull request #375 from hunghg255/update-codeblock
chore: update codeblock use rangi
2 parents 7efd64d + c3eff4c commit 45a410f

17 files changed

Lines changed: 1643 additions & 1370 deletions

File tree

docs/extensions/CodeBlock/index.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@ next:
88

99
# CodeBlock
1010

11-
- The `CodeBlock` extension allows you to add code blocks to your editor. It supports syntax highlighting and language selection, making it ideal for displaying code snippets in a visually appealing way. Reference [code-block-lowlight](https://tiptap.dev/docs/editor/extensions/nodes/code-block-lowlight) for more details.
1211
- The `RichTextCodeBlock` component provides a toolbar for the `CodeBlock` extension, allowing users to easily select the programming language for their code blocks.
13-
- The `CodeBlock` extension is built on top of the `code-block-lowlight` extension, which uses the `lowlight` library for syntax highlighting. You can customize the languages supported by registering them with `lowlight`.
1412
- The `RichTextBubbleCodeBlock` component provides a bubble menu for the `CodeBlock` extension, allowing users to easily delete code blocks.
1513

16-
## Installation
17-
18-
```bash
19-
npm install highlight.js lowlight
20-
```
21-
2214
## Usage
2315

2416
```tsx
@@ -40,26 +32,10 @@ import { RichTextBubbleCodeBlock } from 'reactjs-tiptap-editor/bubble';
4032
import { CodeBlock, RichTextCodeBlock } from 'reactjs-tiptap-editor/codeblock'; // [!code ++]
4133
// ... other extensions
4234

43-
// Lowlight, Highlight.js
44-
import { createLowlight } from 'lowlight';
45-
import css from 'highlight.js/lib/languages/css';
46-
import js from 'highlight.js/lib/languages/javascript';
47-
import ts from 'highlight.js/lib/languages/typescript';
48-
import html from 'highlight.js/lib/languages/xml';
4935

5036
// Import CSS
5137
import 'reactjs-tiptap-editor/style.css';
5238

53-
// Optional: Import lowlight languages
54-
// create a lowlight instance with all languages loaded
55-
56-
//This is only an example, all supported languages are already loaded above
57-
// but you can also register only specific languages to reduce bundle-size
58-
const lowlight = createLowlight();
59-
lowlight.register('html', html);
60-
lowlight.register('css', css);
61-
lowlight.register('js', js);
62-
lowlight.register('ts', ts);
6339

6440
const extensions = [
6541
// Base Extensions
@@ -79,11 +55,6 @@ const extensions = [
7955
...
8056
// Import Extensions Here
8157
CodeBlock// [!code ++]
82-
83-
// Config Lowlight
84-
// CodeBlock.configure({
85-
// lowlight: lowlight, // [!code ++]
86-
// }),
8758
];
8859

8960
const RichTextToolbar = () => {

package.json

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -736,95 +736,94 @@
736736
},
737737
"dependencies": {
738738
"@excalidraw/excalidraw": "^0.18.1",
739-
"@floating-ui/dom": "^1.7.6",
739+
"@floating-ui/dom": "^1.8.0",
740740
"@hocuspocus/provider": "^3.4.4",
741-
"@radix-ui/react-checkbox": "^1.3.7",
742-
"@radix-ui/react-dialog": "^1.1.19",
743-
"@radix-ui/react-dropdown-menu": "^2.1.20",
741+
"@radix-ui/react-checkbox": "^1.3.11",
742+
"@radix-ui/react-dialog": "^1.1.23",
743+
"@radix-ui/react-dropdown-menu": "^2.1.24",
744744
"@radix-ui/react-icons": "^1.3.2",
745-
"@radix-ui/react-label": "^2.1.11",
746-
"@radix-ui/react-popover": "^1.1.19",
747-
"@radix-ui/react-select": "^2.3.3",
748-
"@radix-ui/react-separator": "^1.1.11",
749-
"@radix-ui/react-slot": "^1.3.0",
750-
"@radix-ui/react-switch": "^1.3.3",
751-
"@radix-ui/react-tabs": "^1.1.17",
752-
"@radix-ui/react-toast": "^1.2.19",
753-
"@radix-ui/react-toggle": "^1.1.14",
754-
"@radix-ui/react-tooltip": "^1.2.12",
755-
"@tiptap/core": "^3.27.3",
756-
"@tiptap/extension-blockquote": "^3.27.3",
757-
"@tiptap/extension-bold": "^3.27.3",
758-
"@tiptap/extension-bullet-list": "^3.27.3",
759-
"@tiptap/extension-code": "^3.27.3",
760-
"@tiptap/extension-code-block-lowlight": "^3.27.3",
761-
"@tiptap/extension-collaboration": "^3.27.3",
762-
"@tiptap/extension-collaboration-caret": "^3.27.3",
763-
"@tiptap/extension-document": "^3.27.3",
764-
"@tiptap/extension-drag-handle": "^3.27.3",
765-
"@tiptap/extension-drag-handle-react": "^3.27.3",
766-
"@tiptap/extension-emoji": "^3.27.3",
767-
"@tiptap/extension-hard-break": "^3.27.3",
768-
"@tiptap/extension-heading": "^3.27.3",
769-
"@tiptap/extension-highlight": "^3.27.3",
770-
"@tiptap/extension-horizontal-rule": "^3.27.3",
771-
"@tiptap/extension-image": "^3.27.3",
772-
"@tiptap/extension-italic": "^3.27.3",
773-
"@tiptap/extension-link": "^3.27.3",
774-
"@tiptap/extension-list": "^3.27.3",
775-
"@tiptap/extension-list-item": "^3.27.3",
776-
"@tiptap/extension-mention": "^3.27.3",
777-
"@tiptap/extension-node-range": "^3.27.3",
778-
"@tiptap/extension-ordered-list": "^3.27.3",
779-
"@tiptap/extension-paragraph": "^3.27.3",
780-
"@tiptap/extension-strike": "^3.27.3",
781-
"@tiptap/extension-subscript": "^3.27.3",
782-
"@tiptap/extension-superscript": "^3.27.3",
783-
"@tiptap/extension-table": "^3.27.3",
784-
"@tiptap/extension-task-item": "^3.27.3",
785-
"@tiptap/extension-task-list": "^3.27.3",
786-
"@tiptap/extension-text": "^3.27.3",
787-
"@tiptap/extension-text-align": "^3.27.3",
788-
"@tiptap/extension-text-style": "^3.27.3",
789-
"@tiptap/extension-underline": "^3.27.3",
790-
"@tiptap/extensions": "^3.27.3",
791-
"@tiptap/pm": "^3.27.3",
792-
"@tiptap/react": "^3.27.3",
793-
"@tiptap/suggestion": "^3.27.3",
794-
"@tiptap/y-tiptap": "^3.0.6",
745+
"@radix-ui/react-label": "^2.1.15",
746+
"@radix-ui/react-popover": "^1.1.23",
747+
"@radix-ui/react-select": "^2.3.7",
748+
"@radix-ui/react-separator": "^1.1.15",
749+
"@radix-ui/react-slot": "^1.3.3",
750+
"@radix-ui/react-switch": "^1.3.7",
751+
"@radix-ui/react-tabs": "^1.1.21",
752+
"@radix-ui/react-toast": "^1.2.23",
753+
"@radix-ui/react-toggle": "^1.1.18",
754+
"@radix-ui/react-tooltip": "^1.2.16",
755+
"@tiptap/core": "^3.29.2",
756+
"@tiptap/extension-blockquote": "^3.29.2",
757+
"@tiptap/extension-bold": "^3.29.2",
758+
"@tiptap/extension-bullet-list": "^3.29.2",
759+
"@tiptap/extension-code": "^3.29.2",
760+
"@tiptap/extension-code-block": "^3.29.2",
761+
"@tiptap/extension-collaboration": "^3.29.2",
762+
"@tiptap/extension-collaboration-caret": "^3.29.2",
763+
"@tiptap/extension-document": "^3.29.2",
764+
"@tiptap/extension-drag-handle": "^3.29.2",
765+
"@tiptap/extension-drag-handle-react": "^3.29.2",
766+
"@tiptap/extension-emoji": "^3.29.2",
767+
"@tiptap/extension-hard-break": "^3.29.2",
768+
"@tiptap/extension-heading": "^3.29.2",
769+
"@tiptap/extension-highlight": "^3.29.2",
770+
"@tiptap/extension-horizontal-rule": "^3.29.2",
771+
"@tiptap/extension-image": "^3.29.2",
772+
"@tiptap/extension-italic": "^3.29.2",
773+
"@tiptap/extension-link": "^3.29.2",
774+
"@tiptap/extension-list": "^3.29.2",
775+
"@tiptap/extension-list-item": "^3.29.2",
776+
"@tiptap/extension-mention": "^3.29.2",
777+
"@tiptap/extension-node-range": "^3.29.2",
778+
"@tiptap/extension-ordered-list": "^3.29.2",
779+
"@tiptap/extension-paragraph": "^3.29.2",
780+
"@tiptap/extension-strike": "^3.29.2",
781+
"@tiptap/extension-subscript": "^3.29.2",
782+
"@tiptap/extension-superscript": "^3.29.2",
783+
"@tiptap/extension-table": "^3.29.2",
784+
"@tiptap/extension-task-item": "^3.29.2",
785+
"@tiptap/extension-task-list": "^3.29.2",
786+
"@tiptap/extension-text": "^3.29.2",
787+
"@tiptap/extension-text-align": "^3.29.2",
788+
"@tiptap/extension-text-style": "^3.29.2",
789+
"@tiptap/extension-underline": "^3.29.2",
790+
"@tiptap/extensions": "^3.29.2",
791+
"@tiptap/pm": "^3.29.2",
792+
"@tiptap/react": "^3.29.2",
793+
"@tiptap/suggestion": "^3.29.2",
794+
"@tiptap/y-tiptap": "^3.0.8",
795795
"class-variance-authority": "^0.7.1",
796796
"clsx": "^2.1.1",
797797
"deep-equal": "^2.2.3",
798798
"docx": "^9.7.1",
799799
"easydrawer": "^0.0.15",
800800
"frimousse": "^0.3.0",
801-
"highlight.js": "^11.11.1",
802801
"katex": "^0.16.47",
803802
"lodash-es": "^4.18.1",
804-
"lowlight": "^3.3.0",
805803
"lucide-react": "^0.427.0",
806804
"marked": "^15.0.12",
807-
"mermaid": "^11.16.0",
805+
"mermaid": "^11.16.1",
808806
"prosemirror-docx": "^0.2.1",
807+
"rangi": "^2.2.0",
809808
"re-resizable": "^6.11.2",
810-
"react-colorful": "^5.7.0",
809+
"react-colorful": "^5.8.0",
811810
"react-image-crop": "^11.1.2",
812811
"react-tweet": "^3.3.1",
813812
"reactjs-signal": "^2.0.6",
814813
"scroll-into-view-if-needed": "^3.1.0",
815814
"svg64": "^2.0.0",
816815
"y-protocols": "^1.0.7",
817-
"yjs": "^13.6.31"
816+
"yjs": "^13.6.32"
818817
},
819818
"devDependencies": {
820819
"@types/deep-equal": "^1.0.4",
821820
"@types/katex": "^0.16.8",
822821
"@types/lodash-es": "^4.17.12",
823822
"@types/node": "^24.13.3",
824-
"@types/react": "^19.2.17",
825-
"@types/react-dom": "^19.2.3",
823+
"@types/react": "^19.2.18",
824+
"@types/react-dom": "^19.2.4",
826825
"@vitejs/plugin-react": "^5.2.0",
827-
"autoprefixer": "^10.5.2",
826+
"autoprefixer": "^10.5.4",
828827
"bumpp": "^10.4.1",
829828
"contributorkit": "^0.0.4",
830829
"esno": "^4.8.0",
@@ -834,13 +833,13 @@
834833
"mammoth": "^1.12.0",
835834
"md5": "^2.3.0",
836835
"oxfmt": "^0.55.0",
837-
"oxlint": "^1.73.0",
838-
"postcss": "^8.5.16",
836+
"oxlint": "^1.77.0",
837+
"postcss": "^8.5.26",
839838
"postcss-replace": "^2.0.1",
840839
"postcss-scss": "^4.0.9",
841-
"react": "^19.2.7",
842-
"react-dom": "^19.2.7",
843-
"sass": "^1.101.0",
840+
"react": "^19.2.8",
841+
"react-dom": "^19.2.8",
842+
"sass": "^1.102.0",
844843
"tailwind-merge": "^2.6.1",
845844
"tailwindcss": "^3.4.19",
846845
"typescript": "^5.9.3",

playground/index.html

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>React Tiptap Editor</title>
8-
<link
9-
rel="stylesheet"
10-
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css"
11-
/>
12-
</head>
133

14-
<body>
15-
<div id="root"></div>
16-
<script type="module" src="./src/main.tsx"></script>
17-
</body>
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>React Tiptap Editor</title>
9+
</head>
10+
11+
<body>
12+
<div id="root"></div>
13+
<script type="module" src="./src/main.tsx"></script>
14+
</body>
15+
1816
</html>

playground/src/App.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ import { EditorContent, useEditor } from '@tiptap/react';
1616
// name: 'github.com/hunghg255',
1717
// document: ydoc,
1818
// })
19-
import css from 'highlight.js/lib/languages/css';
20-
import js from 'highlight.js/lib/languages/javascript';
21-
import ts from 'highlight.js/lib/languages/typescript';
22-
import html from 'highlight.js/lib/languages/xml';
23-
import { all, createLowlight } from 'lowlight';
2419
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2520
import { RichTextProvider } from 'reactjs-tiptap-editor';
2621
import { Attachment, RichTextAttachment } from 'reactjs-tiptap-editor/attachment';
@@ -108,15 +103,8 @@ import 'easydrawer/styles.css';
108103
import '@excalidraw/excalidraw/index.css';
109104
import 'katex/contrib/mhchem';
110105

111-
// create a lowlight instance with all languages loaded
112-
const lowlight = createLowlight();
113-
114106
// This is only an example, all supported languages are already loaded above
115107
// but you can also register only specific languages to reduce bundle-size
116-
lowlight.register('html', html);
117-
lowlight.register('css', css);
118-
lowlight.register('js', js);
119-
lowlight.register('ts', ts);
120108

121109
function getRandomColor() {
122110
const letters = '0123456789ABCDEF';
@@ -259,9 +247,7 @@ const extensions = [
259247
Blockquote,
260248
HorizontalRule,
261249
Code,
262-
CodeBlock.configure({
263-
lowlight,
264-
}),
250+
CodeBlock,
265251

266252
Column,
267253
ColumnNode,
@@ -359,7 +345,8 @@ const extensions = [
359345
// }),
360346
];
361347

362-
const DEFAULT = `<pre dir="auto"><code class="language-js">const a = 2;</code></pre><p dir="auto"></p>`;
348+
const DEFAULT = `<pre class="shj" dir="auto"><code class="language-js">const a = 2;\
349+
</code></pre><p dir="auto"></p>`;
363350

364351
function debounce(func: any, wait: number) {
365352
let timeout: NodeJS.Timeout;

0 commit comments

Comments
 (0)