stackernews / stacker.news

Internet communities that pay you Bitcoin
https://stacker.news
MIT License
403 stars 105 forks source link

Syntax highlighting #1242

Open ekzyis opened 1 week ago

ekzyis commented 1 week ago

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':

https://github.com/stackernews/stacker.news/blob/78520b787b928756c81700ab5b3ac16170ac9084/components/text.js#L134-L136

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

huumn commented 1 week ago

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.