diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-26 09:50:40 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-26 09:50:40 -0400 |
commit | fa2c9878d243e109f2e4d05e5d04556133485f30 (patch) | |
tree | 259156636b616d5d42f15e749f1cb5eaec9cce53 /web/react/utils/utils.jsx | |
parent | 845b07ea5f3214c4dc939b7eb65dcfba4e1e0b2a (diff) | |
parent | 51032ae11de9158ea6a4a4be6b73c621b1c75f2a (diff) | |
download | chat-fa2c9878d243e109f2e4d05e5d04556133485f30.tar.gz chat-fa2c9878d243e109f2e4d05e5d04556133485f30.tar.bz2 chat-fa2c9878d243e109f2e4d05e5d04556133485f30.zip |
Merge pull request #1170 from florianorben/PLT-395
PLT-395: Add syntax highlighting to Markdown code blocks
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r-- | web/react/utils/utils.jsx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 1f24cd634..7a876d518 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -403,6 +403,11 @@ export function toTitleCase(str) { } export function applyTheme(theme) { + if (!theme.codeTheme) { + theme.codeTheme = Constants.DEFAULT_CODE_THEME; + } + updateCodeTheme(theme.codeTheme); + if (theme.sidebarBg) { changeCss('.sidebar--left, .settings-modal .settings-table .settings-links, .sidebar--menu', 'background:' + theme.sidebarBg, 1); } @@ -589,6 +594,27 @@ export function rgb2hex(rgbIn) { return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } +export function updateCodeTheme(theme) { + const path = '/static/css/highlight/' + theme + '.css'; + const $link = $('link.code_theme'); + if (path !== $link.attr('href')) { + changeCss('code.hljs', 'visibility: hidden'); + var xmlHTTP = new XMLHttpRequest(); + xmlHTTP.open('GET', path, true); + xmlHTTP.onload = function onLoad() { + $link.attr('href', path); + if (isBrowserFirefox()) { + $link.one('load', () => { + changeCss('code.hljs', 'visibility: visible'); + }); + } else { + changeCss('code.hljs', 'visibility: visible'); + } + }; + xmlHTTP.send(); + } +} + export function placeCaretAtEnd(el) { el.focus(); if (typeof window.getSelection != 'undefined' && typeof document.createRange != 'undefined') { |