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

Syntax highlighting #1242

Open
ekzyis opened this issue Jun 17, 2024 · 9 comments · May be fixed by #1606
Open

Syntax highlighting #1242

ekzyis opened this issue Jun 17, 2024 · 9 comments · May be fixed by #1606
Labels
difficulty:medium feature new product features that weren't there before

Comments

@ekzyis
Copy link
Member

ekzyis commented Jun 17, 2024

Is your feature request related to a problem? Please describe.

Code blocks don't use syntax highlighting. This makes code hard to read.

Describe the solution you'd like

If you use ```[language] instead of simply ``` to start a code block, it should highlight the syntax as the selected language like Github does. Here with python as an example:

def foo():
  bar = 1
  return bar

Describe alternatives you've considered

n/a

Additional context

We already use react-syntax-highlighter but we only use language='text':

<SyntaxHighlighter style={atomDark} language='text' PreTag='div' {...props}>
{children}
</SyntaxHighlighter>

However, it requires more than passing the language since if I manually set it to python, it does not do syntax highlighting.

@ekzyis ekzyis added the feature new product features that weren't there before label Jun 17, 2024
@huumn
Copy link
Member

huumn commented Jun 17, 2024

We used to do this. It made the bundle size HUGE for not much gain. It can probably be done efficiently with selective, dynamic imports.

A solution should use https://nextjs.org/docs/app/building-your-application/optimizing/bundle-analyzer to make sure it doesn't bloat the bundle.

@tsmith123
Copy link
Contributor

How about just importing the files for a few popular languages to tackle this one? If so, which languages would you want to support?

@huumn
Copy link
Member

huumn commented Jul 2, 2024

If they’re dynamically imported, it shouldn’t matter how many we support. But maybe we can find the top 5 somewhere

@tsmith123
Copy link
Contributor

I'm not sure how you'd decide when to "dynamically import" a language file. Selectively importing languages on build would keep the size down but you'd be limited those that you choose. If you mean importing them on the fly then that's a whole different ball game.

@huumn
Copy link
Member

huumn commented Jul 4, 2024

If you mean importing them on the fly then that's a whole different ball game.

That's the ball game I mean.

Unless we use dynamic imports, this isn't worth the bundle size bloat. Maybe we can dynamically import all languages. It's been a long time since I've looked at the code, but I think each language can be imported only when they're used.

@tsmith123
Copy link
Contributor

Well there is such a thing as dynamic imports but that isn't what you refer to as dynamic imports. You can choose which languages you want ahead of time but not during runtime.

@huumn
Copy link
Member

huumn commented Jul 5, 2024

@tsmith123
Copy link
Contributor

tsmith123 commented Jul 5, 2024

That's cool but once you've imported how do you decide when to drop it or does it just "exist" for the duration of the page view?

@huumn
Copy link
Member

huumn commented Jul 5, 2024

You don't decide to drop it. The browser caches it or doesn't. The main thing is that it's only downloaded if it's used.

@aegroto aegroto linked a pull request Nov 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:medium feature new product features that weren't there before
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants