From 880f6bcf0266578c4e8e16d909c18af0449943cc Mon Sep 17 00:00:00 2001 From: "Cheng-Han, Wu" Date: Mon, 15 Feb 2016 19:13:17 -0600 Subject: [PATCH] Updated to support lang attribute and styles in editor --- public/css/index.css | 14 +++++++++++++- public/js/extra.js | 6 +++++- public/js/index.js | 2 +- public/js/pretty.js | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/public/css/index.css b/public/css/index.css index dba158429..177652066 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -11,7 +11,7 @@ body { /*overflow: hidden;*/ } .CodeMirror { - font-family: "Source Code Pro", Consolas, monaco, "Microsoft JhengHei", Meiryo, "MS ゴシック", "MS Gothic", monospace; + font-family: "Source Code Pro", Consolas, monaco, monospace; letter-spacing: 0.025em; line-height: 1.25; font-size: 18px; @@ -19,6 +19,18 @@ body { overflow-y: hidden !important; -webkit-overflow-scrolling: touch; } +/* support japanese font */ +.CodeMirror[lang^="ja"] { + font-family: "Source Code Pro", Consolas, monaco, Meiryo, "MS ゴシック", "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 { color: #777 !important; } diff --git a/public/js/extra.js b/public/js/extra.js index 28a91fbca..cbb30697e 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -66,7 +66,7 @@ function slugifyWithUTF8(text) { } //parse meta -function parseMeta(md, view, toc, tocAffix) { +function parseMeta(md, edit, view, toc, tocAffix) { var robots = null; var lang = null; var dir = null; @@ -93,10 +93,14 @@ function parseMeta(md, view, toc, tocAffix) { view.attr('lang', lang); toc.attr('lang', lang); tocAffix.attr('lang', lang); + if (edit) + edit.attr('lang', lang); } else { view.removeAttr('lang'); toc.removeAttr('lang'); tocAffix.removeAttr('lang'); + if (edit) + edit.removeAttr('lang', lang); } //text direction if (dir) { diff --git a/public/js/index.js b/public/js/index.js index 3507e0168..22aef5b7d 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2137,7 +2137,7 @@ function updateViewInner() { var rendered = md.render(value); // only render again when meta changed 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); } // prevent XSS diff --git a/public/js/pretty.js b/public/js/pretty.js index 40d90cf78..44d27e541 100644 --- a/public/js/pretty.js +++ b/public/js/pretty.js @@ -5,7 +5,7 @@ md.meta = {}; var rendered = md.render(text); // only render again when meta changed 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); } // prevent XSS