Skip to content

Commit

Permalink
fix(extension-code-block-lowlight): use lowlight v3 and update demos (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 authored Aug 6, 2024
1 parent 4b215f7 commit d6e56c4
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .changeset/bright-mayflies-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tiptap-demos": patch
"@tiptap/extension-code-block-lowlight": patch
---

declare lowlight to be a peer dep of extension-code-block-lowlight, update usage to v3
2 changes: 1 addition & 1 deletion demos/includeDependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ highlight.js/lib/languages/xml
highlight.js/lib/core
linkifyjs
lowlight
lowlight/lib/core
prosemirror-commands
prosemirror-dropcursor
prosemirror-gapcursor
Expand All @@ -21,6 +20,7 @@ prosemirror-view
react
react-dom
react-dom/client
use-sync-external-store/shim/with-selector
shiki
simplify-js
tippy.js
Expand Down
4 changes: 2 additions & 2 deletions demos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"@lexical/react": "^0.11.1",
"d3": "^7.3.0",
"fast-glob": "^3.2.11",
"highlight.js": "^11.6.0",
"highlight.js": "^11.10.0",
"lexical": "^0.11.1",
"lowlight": "^2.7.0",
"lowlight": "^3.1.0",
"remixicon": "^2.5.0",
"shiki": "^1.10.3",
"simplify-js": "^1.2.4",
Expand Down
25 changes: 13 additions & 12 deletions demos/src/Examples/CodeBlockLanguage/React/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// load specific languages only
// import { lowlight } from 'lowlight/lib/core'
// import javascript from 'highlight.js/lib/languages/javascript'
// lowlight.registerLanguage('javascript', javascript)
import './styles.scss'

import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
Expand All @@ -13,16 +9,21 @@ import css from 'highlight.js/lib/languages/css'
import js from 'highlight.js/lib/languages/javascript'
import ts from 'highlight.js/lib/languages/typescript'
import html from 'highlight.js/lib/languages/xml'
// load all highlight.js languages
import { lowlight } from 'lowlight'
// load all languages with "all" or common languages with "common"
import { all, createLowlight } from 'lowlight'
import React from 'react'

import CodeBlockComponent from './CodeBlockComponent.jsx'
// eslint-disable-next-line
import CodeBlockComponent from './CodeBlockComponent'

lowlight.registerLanguage('html', html)
lowlight.registerLanguage('css', css)
lowlight.registerLanguage('js', js)
lowlight.registerLanguage('ts', ts)
// create a lowlight instance
const lowlight = createLowlight(all)

// you can also register individual languages
lowlight.register('html', html)
lowlight.register('css', css)
lowlight.register('js', js)
lowlight.register('ts', ts)

const MenuBar = ({ editor }) => {
if (!editor) {
Expand Down Expand Up @@ -56,7 +57,7 @@ export default () => {
],
content: `
<p>
Thats a boring paragraph followed by a fenced code block:
That's a boring paragraph followed by a fenced code block:
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
Expand Down
21 changes: 10 additions & 11 deletions demos/src/Examples/CodeBlockLanguage/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ import css from 'highlight.js/lib/languages/css'
import js from 'highlight.js/lib/languages/javascript'
import ts from 'highlight.js/lib/languages/typescript'
import html from 'highlight.js/lib/languages/xml'
// load all highlight.js languages
import { lowlight } from 'lowlight'
// load all languages with "all" or common languages with "common"
import { all, createLowlight } from 'lowlight'
import CodeBlockComponent from './CodeBlockComponent.vue'
lowlight.registerLanguage('html', html)
lowlight.registerLanguage('css', css)
lowlight.registerLanguage('js', js)
lowlight.registerLanguage('ts', ts)
// create a lowlight instance
const lowlight = createLowlight(all)
// load specific languages only
// import { lowlight } from 'lowlight/lib/core'
// import javascript from 'highlight.js/lib/languages/javascript'
// lowlight.registerLanguage('javascript', javascript)
// you can also register languages
lowlight.register('html', html)
lowlight.register('css', css)
lowlight.register('js', js)
lowlight.register('ts', ts)
export default {
components: {
Expand Down Expand Up @@ -63,7 +62,7 @@ export default {
],
content: `
<p>
Thats a boring paragraph followed by a fenced code block:
That's a boring paragraph followed by a fenced code block:
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
Expand Down
16 changes: 9 additions & 7 deletions demos/src/Experiments/All/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ import TextAlign from '@tiptap/extension-text-align'
import TextStyle from '@tiptap/extension-text-style'
import Underline from '@tiptap/extension-underline'
import { Editor, EditorContent } from '@tiptap/vue-3'
import { lowlight } from 'lowlight'
import { all, createLowlight } from 'lowlight'
const lowlight = createLowlight(all)
export default {
components: {
Expand Down Expand Up @@ -182,14 +184,14 @@ export default {
</p>
<ul>
<li>
Thats a bullet list with one …
That's a bullet list with one …
</li>
<li>
… or two list items.
</li>
</ul>
<p>
Isnt that great? And all of that is editable. But wait, theres more. Lets try a code block:
Isn't that great? And all of that is editable. But wait, there's more. Let's try a code block:
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
Expand All @@ -203,20 +205,20 @@ export default {
console.log(i);
}</code></pre>
<p>
I know, I know, this is impressive. Its only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.
I know, I know, this is impressive. It's only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.
</p>
<blockquote>
Wow, thats amazing. Good work, boy! 👏
Wow, that's amazing. Good work, boy! 👏
<br />
— Mom
</blockquote>
<h2>Text align</h2>
<p style="text-align: center">first paragraph</p>
<p style="text-align: right">second paragraph</p>
<h2>Color</h2>
<p><span style="color: #958DF1">Oh, for some reason thats purple.</span></p>
<p><span style="color: #958DF1">Oh, for some reason that's purple.</span></p>
<h2>Highlight</h2>
<p>This isnt highlighted.</s></p>
<p>This isn't highlighted.</s></p>
<p><mark>But that one is.</mark></p>
<p><mark style="background-color: red;">And this is highlighted too, but in a different color.</mark></p>
<p><mark data-color="#ffa8a8">And this one has a data attribute.</mark></p>
Expand Down
33 changes: 22 additions & 11 deletions demos/src/Nodes/CodeBlockLowlight/React/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// load specific languages only
// import { lowlight } from 'lowlight/lib/core'
// import javascript from 'highlight.js/lib/languages/javascript'
// lowlight.registerLanguage('javascript', javascript)
import './styles.scss'

import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
Expand All @@ -13,14 +9,29 @@ import css from 'highlight.js/lib/languages/css'
import js from 'highlight.js/lib/languages/javascript'
import ts from 'highlight.js/lib/languages/typescript'
import html from 'highlight.js/lib/languages/xml'
// load all highlight.js languages
import { lowlight } from 'lowlight'
// load all languages with "all" or common languages with "common"
import { all, createLowlight } from 'lowlight'
import React from 'react'

lowlight.registerLanguage('html', html)
lowlight.registerLanguage('css', css)
lowlight.registerLanguage('js', js)
lowlight.registerLanguage('ts', ts)
// create a lowlight instance with all languages loaded
const lowlight = createLowlight(all)

// This is only an example, all supported languages are already loaded above
// but you can also register only specific languages to reduce bundle-size
lowlight.register('html', html)
lowlight.register('css', css)
lowlight.register('js', js)
lowlight.register('ts', ts)

/**
* Lowlight version 2.x had a different API
* import { lowlight } from 'lowlight'
*
* lowlight.registerLanguage('html', html)
* lowlight.registerLanguage('css', css)
* lowlight.registerLanguage('js', js)
* lowlight.registerLanguage('ts', ts)
*/

export default () => {
const editor = useEditor({
Expand All @@ -34,7 +45,7 @@ export default () => {
],
content: `
<p>
Thats a boring paragraph followed by a fenced code block:
That's a boring paragraph followed by a fenced code block:
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
Expand Down
18 changes: 11 additions & 7 deletions demos/src/Nodes/CodeBlockLowlight/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import css from 'highlight.js/lib/languages/css'
import js from 'highlight.js/lib/languages/javascript'
import ts from 'highlight.js/lib/languages/typescript'
import html from 'highlight.js/lib/languages/xml'
// load all highlight.js languages
import { lowlight } from 'lowlight'
// load all languages with "all" or common languages with "common"
import { all, createLowlight } from 'lowlight'
lowlight.registerLanguage('html', html)
lowlight.registerLanguage('css', css)
lowlight.registerLanguage('js', js)
lowlight.registerLanguage('ts', ts)
// create a lowlight instance
const lowlight = createLowlight(all)
// you can also register languages
lowlight.register('html', html)
lowlight.register('css', css)
lowlight.register('js', js)
lowlight.register('ts', ts)
export default {
components: {
Expand All @@ -56,7 +60,7 @@ export default {
],
content: `
<p>
Thats a boring paragraph followed by a fenced code block:
That's a boring paragraph followed by a fenced code block:
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
Expand Down
Loading

0 comments on commit d6e56c4

Please sign in to comment.