Roam-Research / issues

Roam Research - A note-taking tool for networked thought.
https://roamresearch.com/
303 stars 7 forks source link

Support Syntax Highlighting in code blocks #297

Open yangsu opened 4 years ago

yangsu commented 4 years ago

Describe the problem

Adding support for syntax highlighting in code blocks would be great.

Feature implementation

Ideally, it would work like GFM's syntax highlighting, which allows you configure the language using the following syntax

```[language] 
[code...]
```

Github uses Linguist.

Alternatively, you can use highlight.js, which auto detects the language in the code block. It's supported languages list is less extensive than Linguist's, but should be sufficient for most use cases.

Stvad commented 4 years ago

I think it's at least partially supported now with the css themes launch

panterarocks49 commented 4 years ago

Is there any language in particular you would like us to support? We use CodeMirror, so we could add any of these languages.

yangsu commented 4 years ago

This list is a good place to start.

https://insights.stackoverflow.com/survey/2019#most-popular-technologies

lukaskawerau commented 4 years ago

My vote is on R and Python, but I think all the languages in @yangsu's link are supported by CodeMirror, so if enabling them is a simple question of changing a line in a config - catch 'em all! :)

jrk commented 4 years ago

Please, just support all of them. It's a bizarre limitation to only allow Clojure, Javascript, and CSS. There's no obvious reason to leave any out.

agentydragon commented 4 years ago

For me Java, JavaScript, HTML, C++, Python, SQL (ZetaSQL flavor) would cover most that I need.

But I would also recommend just supporting everything CodeMirror allows. For such a long list I think it would also be a good idea to change the language picker widget to be a combobox (i.e., allowing selecting language from a list, with filtering by typing).

Also please add a plaintext without highlighting option.

Arwalk commented 4 years ago

Please, just support all of them. It's a bizarre limitation to only allow Clojure, Javascript, and CSS. There's no obvious reason to leave any out.

Seconding this. I'd really like to be able to highlight C, Pyton and Rust personally.

wulymammoth commented 4 years ago

There are a lot of Roam users that are programmers and supporting the list that @yangsu shared is a good start if it isn't too much trouble -- I definitely use languages lower on that StackOverflow list regularly and keep RR notes on them, like Elixir. An alternative, although less idea, but if easy, would just let us not specify a language and allow us to type plaintext such that we don't get weird syntax highlighting for unsupported langs

deric4 commented 4 years ago

YAML and JSON plz, or at least a raw text for blocks which aren't supported :)

vanb commented 4 years ago

A popular language that I’d like to call out specifically is Typescript. It’s high on the popular languages list provided by @yangsu but doesn’t seem appear on the code mirror list. I hope it doesn’t get left out for that reason.

This is another good resource based on GitHub activity. https://madnight.github.io/githut/#/pull_requests/2020/2

necopinus commented 4 years ago

Fourth vote for the list that @yangsu linked, though my personal top three are bash/sh, PowerShell, and Go or Python.

(Edit: Why did I write JavaScript for the last option?)

kimaldis commented 4 years ago

Lua, AppleScript, Swift are the more unusual ones I’d need, but like they say, dump the lot in. There’s always going to be outriders.

justin-chau commented 4 years ago

+1 on adding more languages. It would help with anyone who touches code to some capacity. For me, I would like to see Python, C, C++, C#, but I feel as though even more languages should be supported. Ideally, Roam would support all languages that Notion does. Thanks for looking into this!

jrk commented 4 years ago

A recent update finally got around to adding more than the ridiculously limited previous list of CSS, Javascript, and Clojure, but it's still severely limited. This is very frustrating. There is no reason for this limitation! Please, just support all of the languages in CodeMirror. This is what GitHub and most others do at this point.

Think of yourselves using someone else's tool: there's no way Clojure would be on any top-10 list, so you'd be totally out of luck trying with your own language of choice.

If you want to limit the options in the main language choice dropdown to keep it really short without any extra UI effort, fine — but at the very least we should be able to specify any supported language in the code block prefix.

joedevivo commented 3 years ago

If there is a concern about supporting all the languages in CodeMirror, a plaintext option would be great. No highlighting is better than incorrect highlighting.

Also, if you allowed any CodeMirror language in the code block prefix, like @jrk suggested, but didn't want to support that language yet, we'd be able to specify it, and benefit from that language's highlighting in the future when it is supported, defaulting to plaintext until then.

madlep commented 3 years ago

👍 to allowing plaintext if language isn't supported. I add a lot of Elixir and Erlang code blocks, so specifically those. JSON would be good too (can use javascript, but not exactly the same thing), as well as CSV.

LieseOnLife commented 3 years ago

If I could add a vote for Go, it would be super appreciated 😃

tisonkun commented 3 years ago

I'd appreciate it if the experience writing a code block is just like in Typora.