diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-30 09:21:53 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-30 09:21:53 -0400 |
commit | c2cd58a33f52c6567e39d8ba563425dc06916d41 (patch) | |
tree | 492f80236bf30aa05514f1428296cf6b0432f435 /web/react/utils/utils.jsx | |
parent | b686e51cfde4c50fba8e2797a532c8813ee8aade (diff) | |
parent | d630567c91d01d5b78be84ac1a5e638e4e72516c (diff) | |
download | chat-c2cd58a33f52c6567e39d8ba563425dc06916d41.tar.gz chat-c2cd58a33f52c6567e39d8ba563425dc06916d41.tar.bz2 chat-c2cd58a33f52c6567e39d8ba563425dc06916d41.zip |
Merge pull request #1220 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 35ce49ae2..c7c8549b9 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -424,6 +424,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); } @@ -612,6 +617,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') { |