-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Disable syntax highlighting by default, or on stuff that doesn't look like code #508
Comments
Here is valid code that doesn't have curly or angle brackets: print "hello world"
function hi(x)
print("hi " .. x)
end main :: IO ()
main = putStrLn "Hello world!" |
Suggestinons for better heuristics more than welcome - I just don't want
to lose the autohighlighting entirely, as it's been useful more times than
otherwise so far. Perhaps highlight.js itself can be tuned.
|
does it support things like github flavored markdown language tagging?
main :: IO ()
main = putStrLn "Hello World!" |
GFM-style languge tagging for preformatted blocks can be done with something like the following (I have this working for my webpage): marked.setOptions({
highlight: function (code, lang) {
return (lang === undefined) ? code : H.highlight(lang, code).value;
},
}); Note that the above will disable highlighting for untagged preformatted code blocks, so it might be desirable to apply some heuristic anyway when Should I send a PR for |
sure - PR would be very welcome. The highlighting is currently done by highlight.js as a non-reactish DOM pass once the page has rendered. It's completely decoupled from marked currently. If there's a nice way to do make marked do the highlighting (whilst retaining highlight.js's heuristics if no language is marked) that'd be awesome. https://github.com/matrix-org/matrix-react-sdk/blob/master/src/components/views/messages/TextualBody.js#L72 is the current super-stupid code. |
just realised that making marked do this would shift responsibility to the client sending the message rather than displaying it, which is a bit of a pain in the ass. To fix this properly we'd need to finally get the "human representation of message" stuff landed in the spec to allow native markdown to be included in events, so the receiving client can then render the markdown as it liked. I suspect a better bet would be to instead make the existing highlight.js code 'do the right thing' for syntax highlighting. |
@ara4n: Yeah, I noticed also the shift in responsibility when tying this to |
The highlight.js autodetection is finicky and often wrong, so disable highlighting unless the language was explicitly specified. Fixes element-hq/element-web#508. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
The highlight.js autodetection is finicky and often wrong, so disable highlighting unless the language was explicitly specified. Fixes element-hq/element-web#508. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
The highlight.js autodetection is finicky and often wrong, so disable highlighting unless the language was explicitly specified, or if the user has explicitly enabled it in the settings. Fixes element-hq/element-web#508. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
A crappy heuristic like "needs a curly or right-angled bracket" might be sufficient for now.
The text was updated successfully, but these errors were encountered: