tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

Support lowlight v2 in code block extension

Open tn opened this issue 2 years ago • 8 comments

What’s the bug you are facing?

Looks like lowlight changed module exports and extension-code-block-lowlight can't find listLanguages function

How can we reproduce the bug on our side?

Just install lowlight at least v2.4.0 Use official example

Can you provide a CodeSandbox?

https://codesandbox.io/s/elastic-goldwasser-7pkjp?file=/src/CodeBlockComponent.tsx

What did you expect to happen?

It should work

Anything to add? (optional)

No response

Did you update your dependencies?

  • [X] Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • [ ] Yes, I’m a sponsor. 💖

tn avatar Nov 01 '21 22:11 tn

This is how you have to import lowlight v2.x:

import { lowlight } from "lowlight";

Here is the updated codesandbox: https://codesandbox.io/s/trusting-lake-22hls

cadars avatar Nov 02 '21 15:11 cadars

@cadars Any thoughts on why does the sandbox show Module '"lowlight"' has no exported member 'lowlight'.

aquibbaig avatar Nov 23 '21 16:11 aquibbaig

Not really, but it looks like the error (hint?) disappears when importing this way instead:

import { lowlight } from "lowlight/lib/all.js";

Personally I only import the most common languages:

import { lowlight } from "lowlight/lib/common.js";

cadars avatar Nov 23 '21 17:11 cadars

I think the solution to this problem is to register languages by installing highlight.js first.

aquibbaig avatar Nov 23 '21 17:11 aquibbaig

@cadars I think that solves it, thanks!

aquibbaig avatar Nov 23 '21 17:11 aquibbaig

i just ran into a similar problem. lowlight languages didn't show up in my "electron" build. (without any error messages and it did work in the test environment)

so i used @cadars way to import lowlight import { lowlight } from "lowlight/lib/common.js"; and it worked. thx!

valueerrorx avatar Mar 10 '22 11:03 valueerrorx

Looking into the usage, there doesn't seem to be any compelling reason not to upgrade. This is an inconvenience for users to be sure in both extra code to override the lowlight version and in bundling to assert that only one version is packaged. For a light lift like this, could the maintainers comment on what is holding this upgrade up?

shellscape avatar Mar 22 '22 18:03 shellscape

@cadars Any thoughts on why does the sandbox show Module '"lowlight"' has no exported member 'lowlight'.

It's because its using an outdated type-declaration from @types/lowlight instead of from lowlight itself (lowlight declares its own types).

Currently @types/lowlight is required by @tiptap/extension-code-block-lowlight package, and definitely needs to be removed from the extension's dependency, else it can't be uninstalled.

EvitanRelta avatar Jun 14 '22 05:06 EvitanRelta

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Oct 31 '22 00:10 github-actions[bot]