diff options
author | Sheogorath | 2019-10-23 21:18:57 +0200 |
---|---|---|
committer | GitHub | 2019-10-23 21:18:57 +0200 |
commit | 7a27579589a739e66edc08528c20d32e7a9d7aaf (patch) | |
tree | ca04f1debba564b36e89fd37b63a2e1bdc61e97a /public/js | |
parent | 3db757754f02ecd874b4750ee2f7d735222ce641 (diff) | |
parent | e654ca8a3130108a6616131e35524d8f50d80ed0 (diff) |
Merge pull request #205 from hoijui/linkifyHeaderStyle
Allow to generate lower case header references through the config
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/extra.js | 12 | ||||
-rw-r--r-- | public/js/lib/common/constant.ejs | 2 |
2 files changed, 10 insertions, 4 deletions
diff --git a/public/js/extra.js b/public/js/extra.js index 4431513d..d381576f 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 } @@ -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 %>' |