TextualBody: only highlight code block if language was specified
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 vector-im/riot-web#508. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
This commit is contained in:
parent
661e6a6d01
commit
48c32172fd
3 changed files with 18 additions and 1 deletions
|
@ -29,6 +29,7 @@ import Modal from '../../../Modal';
|
|||
import SdkConfig from '../../../SdkConfig';
|
||||
import dis from '../../../dispatcher';
|
||||
import { _t } from '../../../languageHandler';
|
||||
import UserSettingsStore from "../../../UserSettingsStore";
|
||||
|
||||
linkifyMatrix(linkify);
|
||||
|
||||
|
@ -90,7 +91,18 @@ module.exports = React.createClass({
|
|||
setTimeout(() => {
|
||||
if (this._unmounted) return;
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
highlight.highlightBlock(blocks[i]);
|
||||
if (UserSettingsStore.getSyncedSetting("enableSyntaxHighlightLanguageDetection", false)) {
|
||||
highlight.highlightBlock(blocks[i])
|
||||
} else {
|
||||
// Only syntax highlight if there's a class starting with language-
|
||||
let classes = blocks[i].className.split(/\s+/).filter(function (cl) {
|
||||
return cl.startsWith('language-');
|
||||
});
|
||||
|
||||
if (classes.length != 0) {
|
||||
highlight.highlightBlock(blocks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue