Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NcRichText): highlight code syntax if language provided #6212

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

Antreesy
Copy link
Contributor

@Antreesy Antreesy commented Nov 12, 2024

☑️ Resolves

Supported languages: https://github.com/wooorm/lowlight/blob/main/lib/common.js

🖼️ Screenshots

🏚️ Before 🏡 After
image image
image image
image image

🚧 Tasks

  • Introduce new prop?
    • We don't support language syntax before, so use-extended-markdown without providing lang prefix would work as before
  • Color themes?
    • I haven't found a better way to do it (see PR). Suggestions are welcome

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 3️⃣ Backport to next requested with a Vue 3 upgrade

@Antreesy Antreesy added enhancement New feature or request 3. to review Waiting for reviews feature: richtext Related to the richtext component labels Nov 12, 2024
@Antreesy Antreesy added this to the 8.21.0 milestone Nov 12, 2024
@Antreesy Antreesy self-assigned this Nov 12, 2024
@Antreesy
Copy link
Contributor Author

cc @juliusknorr for possible affect on Office apps

@Antreesy Antreesy force-pushed the feat/13687/syntax-highlight branch from dafd9a9 to 4d2c704 Compare November 13, 2024 16:19
@juliusknorr
Copy link
Contributor

cc @juliusknorr for possible affect on Office apps

Nice one, all good from my side. Only relevant usage is comment rendering in deck, where this works as expected 👍

@Antreesy Antreesy requested a review from susnux November 14, 2024 13:11
Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

But for NcRichText it costs about 6.6 kB css + 191 kB js (297 -> 488 kb) in production minified build.

@ShGKme
Copy link
Contributor

ShGKme commented Nov 14, 2024

We can load it async on the first code block render, but I don't know if it worth it.

@susnux What do you think?

@susnux
Copy link
Contributor

susnux commented Nov 14, 2024

We can load it async on the first code block render, but I don't know if it worth it.

Yes I think it makes sense, sadly that plugin forces to bundle languages.
For text we load the languages dynamically which reduces the size a lot.

@ShGKme
Copy link
Contributor

ShGKme commented Nov 14, 2024

We can load it async on the first code block render, but I don't know if it worth it.

Yes I think it makes sense, sadly that plugin forces to bundle languages. For text we load the languages dynamically which reduces the size a lot.

Proposal:

  1. Add module-scope reactive property aka highlightAvailable
  2. Use rehypeHighlight if highlightAvailable === true
  3. Add a function to load rehypeHighlight with dynamic import()
  4. Inside rehype2react check for code block and init loading rehypeHighlight from p.3

In theory when it is loaded p.1 changes and triggers rerender in p.2.

@Antreesy
Copy link
Contributor Author

Antreesy commented Nov 15, 2024

Added, see screenshot from styleguide network tab.

image

Did a quick test, remark-gfm is 40kB and could be extracted as well. Shall we do it?

@Antreesy Antreesy force-pushed the feat/13687/syntax-highlight branch from 228e30f to 99b5395 Compare November 15, 2024 15:21
Copy link
Contributor

@DorraJaouad DorraJaouad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, looks good

@Antreesy Antreesy force-pushed the feat/13687/syntax-highlight branch from 99b5395 to c523550 Compare November 19, 2024 11:20
src/components/NcRichText/NcRichText.vue Outdated Show resolved Hide resolved
@Antreesy
Copy link
Contributor Author

Antreesy commented Nov 20, 2024

Squashed and added a unit test, rewrote Promise syntax to async/await - no other changes
Tested with Talk

@Antreesy Antreesy merged commit 52ccc29 into master Nov 20, 2024
19 checks passed
@Antreesy Antreesy deleted the feat/13687/syntax-highlight branch November 20, 2024 08:16
@Antreesy
Copy link
Contributor Author

/backport to next

@jclsn
Copy link

jclsn commented Nov 20, 2024

How would I test this?

@ShGKme
Copy link
Contributor

ShGKme commented Nov 20, 2024

@jclsn
Copy link

jclsn commented Nov 20, 2024

Thanks, I'll just wait until it's shipped then.

@ShGKme
Copy link
Contributor

ShGKme commented Nov 20, 2024

Thanks, I'll just wait until it's shipped then.

If you want to test it in a specific app, you can also link it with npm link

@jclsn
Copy link

jclsn commented Nov 20, 2024

I am using the docker installation of Nextcloud. It is probably a bit more of a hassle. If it ships with the next update, it's fine.

@Antreesy Antreesy mentioned this pull request Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request feature: richtext Related to the richtext component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax Highlighting for Code-Boxes
6 participants