From 2453b2a9be16aeb379d62e31db02d43b60b5f8f7 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 18:29:37 +0800 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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); From 3df090302c8a9ba15fe30400e436a92934c9c1e2 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Sat, 22 Aug 2020 18:05:23 +0900 Subject: [PATCH 04/12] Convert "include" directives to functions Signed-off-by: Tamotsu Takahashi --- public/views/codimd.ejs | 10 +++++----- public/views/codimd/body.ejs | 10 +++++----- public/views/codimd/foot.ejs | 4 ++-- public/views/codimd/head.ejs | 6 +++--- public/views/error.ejs | 6 +++--- public/views/index.ejs | 10 +++++----- public/views/index/body.ejs | 2 +- public/views/index/foot.ejs | 4 ++-- public/views/index/head.ejs | 6 +++--- public/views/pretty.ejs | 14 +++++++------- public/views/slide.ejs | 14 +++++++------- 11 files changed, 43 insertions(+), 43 deletions(-) diff --git a/public/views/codimd.ejs b/public/views/codimd.ejs index 7818346c..1cdadba2 100644 --- a/public/views/codimd.ejs +++ b/public/views/codimd.ejs @@ -2,14 +2,14 @@ - <%- include codimd/head %> + <%- include('codimd/head'); %> - <%- include codimd/header %> - <%- include codimd/body %> - <%- include codimd/footer %> - <%- include codimd/foot %> + <%- include('codimd/header'); %> + <%- include('codimd/body'); %> + <%- include('codimd/footer'); %> + <%- include('codimd/foot'); %> diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index c688ae38..10315328 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -246,8 +246,8 @@ -<%- include ../shared/refresh-modal %> -<%- include ../shared/signin-modal %> -<%- include ../shared/help-modal %> -<%- include ../shared/revision-modal %> -<%- include ../shared/pandoc-export-modal %> +<%- include('../shared/refresh-modal'); %> +<%- include('../shared/signin-modal'); %> +<%- include('../shared/help-modal'); %> +<%- include('../shared/revision-modal'); %> +<%- include('../shared/pandoc-export-modal'); %> diff --git a/public/views/codimd/foot.ejs b/public/views/codimd/foot.ejs index 243fa40a..e3e74670 100644 --- a/public/views/codimd/foot.ejs +++ b/public/views/codimd/foot.ejs @@ -25,10 +25,10 @@ -<%- include ../build/index-scripts %> +<%- include('../build/index-scripts'); %> <% } else { %> -<%- include ../build/index-pack-scripts %> +<%- include('../build/index-pack-scripts'); %> <% } %> diff --git a/public/views/codimd/head.ejs b/public/views/codimd/head.ejs index 810781bb..c0cd9264 100644 --- a/public/views/codimd/head.ejs +++ b/public/views/codimd/head.ejs @@ -14,12 +14,12 @@ -<%- include ../build/index-header %> -<%- include ../shared/polyfill %> +<%- include('../build/index-header'); %> +<%- include('../shared/polyfill'); %> <% } else { %> -<%- include ../build/index-pack-header %> +<%- include('../build/index-pack-header'); %> <% } %> diff --git a/public/views/error.ejs b/public/views/error.ejs index 3ed76c8c..9e78ed7e 100644 --- a/public/views/error.ejs +++ b/public/views/error.ejs @@ -2,18 +2,18 @@ - <%- include codimd/head %> + <%- include('codimd/head'); %> - <%- include codimd/header %> + <%- include('codimd/header'); %>

<%- code %> <%- detail %> <%- msg %>

- <%- include codimd/footer %> + <%- include('codimd/footer'); %> diff --git a/public/views/index.ejs b/public/views/index.ejs index 5732db4a..1ec4eb81 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -2,14 +2,14 @@ - <%- include index/head %> + <%- include('index/head'); %> - <%- include index/header %> - <%- include index/body %> - <%- include index/footer %> - <%- include index/foot %> + <%- include('index/header'); %> + <%- include('index/body'); %> + <%- include('index/footer'); %> + <%- include('index/foot'); %> diff --git a/public/views/index/body.ejs b/public/views/index/body.ejs index db20b0e3..ee4f3e02 100644 --- a/public/views/index/body.ejs +++ b/public/views/index/body.ejs @@ -201,4 +201,4 @@ -<%- include ../shared/signin-modal %> +<%- include('../shared/signin-modal'); %> diff --git a/public/views/index/foot.ejs b/public/views/index/foot.ejs index e9af48e5..1d261e9a 100644 --- a/public/views/index/foot.ejs +++ b/public/views/index/foot.ejs @@ -7,7 +7,7 @@ -<%- include ../build/cover-scripts %> +<%- include('../build/cover-scripts'); %> <% } else { %> -<%- include ../build/cover-pack-scripts %> +<%- include('../build/cover-pack-scripts'); %> <% } %> diff --git a/public/views/index/head.ejs b/public/views/index/head.ejs index 8a1f08cf..58bf3c6d 100644 --- a/public/views/index/head.ejs +++ b/public/views/index/head.ejs @@ -15,10 +15,10 @@ -<%- include ../build/cover-header %> -<%- include ../shared/polyfill %> +<%- include('../build/cover-header'); %> +<%- include('../shared/polyfill'); %> <% } else { %> -<%- include ../build/cover-pack-header %> +<%- include('../build/cover-pack-header'); %> <% } %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index 30248a70..5f03a767 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -26,13 +26,13 @@ - <%- include build/pretty-header %> - <%- include shared/polyfill %> + <%- include('build/pretty-header'); %> + <%- include('shared/polyfill'); %> <% } else { %> - <%- include build/pretty-pack-header %> + <%- include('build/pretty-pack-header'); %> <% } %> @@ -71,7 +71,7 @@ <% if(typeof disqus !== 'undefined' && disqus) { %>
- <%- include shared/disqus %> + <%- include('shared/disqus'); %>
<% } %> @@ -100,11 +100,11 @@ -<%- include build/pretty-scripts %> +<%- include('build/pretty-scripts'); %> <% } else { %> -<%- include build/pretty-pack-scripts %> +<%- include('build/pretty-pack-scripts'); %> <% } %> -<%- include shared/ga %> +<%- include('shared/ga'); %> diff --git a/public/views/slide.ejs b/public/views/slide.ejs index 83d1539a..e7c0ef6d 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -21,14 +21,14 @@ - <%- include build/slide-header %> - <%- include shared/polyfill %> + <%- include('build/slide-header'); %> + <%- include('shared/polyfill'); %> <% } else { %> - <%- include build/slide-pack-header %> + <%- include('build/slide-pack-header'); %> <% } %> @@ -83,7 +83,7 @@ <% if(typeof disqus !== 'undefined' && disqus) { %>
- <%- include shared/disqus %> + <%- include('shared/disqus'); %>
<% } %> @@ -112,14 +112,14 @@ - <%- include build/slide-scripts %> + <%- include('build/slide-scripts'); %> <% } else { %> - <%- include build/slide-pack-scripts %> + <%- include('build/slide-pack-scripts'); %> <% } %> -<%- include shared/ga %> +<%- include('shared/ga'); %> From 0aff524bbae0cd397e9bb3caf8fb15d1e5d4ca5e Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 17:19:38 +0900 Subject: [PATCH 05/12] Make permission labels translatable. https://github.com/hackmdio/codimd/issues/1581#issuecomment-683236111 Signed-off-by: Tamotsu Takahashi --- public/views/codimd/body.ejs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index c688ae38..a48b4a40 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -15,20 +15,20 @@
From 66fdf7b49c8d88c3d785749864651bdab5e78046 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 19:17:11 +0900 Subject: [PATCH 06/12] Make permission and status translatable Move HTML from JS to EJS. https://github.com/hackmdio/codimd/issues/1581#issuecomment-683236111 https://github.com/hackmdio/codimd/issues/1581#issuecomment-683431173 Signed-off-by: Tamotsu Takahashi --- public/js/index.js | 77 +++++++---------------------- public/js/lib/editor/ui-elements.js | 5 ++ public/views/codimd/body.ejs | 22 +++++---- public/views/codimd/header.ejs | 9 +++- 4 files changed, 44 insertions(+), 69 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index c736cb7f..f5dab51b 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -237,21 +237,9 @@ const supportExtraTags = [ } ] const statusType = { - connected: { - msg: 'CONNECTED', - label: 'label-warning', - fa: 'fa-wifi' - }, - online: { - msg: 'ONLINE', - label: 'label-primary', - fa: 'fa-users' - }, - offline: { - msg: 'OFFLINE', - label: 'label-danger', - fa: 'fa-plug' - } + connected: 1, + online: 2, + offline: 3 } // global vars @@ -723,43 +711,23 @@ function checkTocStyle () { function showStatus (type, num) { currentStatus = type - var shortStatus = ui.toolbar.shortStatus - var status = ui.toolbar.status - var label = $('') - var fa = $('') - var msg = '' - var shortMsg = '' - shortStatus.html('') - status.html('') + ui.toolbar.statusConnected.hide() + ui.toolbar.statusOnline.hide() + ui.toolbar.statusOffline.hide() switch (currentStatus) { case statusType.connected: - label.addClass(statusType.connected.label) - fa.addClass(statusType.connected.fa) - msg = statusType.connected.msg + ui.toolbar.statusConnected.show() break case statusType.online: - label.addClass(statusType.online.label) - fa.addClass(statusType.online.fa) - shortMsg = num - msg = num + ' ' + statusType.online.msg + ui.toolbar.statusShortMsg.text(num) + ui.toolbar.statusOnline.show() break case statusType.offline: - label.addClass(statusType.offline.label) - fa.addClass(statusType.offline.fa) - msg = statusType.offline.msg + ui.toolbar.statusOffline.show() break } - - label.append(fa) - var shortLabel = label.clone() - - shortLabel.append(' ' + shortMsg) - shortStatus.append(shortLabel) - - label.append(' ' + msg) - status.append(label) } function toggleMode () { @@ -1647,41 +1615,34 @@ function updatePermission (newPermission) { permission = newPermission if (window.loaded) refreshView() } - var label = null - var title = null + ui.infobar.permission.label.hide() switch (permission) { case 'freely': - label = ' Freely' - title = 'Anyone can edit' + $('#permissionLabelFreely').show() break case 'editable': - label = ' Editable' - title = 'Signed people can edit' + $('#permissionLabelEditable').show() break case 'limited': - label = ' Limited' - title = 'Signed people can edit (forbid guest)' + $('#permissionLabelLimited').show() break case 'locked': - label = ' Locked' - title = 'Only owner can edit' + $('#permissionLabelLocked').show() break case 'protected': - label = ' Protected' - title = 'Only owner can edit (forbid guest)' + $('#permissionLabelProtected').show() break case 'private': - label = ' Private' - title = 'Only owner can view & edit' + $('#permissionLabelPrivate').show() break } if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) { - label += ' ' + ui.infobar.permission.labelCaretDown.show() ui.infobar.permission.label.removeClass('disabled') } else { + ui.infobar.permission.labelCaretDown.hide() ui.infobar.permission.label.addClass('disabled') } - ui.infobar.permission.label.html(label).attr('title', title) } function havePermission () { diff --git a/public/js/lib/editor/ui-elements.js b/public/js/lib/editor/ui-elements.js index d084607f..bedf51fc 100644 --- a/public/js/lib/editor/ui-elements.js +++ b/public/js/lib/editor/ui-elements.js @@ -9,6 +9,10 @@ export const getUIElements = () => ({ toolbar: { shortStatus: $('.ui-short-status'), status: $('.ui-status'), + statusShortMsg: $('.ui-status-short-msg'), + statusConnected: $('.ui-status-connected'), + statusOnline: $('.ui-status-online'), + statusOffline: $('.ui-status-offline'), new: $('.ui-new'), publish: $('.ui-publish'), extra: { @@ -46,6 +50,7 @@ export const getUIElements = () => ({ permission: { permission: $('.ui-permission'), label: $('.ui-permission-label'), + labelCaretDown: $('.ui-permission-caret-down'), freely: $('.ui-permission-freely'), editable: $('.ui-permission-editable'), locked: $('.ui-permission-locked'), diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index a48b4a40..0a2f17ee 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -12,15 +12,19 @@ - -