Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Only syntax highlight if language was specified #1074

Merged
merged 2 commits into from
Jun 26, 2017

Conversation

kyrias
Copy link
Contributor

@kyrias kyrias commented Jun 12, 2017

Currently we always try to syntax highlight anything within backticks, which leads to things like fooa_bar being highlighted as autohotkey automatically by highlight.js. There isn't really any good way to autodetect the language for things like that, so instead this PR changes the behavior to only try to syntax highlight if a language was passed when sending a full-fledged fenced codeblock:

```python
import foo
foo.bar
```

This fixes element-hq/element-web#508.

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@kyrias
Copy link
Contributor Author

kyrias commented Jun 12, 2017

Currently foo blocks will not render properly with the dark theme though, because the text color ends up the same color as the background.

@kyrias
Copy link
Contributor Author

kyrias commented Jun 14, 2017

(@ara4n ping? <3)

@ara4n
Copy link
Member

ara4n commented Jun 26, 2017

sorry for totally missing this - it looks good. Only feedback would be:
a) Can we provide an option to auto-highlight by default for folks who liked the original behaviour (I think this should be trivial via SyncedSettings)?
b) might be worth commenting the two filter() lines just to make it quicker to see what's going on: ("// Filter out all classes other than language-" and "// only run highlight.js on code blocks with explicit language classes" or something)

@kyrias
Copy link
Contributor Author

kyrias commented Jun 26, 2017

Hmm, I'll look into how SyncedSettings works, and how to add a Riot toggle setting then.

@ara4n
Copy link
Member

ara4n commented Jun 26, 2017

it should be two lines - one to add the definition to UserSettings and one to check it in TextualBody.

@kyrias kyrias force-pushed the only-highlight-specified-language branch from 44e2d02 to 0fce921 Compare June 26, 2017 15:42
kyrias added 2 commits June 26, 2017 17:45
This is required to be able to specify the highlight language in fenced
blocks like the following:

    ```python
    print("foo")
    ```

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>
@kyrias kyrias force-pushed the only-highlight-specified-language branch from 0fce921 to 48c3217 Compare June 26, 2017 15:45
@kyrias
Copy link
Contributor Author

kyrias commented Jun 26, 2017

@ara4n Fixed

@ara4n
Copy link
Member

ara4n commented Jun 26, 2017

lgtm - thanks :)

@ara4n ara4n merged commit 447f93b into matrix-org:develop Jun 26, 2017
@kyrias kyrias deleted the only-highlight-specified-language branch June 26, 2017 17:45
@turt2live
Copy link
Member

:(
This made code blocks on the dark theme illegible.
image

@kyrias
Copy link
Contributor Author

kyrias commented Jun 27, 2017

cough #1074 (comment) /cough

@kegsay
Copy link
Member

kegsay commented Jun 30, 2017

The fact that it means code blocks in general are illegible on dark theme is really infuriating, as someone who uses dark theme a lot. I've had to turn on auto-syntax highlighting to fix this. I think we should still default to auto-highlighting, and let people disable it instead.

@kyrias
Copy link
Contributor Author

kyrias commented Jun 30, 2017

Or the style could be fixed instead, and @ara4n said a few weeks ago that he'd done the same fix to the regular theme already, so shouldn't be hard. I have no clue where said stylesheet is, or what he changed though. And the auto-detection is pretty much always wrong, which is why we started looking into disabling it at all.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable syntax highlighting by default, or on stuff that doesn't look like code
5 participants