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

Auto detect language in codeblocks #1516

Closed
TheHamkerCat opened this issue May 18, 2023 · 6 comments
Closed

Auto detect language in codeblocks #1516

TheHamkerCat opened this issue May 18, 2023 · 6 comments
Labels
feature request Request a feature or introduce and update to the project.
Milestone

Comments

@TheHamkerCat
Copy link
Contributor

Describe what feature you'd like. Pseudo-code, mockups, or screenshots of similar solutions are encouraged!

Can we have a feature to use hljs.highlightAuto() of highlight.js with <CodeBlock/> to auto-detect language?

Something like this

This would be really helpful when we're unsure about the language, especially when working with LLMs.

Currently we use this syntax:

<CodeBlock language="ts" code={`const skeleton: string = 'awesome';`}></CodeBlock>

How about?

<CodeBlock autodetect={true} code={`const skeleton: string = 'awesome';`}></CodeBlock>

I know this will dramatically increase bundle size, but maybe we can explicitly specify a list of languages we want support for when initializing.

What type of pull request would this be?

Enhancement

Any links to similar examples or other references we should review?

https://github.com/highlightjs/highlight.js#using-with-vuejs
https://github.com/highlightjs/highlight.js#nodejs-on-the-server

@TheHamkerCat TheHamkerCat added the feature request Request a feature or introduce and update to the project. label May 18, 2023
@TheHamkerCat
Copy link
Contributor Author

TheHamkerCat commented May 18, 2023

displayCode = $storeHighlightJs.highlight(code, { language }).value.trim();

Replacing highlight() with highlightAuto() and removing the language parameter works here temporarily (language displayed on ui will be incorrect though), i'll use this until that feature is added

@endigo9740
Copy link
Contributor

endigo9740 commented May 18, 2023

This is a bit at odds with: #1381

But FYI we're in the process of some major structural changes to the Skeleton project - which includes migrating to a monorepo. When this is complete, the code blocks are one of a handful of features we're looking to spin off as standalone packages. When this occurs we'll revisit a lot of the feature set and capabilities provided.

This could include potentially switching to something like Prism.js in favor of Highlight.js. So just FYI there are some prerequisites before we move forward with improvements to the existing code blocks.

If you need a short term fix, consider cloning the component to your local project, and modifying the functionality locally. It won't receive upstream updates obviously, but it'll operate as you see fit. You can find the source here:
https://github.com/skeletonlabs/skeleton/tree/dev/src/lib/utilities/CodeBlock

@TheHamkerCat
Copy link
Contributor Author

If you need a short term fix, consider cloning the component to your local project

Thanks, i'll do this!

You can find the source here: https://github.com/skeletonlabs/skeleton/tree/dev/src/lib/utilities/CodeBlock

Did you mean https://github.com/skeletonlabs/skeleton/tree/dev/packages/skeleton/src/lib/utilities/CodeBlock

@endigo9740
Copy link
Contributor

@TheHamkerCat we literally just pushed the monorepo change so that path just updated accordingly. But yes that's the new corrected path, thanks!

@endigo9740 endigo9740 added this to the v3.0 milestone Jun 2, 2023
@endigo9740
Copy link
Contributor

Note that this will be considered as part of the transition to the Code Block becoming a standalone package.

@endigo9740
Copy link
Contributor

endigo9740 commented Jan 3, 2024

In an effort to prepare for Skeleton v3, we're consolidate some related issues down to a single ticket. This will ensure that we can see the full context of requests when the time comes to refactor and update this feature going forward. If you wish to add additional feedback or suggestions, please so here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request a feature or introduce and update to the project.
Projects
None yet
Development

No branches or pull requests

2 participants