Updated to support lang attribute and styles in editor

This commit is contained in:
Cheng-Han, Wu 2016-02-15 19:13:17 -06:00
parent 6967dac0ff
commit 880f6bcf02
4 changed files with 20 additions and 4 deletions

View file

@ -11,7 +11,7 @@ body {
/*overflow: hidden;*/ /*overflow: hidden;*/
} }
.CodeMirror { .CodeMirror {
font-family: "Source Code Pro", Consolas, monaco, "Microsoft JhengHei", Meiryo, " ゴシック", "MS Gothic", monospace; font-family: "Source Code Pro", Consolas, monaco, monospace;
letter-spacing: 0.025em; letter-spacing: 0.025em;
line-height: 1.25; line-height: 1.25;
font-size: 18px; font-size: 18px;
@ -19,6 +19,18 @@ body {
overflow-y: hidden !important; overflow-y: hidden !important;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
/* support japanese font */
.CodeMirror[lang^="ja"] {
font-family: "Source Code Pro", Consolas, monaco, Meiryo, " ゴシック", "MS Gothic", monospace;
}
/* support zh-tw font */
.CodeMirror[lang="zh-tw"] {
font-family: "Source Code Pro", Consolas, monaco, "Microsoft JhengHei", "微軟正黑", monospace;
}
/* support zh-cn font */
.CodeMirror[lang="zh-cn"] {
font-family: "Source Code Pro", Consolas, monaco, "Microsoft YaHei", "微软雅黑", monospace;
}
.CodeMirror-placeholder { .CodeMirror-placeholder {
color: #777 !important; color: #777 !important;
} }

View file

@ -66,7 +66,7 @@ function slugifyWithUTF8(text) {
} }
//parse meta //parse meta
function parseMeta(md, view, toc, tocAffix) { function parseMeta(md, edit, view, toc, tocAffix) {
var robots = null; var robots = null;
var lang = null; var lang = null;
var dir = null; var dir = null;
@ -93,10 +93,14 @@ function parseMeta(md, view, toc, tocAffix) {
view.attr('lang', lang); view.attr('lang', lang);
toc.attr('lang', lang); toc.attr('lang', lang);
tocAffix.attr('lang', lang); tocAffix.attr('lang', lang);
if (edit)
edit.attr('lang', lang);
} else { } else {
view.removeAttr('lang'); view.removeAttr('lang');
toc.removeAttr('lang'); toc.removeAttr('lang');
tocAffix.removeAttr('lang'); tocAffix.removeAttr('lang');
if (edit)
edit.removeAttr('lang', lang);
} }
//text direction //text direction
if (dir) { if (dir) {

View file

@ -2137,7 +2137,7 @@ function updateViewInner() {
var rendered = md.render(value); var rendered = md.render(value);
// only render again when meta changed // only render again when meta changed
if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) { if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
parseMeta(md, ui.area.markdown, $('#toc'), $('#toc-affix')); parseMeta(md, ui.area.codemirror, ui.area.markdown, $('#toc'), $('#toc-affix'));
rendered = md.render(value); rendered = md.render(value);
} }
// prevent XSS // prevent XSS

View file

@ -5,7 +5,7 @@ md.meta = {};
var rendered = md.render(text); var rendered = md.render(text);
// only render again when meta changed // only render again when meta changed
if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) { if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
parseMeta(md, markdown, $('#toc'), $('#toc-affix')); parseMeta(md, null, markdown, $('#toc'), $('#toc-affix'));
rendered = md.render(text); rendered = md.render(text);
} }
// prevent XSS // prevent XSS