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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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

@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?

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

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
5 participants