From 20adab2f32a785c2dedcd42ee8e0750039fd9dd9 Mon Sep 17 00:00:00 2001 From: hoijui Date: Mon, 21 Oct 2019 08:26:42 +0200 Subject: slight doc comment touch-up/simplification [minor] Signed-off-by: hoijui --- public/js/extra.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 4431513d..91984c2c 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -164,11 +164,11 @@ export function renderTags (view) { } function slugifyWithUTF8 (text) { - // remove html tags and trim spaces + // remove HTML tags and trim spaces let newText = S(text).trim().stripTags().s - // replace all spaces in between to dashes + // replace space between words with dashes newText = newText.replace(/\s+/g, '-') - // slugify string to make it valid for attribute + // slugify string to make it valid as an attribute newText = newText.replace(/([!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, '') return newText } -- cgit v1.2.3 From e654ca8a3130108a6616131e35524d8f50d80ed0 Mon Sep 17 00:00:00 2001 From: hoijui Date: Mon, 21 Oct 2019 22:10:06 +0200 Subject: Allow to generate lower case header references through the config This makes the references consistent/compatible with GitHub, GitLab, Pandoc and many other tools. This behavior can be enabled in config.json with: ``` "linkifyHeaderStyle": "gfm" ``` Signed-off-by: hoijui --- config.json.example | 3 ++- lib/config/default.js | 3 ++- lib/web/statusRouter.js | 3 ++- public/js/extra.js | 6 +++++- public/js/lib/common/constant.ejs | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config.json.example b/config.json.example index f627fadb..e3bd54b4 100644 --- a/config.json.example +++ b/config.json.example @@ -123,6 +123,7 @@ { "connectionString": "change this", "container": "change this" - } + }, + "linkifyHeaderStyle": "gfm" } } diff --git a/lib/config/default.js b/lib/config/default.js index 19bbeb21..f5cceac6 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -157,5 +157,6 @@ module.exports = { allowEmailRegister: true, allowGravatar: true, allowPDFExport: true, - openID: false + openID: false, + linkifyHeaderStyle: 'keep-case' } diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index da69e62c..1d9a1157 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -96,7 +96,8 @@ statusRouter.get('/config', function (req, res) { debug: config.debug, version: config.fullversion, DROPBOX_APP_KEY: config.dropbox.appKey, - allowedUploadMimeTypes: config.allowedUploadMimeTypes + allowedUploadMimeTypes: config.allowedUploadMimeTypes, + linkifyHeaderStyle: config.linkifyHeaderStyle } res.set({ 'Cache-Control': 'private', // only cache by client diff --git a/public/js/extra.js b/public/js/extra.js index 91984c2c..d381576f 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -833,7 +833,11 @@ const linkifyAnchors = (level, containingElement) => { if (header.getElementsByClassName('anchor').length === 0) { if (typeof header.id === 'undefined' || header.id === '') { // to escape characters not allow in css and humanize - const id = slugifyWithUTF8(getHeaderContent(header)) + let id = slugifyWithUTF8(getHeaderContent(header)) + // to make compatible with GitHub, GitLab, Pandoc and many more + if (window.linkifyHeaderStyle !== 'keep-case') { + id = id.toLowerCase() + } header.id = id } if (!(typeof header.id === 'undefined' || header.id === '')) { diff --git a/public/js/lib/common/constant.ejs b/public/js/lib/common/constant.ejs index a94b815e..bbcb8c7a 100644 --- a/public/js/lib/common/constant.ejs +++ b/public/js/lib/common/constant.ejs @@ -5,4 +5,6 @@ window.version = '<%- version %>' window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %> +window.linkifyHeaderStyle = <%- JSON.stringify(linkifyHeaderStyle) %> + window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>' -- cgit v1.2.3