Merge pull request #1170 from florianorben/PLT-395

PLT-395: Add syntax highlighting to Markdown code blocks
Этот коммит содержится в:
Harrison Healey
2015-10-26 09:50:40 -04:00
родитель 845b07ea5f 51032ae11d
Коммит fa2c9878d2
13 изменённых файлов: 219 добавлений и 1 удалений

Просмотреть файл

@@ -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') {