From 2453b2a9be16aeb379d62e31db02d43b60b5f8f7 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 18:29:37 +0800 Subject: [PATCH 1/3] set lang attr on according to user's choice Signed-off-by: BinotaLIU --- public/views/codimd.ejs | 2 +- public/views/error.ejs | 2 +- public/views/index.ejs | 2 +- public/views/pretty.ejs | 2 +- public/views/slide.ejs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/views/codimd.ejs b/public/views/codimd.ejs index 7818346c..33341b4a 100644 --- a/public/views/codimd.ejs +++ b/public/views/codimd.ejs @@ -1,5 +1,5 @@ - + <%- include codimd/head %> diff --git a/public/views/error.ejs b/public/views/error.ejs index 3ed76c8c..874988a5 100644 --- a/public/views/error.ejs +++ b/public/views/error.ejs @@ -1,5 +1,5 @@ - + <%- include codimd/head %> diff --git a/public/views/index.ejs b/public/views/index.ejs index 5732db4a..b7a3f684 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -1,5 +1,5 @@ - + <%- include index/head %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index aa330e0f..6d780c73 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -1,5 +1,5 @@ - + diff --git a/public/views/slide.ejs b/public/views/slide.ejs index 42b1165d..295b75f5 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -1,5 +1,5 @@ - + From bdd2de72bafaa6f67bb4cd7a6cfba803b55ee817 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 19:26:06 +0800 Subject: [PATCH 2/3] set default lang attr for note to 'en' Signed-off-by: BinotaLIU --- public/js/extra.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 99233c09..8f38a96e 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -191,18 +191,15 @@ export function parseMeta (md, edit, view, toc, tocAffix) { dir = meta.dir breaks = meta.breaks } - // text language - if (lang && typeof lang === 'string') { - 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) } + if (!lang || typeof lang !== 'string') { + lang = 'en' } + // text language + view.attr('lang', lang) + toc.attr('lang', lang) + tocAffix.attr('lang', lang) + if (edit) { edit.attr('lang', lang) } + // text direction if (dir && typeof dir === 'string') { view.attr('dir', dir) From 9b899c7778c7f5e066f031640ff3dfc563964623 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 22:40:28 +0800 Subject: [PATCH 3/3] escape attribute value for lang Signed-off-by: BinotaLIU --- public/js/extra.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 8f38a96e..61007b8b 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -16,6 +16,8 @@ import { stripTags } from '../../utils/string' import getUIElements from './lib/editor/ui-elements' import { emojifyImageDir } from './lib/editor/constants' +import { escapeAttrValue } from './render' + import markdownit from 'markdown-it' import markdownitContainer from 'markdown-it-container' @@ -734,8 +736,8 @@ export function exportToHTML (view) { html: src[0].outerHTML, 'ui-toc': toc.html(), 'ui-toc-affix': tocAffix.html(), - lang: (md && md.meta && md.meta.lang) ? `lang="${md.meta.lang}"` : null, - dir: (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : null + lang: (md && md.meta && md.meta.lang) ? `lang="${escapeAttrValue(md.meta.lang)}"` : null, + dir: (md && md.meta && md.meta.dir) ? `dir="${escapeAttrValue(md.meta.dir)}"` : null } const html = template(context) // console.log(html);