From 9e4d07926ae062e31ad92c51a152c5d6ef36e52f Mon Sep 17 00:00:00 2001 From: hoijui Date: Mon, 21 Oct 2019 08:26:42 +0200 Subject: [PATCH 01/20] 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 03f04664..b45c60ff 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -168,11 +168,11 @@ export function renderTags (view) { } function slugifyWithUTF8 (text) { - // remove html tags and trim spaces + // remove HTML tags and trim spaces let newText = stripTags(text.toString().trim()) - // 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 } From 34c2bfcfc5e936e88671e920d6f5ac51f9a753ab Mon Sep 17 00:00:00 2001 From: hoijui Date: Mon, 21 Oct 2019 22:10:06 +0200 Subject: [PATCH 02/20] Allow to generate lower case header references through the config (#1305) 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 30bd3ced..c841d864 100644 --- a/config.json.example +++ b/config.json.example @@ -127,6 +127,7 @@ "plantuml": { "server": "https://www.plantuml.com/plantuml" - } + }, + "linkifyHeaderStyle": "gfm" } } diff --git a/lib/config/default.js b/lib/config/default.js index 93de2599..f3dafea9 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -162,5 +162,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 f8c1f6cf..f1de7dbf 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -99,7 +99,8 @@ statusRouter.get('/config', function (req, res) { version: config.fullversion, plantumlServer: config.plantuml.server, 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 b45c60ff..50b75f8a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -867,7 +867,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)) + var 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 7821329d..e812bb8e 100644 --- a/public/js/lib/common/constant.ejs +++ b/public/js/lib/common/constant.ejs @@ -6,4 +6,6 @@ window.plantumlServer = '<%- plantumlServer %>' window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %> +window.linkifyHeaderStyle = <%- JSON.stringify(linkifyHeaderStyle) %> + window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>' From 0dfb8a320d8366b08f7548dbd17f1623ffae1dd9 Mon Sep 17 00:00:00 2001 From: kondouagi Date: Mon, 21 Oct 2019 13:37:59 +0900 Subject: [PATCH 03/20] feat: add syntax hilight on pdf Signed-off-by: kondouagi --- lib/config/index.js | 1 + lib/response.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/config/index.js b/lib/config/index.js index 22e7ec47..b422da74 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -200,6 +200,7 @@ config.sslCAPath.forEach(function (capath, i, array) { array[i] = path.resolve(appRootPath, capath) }) +config.appRootPath = appRootPath config.sslCertPath = path.resolve(appRootPath, config.sslCertPath) config.sslKeyPath = path.resolve(appRootPath, config.sslKeyPath) config.dhParamPath = path.resolve(appRootPath, config.dhParamPath) diff --git a/lib/response.js b/lib/response.js index 10b57c79..ce7e4fc3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -316,17 +316,22 @@ function actionPDF (req, res, note) { var content = extracted.markdown var title = models.Note.decodeTitle(note.title) + var highlightCssPath = path.join(config.appRootPath, '/node_modules/highlight.js/styles/github-gist.css') + if (!fs.existsSync(config.tmpPath)) { fs.mkdirSync(config.tmpPath) } - var path = config.tmpPath + '/' + Date.now() + '.pdf' + var pdfPath = config.tmpPath + '/' + Date.now() + '.pdf' content = content.replace(/\]\(\//g, '](' + url + '/') - markdownpdf().from.string(content).to(path, function () { - if (!fs.existsSync(path)) { - logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path) + var markdownpdfOptions = { + highlightCssPath: highlightCssPath + } + markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () { + if (!fs.existsSync(pdfPath)) { + logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + pdfPath) return errorInternalError(res) } - var stream = fs.createReadStream(path) + var stream = fs.createReadStream(pdfPath) var filename = title // Be careful of special characters filename = encodeURIComponent(filename) @@ -336,7 +341,7 @@ function actionPDF (req, res, note) { res.setHeader('Content-Type', 'application/pdf; charset=UTF-8') res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling stream.pipe(res) - fs.unlinkSync(path) + fs.unlinkSync(pdfPath) }) } From 905414d039f753be0082b16f294c80b744df6463 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 22 Oct 2019 08:40:02 +0200 Subject: [PATCH 04/20] Make `id` block-scoped (thanks @Yukaii) Co-Authored-By: Yukai Huang Signed-off-by: hoijui --- public/js/extra.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/extra.js b/public/js/extra.js index 50b75f8a..7ac331cf 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -867,7 +867,7 @@ 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 - var 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() From c4906c0592178714745b64092c81e68a1f0202f6 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 22 Oct 2019 17:12:47 +0200 Subject: [PATCH 05/20] linkifyHeaderStyle needs no string-ification; is already str. Co-Authored-By: Yukai Huang Signed-off-by: hoijui --- public/js/lib/common/constant.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/lib/common/constant.ejs b/public/js/lib/common/constant.ejs index e812bb8e..057c92c8 100644 --- a/public/js/lib/common/constant.ejs +++ b/public/js/lib/common/constant.ejs @@ -6,6 +6,6 @@ window.plantumlServer = '<%- plantumlServer %>' window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %> -window.linkifyHeaderStyle = <%- JSON.stringify(linkifyHeaderStyle) %> +window.linkifyHeaderStyle = '<%- linkifyHeaderStyle %>' window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>' From d0b02af144204c63bd742d5a61aee0f35ed82f0b Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Wed, 23 Oct 2019 00:54:02 +0800 Subject: [PATCH 06/20] fix: wrong permission caused user cannot upload image in docker Signed-off-by: BoHong Li --- deployments/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/Dockerfile b/deployments/Dockerfile index e1c411c4..916012a5 100644 --- a/deployments/Dockerfile +++ b/deployments/Dockerfile @@ -18,6 +18,6 @@ RUN set -xe && \ FROM hackmdio/runtime:1.0.4 USER hackmd WORKDIR /home/hackmd/app -COPY --from=BUILD /home/hackmd/app . +COPY --chown=1500:1500 --from=BUILD /home/hackmd/app . EXPOSE 3000 ENTRYPOINT ["/home/hackmd/app/docker-entrypoint.sh"] From 225e28bdbd0e75829504623b03ce3fa32de8acc2 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Fri, 25 Oct 2019 15:12:20 +0900 Subject: [PATCH 07/20] support to login with github enterprise Signed-off-by: kamijin_fanta --- config.json.example | 1 + lib/models/user.js | 3 ++- lib/web/auth/github/index.js | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index 30bd3ced..b878067a 100644 --- a/config.json.example +++ b/config.json.example @@ -50,6 +50,7 @@ "consumerSecret": "change this" }, "github": { + "enterpriseURL": "if you use github.com, not need to specify", "clientID": "change this", "clientSecret": "change this" }, diff --git a/lib/models/user.js b/lib/models/user.js index ba817c0b..19836029 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -103,7 +103,8 @@ module.exports = function (sequelize, DataTypes) { else photo += '?size=bigger' break case 'github': - photo = 'https://avatars.githubusercontent.com/u/' + profile.id + if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '') + else photo = 'https://avatars.githubusercontent.com/u/' + profile.id if (bigger) photo += '?s=400' else photo += '?s=96' break diff --git a/lib/web/auth/github/index.js b/lib/web/auth/github/index.js index c1bf48f8..0609f6b3 100644 --- a/lib/web/auth/github/index.js +++ b/lib/web/auth/github/index.js @@ -6,13 +6,21 @@ const GithubStrategy = require('passport-github').Strategy const config = require('../../../config') const response = require('../../../response') const { setReturnToFromReferer, passportGeneralCallback } = require('../utils') +const { URL } = require('url') const githubAuth = module.exports = Router() +function githubUrl (path) { + return config.github.enterpriseURL && new URL(path, config.github.enterpriseURL).toString() +} + passport.use(new GithubStrategy({ clientID: config.github.clientID, clientSecret: config.github.clientSecret, - callbackURL: config.serverURL + '/auth/github/callback' + callbackURL: config.serverURL + '/auth/github/callback', + authorizationURL: githubUrl('login/oauth/authorize'), + tokenURL: githubUrl('login/oauth/access_token'), + userProfileURL: githubUrl('api/v3/user') }, passportGeneralCallback)) githubAuth.get('/auth/github', function (req, res, next) { From 052c787c0a92847187a4a12a1b52051c48bd9e46 Mon Sep 17 00:00:00 2001 From: Max Wu Date: Sat, 26 Oct 2019 15:02:35 +0800 Subject: [PATCH 08/20] fix: table editor key map might conflict with textcomplete keymap and avoid add/remove keymap on every updateActiveState Signed-off-by: Max Wu --- public/js/index.js | 44 +++++++++++++++------------- public/js/lib/editor/table-editor.js | 10 +++++-- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index ad8f3a86..67c1525d 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -3116,6 +3116,27 @@ function matchInContainer (text) { } } +const textCompleteKeyMap = { + Up: function () { + return false + }, + Right: function () { + editor.doc.cm.execCommand('goCharRight') + }, + Down: function () { + return false + }, + Left: function () { + editor.doc.cm.execCommand('goCharLeft') + }, + Enter: function () { + return false + }, + Backspace: function () { + editor.doc.cm.execCommand('delCharBefore') + } +} + $(editor.getInputField()) .textcomplete([ { // emoji strategy @@ -3317,29 +3338,10 @@ $(editor.getInputField()) }, 'textComplete:show': function (e) { $(this).data('autocompleting', true) - editor.setOption('extraKeys', { - Up: function () { - return false - }, - Right: function () { - editor.doc.cm.execCommand('goCharRight') - }, - Down: function () { - return false - }, - Left: function () { - editor.doc.cm.execCommand('goCharLeft') - }, - Enter: function () { - return false - }, - Backspace: function () { - editor.doc.cm.execCommand('delCharBefore') - } - }) + editor.addKeyMap(textCompleteKeyMap) }, 'textComplete:hide': function (e) { $(this).data('autocompleting', false) - editor.setOption('extraKeys', editorInstance.defaultExtraKeys) + editor.removeKeyMap(textCompleteKeyMap) } }) diff --git a/public/js/lib/editor/table-editor.js b/public/js/lib/editor/table-editor.js index df6ef80b..439f1f5a 100644 --- a/public/js/lib/editor/table-editor.js +++ b/public/js/lib/editor/table-editor.js @@ -166,19 +166,25 @@ export function initTableEditor (editor) { 'Alt-Shift-Ctrl-Down': () => { tableEditor.moveRow(1, opts) }, 'Alt-Shift-Cmd-Down': () => { tableEditor.moveRow(1, opts) } }) + let lastActive // enable keymap if the cursor is in a table function updateActiveState () { const tableTools = $('.toolbar .table-tools') const active = tableEditor.cursorIsInTable(opts) + // avoid to update if state not changed + if (lastActive === active) { + return + } if (active) { tableTools.show() tableTools.parent().scrollLeft(tableTools.parent()[0].scrollWidth) - editor.setOption('extraKeys', keyMap) + editor.addKeyMap(keyMap) } else { tableTools.hide() - editor.setOption('extraKeys', null) + editor.removeKeyMap(keyMap) tableEditor.resetSmartCursor() } + lastActive = active } // event subscriptions editor.on('cursorActivity', () => { From ba37faf71a1dc62b7233c9919c749e14c8bb5ed2 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Sat, 26 Oct 2019 22:17:45 +0900 Subject: [PATCH 09/20] github login: default config/config from env vars. Signed-off-by: kamijin_fanta --- lib/config/default.js | 1 + lib/config/environment.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/config/default.js b/lib/config/default.js index 93de2599..9083b4c0 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,6 +104,7 @@ module.exports = { consumerSecret: undefined }, github: { + enterpriseURL: undefined, clientID: undefined, clientSecret: undefined }, diff --git a/lib/config/environment.js b/lib/config/environment.js index de573e18..e3a15006 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -66,6 +66,7 @@ module.exports = { consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET }, github: { + enterpriseURL: process.env.ENTERPRISE_URL, clientID: process.env.CMD_GITHUB_CLIENTID, clientSecret: process.env.CMD_GITHUB_CLIENTSECRET }, From b785ead5e5a9abe37f681f1281177ce9e00caed1 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Sun, 27 Oct 2019 00:01:56 +0900 Subject: [PATCH 10/20] github login: fix env name Signed-off-by: kamijin_fanta --- lib/config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/environment.js b/lib/config/environment.js index e3a15006..bc2516e7 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -66,7 +66,7 @@ module.exports = { consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET }, github: { - enterpriseURL: process.env.ENTERPRISE_URL, + enterpriseURL: process.env.CMD_GITHUB_ENTERPRISE_URL, clientID: process.env.CMD_GITHUB_CLIENTID, clientSecret: process.env.CMD_GITHUB_CLIENTSECRET }, From 3d5d8e20f73bf8d363975273f8ade70d729aa126 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 09:56:47 +0100 Subject: [PATCH 11/20] document `linkifyHeaderStyle` in default.js Signed-off-by: hoijui --- lib/config/default.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/config/default.js b/lib/config/default.js index f3dafea9..e3aee6ca 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -163,5 +163,18 @@ module.exports = { allowGravatar: true, allowPDFExport: true, openID: false, + // linkifyHeaderStyle - How is a header text converted into a link id. + // Header Example: "3.1. Good Morning my Friend! - Do you have 5$?" + // * 'keep-case' is the legacy CodiMD value. + // Generated id: "31-Good-Morning-my-Friend---Do-you-have-5" + // * 'lower-case' is the same like legacy (see above), but converted to lower-case. + // Generated id: "#31-good-morning-my-friend---do-you-have-5" + // * 'gfm' _GitHub-Flavored Markdown_ style as described here: + // https://gist.github.com/asabaylus/3071099#gistcomment-1593627 + // It works like 'lower-case', but making sure the ID is unique. + // This is What GitHub, GitLab and (hopefully) most other tools use. + // Generated id: "31-good-morning-my-friend---do-you-have-5" + // 2nd appearance: "31-good-morning-my-friend---do-you-have-5-1" + // 3rd appearance: "31-good-morning-my-friend---do-you-have-5-2" linkifyHeaderStyle: 'keep-case' } From 9742f7d075c2a8bab5169539dc041de18f88a891 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 09:58:59 +0100 Subject: [PATCH 12/20] fix gfm header link generation with respect to `deduplicatedHeaderId` Signed-off-by: hoijui --- public/js/extra.js | 88 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 7ac331cf..0b521ccd 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -859,6 +859,37 @@ const anchorForId = id => { return anchor } +const createHeaderId = (headerContent, headerIds = null) => { + + // to escape characters not allow in css and humanize + const slug = slugifyWithUTF8(headerContent) + let id + if (window.linkifyHeaderStyle === 'keep-case') { + id = slug + } else if (window.linkifyHeaderStyle === 'lower-case') { + // to make compatible with GitHub, GitLab, Pandoc and many more + id = slug.toLowerCase() + } else if (window.linkifyHeaderStyle === 'gfm') { + // see GitHub implementation reference: + // https://gist.github.com/asabaylus/3071099#gistcomment-1593627 + // it works like 'lower-case', but ... + const id_base = slug.toLowerCase() + id = id_base + if (headerIds !== null) { + // ... making sure the id is unique + let i = 1 + while (headerIds.has(id)) { + id = id_base + '-' + i + i++ + } + headerIds.add(id) + } + } else { + throw new Error('Unknown linkifyHeaderStyle value "' + window.linkifyHeaderStyle + '"') + } + return id +} + const linkifyAnchors = (level, containingElement) => { const headers = containingElement.getElementsByTagName(`h${level}`) @@ -866,13 +897,7 @@ const linkifyAnchors = (level, containingElement) => { const header = headers[i] if (header.getElementsByClassName('anchor').length === 0) { if (typeof header.id === 'undefined' || header.id === '') { - // to escape characters not allow in css and humanize - 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 + header.id = createHeaderId(getHeaderContent(header)) } if (!(typeof header.id === 'undefined' || header.id === '')) { header.insertBefore(anchorForId(header.id), header.firstChild) @@ -898,20 +923,45 @@ function getHeaderContent (header) { return headerHTML[0].innerHTML } +function changeHeaderId ($header, id, newId) { + + $header.attr('id', newId) + const $headerLink = $header.find(`> a.anchor[href="#${id}"]`) + $headerLink.attr('href', `#${newId}`) + $headerLink.attr('title', newId) +} + export function deduplicatedHeaderId (view) { + + // headers contained in the last change const headers = view.find(':header.raw').removeClass('raw').toArray() - for (let i = 0; i < headers.length; i++) { - const id = $(headers[i]).attr('id') - if (!id) continue - const duplicatedHeaders = view.find(`:header[id="${id}"]`).toArray() - for (let j = 0; j < duplicatedHeaders.length; j++) { - if (duplicatedHeaders[j] !== headers[i]) { - const newId = id + j - const $duplicatedHeader = $(duplicatedHeaders[j]) - $duplicatedHeader.attr('id', newId) - const $headerLink = $duplicatedHeader.find(`> a.anchor[href="#${id}"]`) - $headerLink.attr('href', `#${newId}`) - $headerLink.attr('title', newId) + if (headers.length == 0) { + return; + } + if (window.linkifyHeaderStyle === 'gfm') { + // consistent with GitHub, GitLab, Pandoc & co. + // all headers contained in the document, in order of appearance + const allHeaders = view.find(`:header`).toArray() + // list of finaly assigned header IDs + let headerIds = new Set() + for (let j = 0; j < allHeaders.length; j++) { + const $header = $(allHeaders[j]) + const id = $header.attr('id') + const newId = createHeaderId(getHeaderContent($header), headerIds) + changeHeaderId($header, id, newId) + } + } else { + // the legacy way + for (let i = 0; i < headers.length; i++) { + const id = $(headers[i]).attr('id') + if (!id) continue + const duplicatedHeaders = view.find(`:header[id="${id}"]`).toArray() + for (let j = 0; j < duplicatedHeaders.length; j++) { + if (duplicatedHeaders[j] !== headers[i]) { + const newId = id + j + const $header = $(duplicatedHeaders[j]) + changeHeaderId($header, id, newId) + } } } } From c202cca39b1098463b27bd9a57c159334fb4c7f9 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 09:59:42 +0100 Subject: [PATCH 13/20] also use gfm header generation in test and debug configuraitons Signed-off-by: hoijui --- config.json.example | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index c841d864..11422652 100644 --- a/config.json.example +++ b/config.json.example @@ -3,7 +3,8 @@ "db": { "dialect": "sqlite", "storage": ":memory:" - } + }, + "linkifyHeaderStyle": "gfm" }, "development": { "loglevel": "debug", @@ -13,7 +14,8 @@ "db": { "dialect": "sqlite", "storage": "./db.codimd.sqlite" - } + }, + "linkifyHeaderStyle": "gfm" }, "production": { "domain": "localhost", From 7c5ac3603af7b66fe3d754b8d9025498a26ba2a3 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 10:53:20 +0100 Subject: [PATCH 14/20] allow to define header link generation style via environment var Signed-off-by: hoijui --- lib/config/environment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/config/environment.js b/lib/config/environment.js index de573e18..905f0e0d 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -135,5 +135,6 @@ module.exports = { allowEmailRegister: toBooleanConfig(process.env.CMD_ALLOW_EMAIL_REGISTER), allowGravatar: toBooleanConfig(process.env.CMD_ALLOW_GRAVATAR), allowPDFExport: toBooleanConfig(process.env.CMD_ALLOW_PDF_EXPORT), - openID: toBooleanConfig(process.env.CMD_OPENID) + openID: toBooleanConfig(process.env.CMD_OPENID), + linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE } From aaf9466498cecfd2b75a5ece688edff35669c9d5 Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 11:57:51 +0100 Subject: [PATCH 15/20] make `headerIds` `const` [fix] Signed-off-by: hoijui --- public/js/extra.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/extra.js b/public/js/extra.js index 0b521ccd..3d3f7f64 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -943,7 +943,7 @@ export function deduplicatedHeaderId (view) { // all headers contained in the document, in order of appearance const allHeaders = view.find(`:header`).toArray() // list of finaly assigned header IDs - let headerIds = new Set() + const headerIds = new Set() for (let j = 0; j < allHeaders.length; j++) { const $header = $(allHeaders[j]) const id = $header.attr('id') From 558fa5fcf46b0a94c49c503c2e1373c86829ff1e Mon Sep 17 00:00:00 2001 From: hoijui Date: Tue, 29 Oct 2019 13:20:18 +0100 Subject: [PATCH 16/20] make standard conform [fix] Signed-off-by: hoijui --- public/js/extra.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 3d3f7f64..1282b801 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -860,7 +860,6 @@ const anchorForId = id => { } const createHeaderId = (headerContent, headerIds = null) => { - // to escape characters not allow in css and humanize const slug = slugifyWithUTF8(headerContent) let id @@ -873,13 +872,13 @@ const createHeaderId = (headerContent, headerIds = null) => { // see GitHub implementation reference: // https://gist.github.com/asabaylus/3071099#gistcomment-1593627 // it works like 'lower-case', but ... - const id_base = slug.toLowerCase() - id = id_base + const idBase = slug.toLowerCase() + id = idBase if (headerIds !== null) { // ... making sure the id is unique let i = 1 while (headerIds.has(id)) { - id = id_base + '-' + i + id = idBase + '-' + i i++ } headerIds.add(id) @@ -924,7 +923,6 @@ function getHeaderContent (header) { } function changeHeaderId ($header, id, newId) { - $header.attr('id', newId) const $headerLink = $header.find(`> a.anchor[href="#${id}"]`) $headerLink.attr('href', `#${newId}`) @@ -932,11 +930,10 @@ function changeHeaderId ($header, id, newId) { } export function deduplicatedHeaderId (view) { - // headers contained in the last change const headers = view.find(':header.raw').removeClass('raw').toArray() - if (headers.length == 0) { - return; + if (headers.length === 0) { + return } if (window.linkifyHeaderStyle === 'gfm') { // consistent with GitHub, GitLab, Pandoc & co. From bac3921197ce7e0598a1e8f5dcbd03b234111959 Mon Sep 17 00:00:00 2001 From: rhtenhove Date: Tue, 8 Oct 2019 18:47:54 +0200 Subject: [PATCH 17/20] Add https_proxy support to gitlab oauth Signed-off-by: Ruben ten Hove --- lib/web/auth/gitlab/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/web/auth/gitlab/index.js b/lib/web/auth/gitlab/index.js index 22611eed..f54e2434 100644 --- a/lib/web/auth/gitlab/index.js +++ b/lib/web/auth/gitlab/index.js @@ -6,16 +6,24 @@ const GitlabStrategy = require('passport-gitlab2').Strategy const config = require('../../../config') const response = require('../../../response') const { setReturnToFromReferer, passportGeneralCallback } = require('../utils') +const HttpsProxyAgent = require('https-proxy-agent'); const gitlabAuth = module.exports = Router() -passport.use(new GitlabStrategy({ +let gitlabAuthStrategy = new GitlabStrategy({ baseURL: config.gitlab.baseURL, clientID: config.gitlab.clientID, clientSecret: config.gitlab.clientSecret, scope: config.gitlab.scope, callbackURL: config.serverURL + '/auth/gitlab/callback' -}, passportGeneralCallback)) +}, passportGeneralCallback) + +if (process.env['https_proxy']) { + let httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']); + gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent); +} + +passport.use(gitlabAuthStrategy) gitlabAuth.get('/auth/gitlab', function (req, res, next) { setReturnToFromReferer(req) From afc4a3e11d7a6ea9b36525c6bc26abd76156cf45 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 30 Oct 2019 07:32:14 +0100 Subject: [PATCH 18/20] yarn add https-proxy-agent Signed-off-by: Ruben ten Hove --- package.json | 1 + yarn.lock | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/package.json b/package.json index d049e070..f6f75f8c 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "handlebars": "~4.1.2", "helmet": "~3.20.0", "highlight.js": "~9.15.9", + "https-proxy-agent": "^3.0.1", "i18n": "~0.8.3", "ionicons": "~2.0.1", "isomorphic-fetch": "~2.2.1", diff --git a/yarn.lock b/yarn.lock index cb7b2c23..4949d48e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6442,6 +6442,14 @@ https-browserify@^1.0.0: resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73" integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM= +https-proxy-agent@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz#b8c286433e87602311b01c8ea34413d856a4af81" + integrity sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg== + dependencies: + agent-base "^4.3.0" + debug "^3.1.0" + i18n@~0.8.3: version "0.8.3" resolved "https://registry.yarnpkg.com/i18n/-/i18n-0.8.3.tgz#2d8cf1c24722602c2041d01ba6ae5eaa51388f0e" From 2a365d69717b869cdb9373fa18cc42bd6d32fbad Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Wed, 30 Oct 2019 07:58:36 +0100 Subject: [PATCH 19/20] fix linter issues Signed-off-by: Ruben ten Hove --- lib/web/auth/gitlab/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/web/auth/gitlab/index.js b/lib/web/auth/gitlab/index.js index f54e2434..f5f493de 100644 --- a/lib/web/auth/gitlab/index.js +++ b/lib/web/auth/gitlab/index.js @@ -6,11 +6,11 @@ const GitlabStrategy = require('passport-gitlab2').Strategy const config = require('../../../config') const response = require('../../../response') const { setReturnToFromReferer, passportGeneralCallback } = require('../utils') -const HttpsProxyAgent = require('https-proxy-agent'); +const HttpsProxyAgent = require('https-proxy-agent') const gitlabAuth = module.exports = Router() -let gitlabAuthStrategy = new GitlabStrategy({ +const gitlabAuthStrategy = new GitlabStrategy({ baseURL: config.gitlab.baseURL, clientID: config.gitlab.clientID, clientSecret: config.gitlab.clientSecret, @@ -19,8 +19,8 @@ let gitlabAuthStrategy = new GitlabStrategy({ }, passportGeneralCallback) if (process.env['https_proxy']) { - let httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']); - gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent); + const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']) + gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent) } passport.use(gitlabAuthStrategy) From 9e6f980d8d3422e0a3f178226e1445ca37009a95 Mon Sep 17 00:00:00 2001 From: kamijin_fanta Date: Wed, 30 Oct 2019 17:02:15 +0900 Subject: [PATCH 20/20] github-login: move comment to default.js Signed-off-by: kamijin_fanta --- config.json.example | 1 - lib/config/default.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index b878067a..30bd3ced 100644 --- a/config.json.example +++ b/config.json.example @@ -50,7 +50,6 @@ "consumerSecret": "change this" }, "github": { - "enterpriseURL": "if you use github.com, not need to specify", "clientID": "change this", "clientSecret": "change this" }, diff --git a/lib/config/default.js b/lib/config/default.js index 9083b4c0..3463c4a2 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -104,7 +104,7 @@ module.exports = { consumerSecret: undefined }, github: { - enterpriseURL: undefined, + enterpriseURL: undefined, // if you use github.com, not need to specify clientID: undefined, clientSecret: undefined },