Skip to content

Commit 34c2bfc

Browse files
committed
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 <[email protected]>
1 parent 9e4d079 commit 34c2bfc

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

config.json.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"plantuml":
128128
{
129129
"server": "https://www.plantuml.com/plantuml"
130-
}
130+
},
131+
"linkifyHeaderStyle": "gfm"
131132
}
132133
}

lib/config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@ module.exports = {
162162
allowEmailRegister: true,
163163
allowGravatar: true,
164164
allowPDFExport: true,
165-
openID: false
165+
openID: false,
166+
linkifyHeaderStyle: 'keep-case'
166167
}

lib/web/statusRouter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ statusRouter.get('/config', function (req, res) {
9999
version: config.fullversion,
100100
plantumlServer: config.plantuml.server,
101101
DROPBOX_APP_KEY: config.dropbox.appKey,
102-
allowedUploadMimeTypes: config.allowedUploadMimeTypes
102+
allowedUploadMimeTypes: config.allowedUploadMimeTypes,
103+
linkifyHeaderStyle: config.linkifyHeaderStyle
103104
}
104105
res.set({
105106
'Cache-Control': 'private', // only cache by client

public/js/extra.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,11 @@ const linkifyAnchors = (level, containingElement) => {
867867
if (header.getElementsByClassName('anchor').length === 0) {
868868
if (typeof header.id === 'undefined' || header.id === '') {
869869
// to escape characters not allow in css and humanize
870-
const id = slugifyWithUTF8(getHeaderContent(header))
870+
var id = slugifyWithUTF8(getHeaderContent(header))
871+
// to make compatible with GitHub, GitLab, Pandoc and many more
872+
if (window.linkifyHeaderStyle !== 'keep-case') {
873+
id = id.toLowerCase()
874+
}
871875
header.id = id
872876
}
873877
if (!(typeof header.id === 'undefined' || header.id === '')) {

public/js/lib/common/constant.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ window.plantumlServer = '<%- plantumlServer %>'
66

77
window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %>
88

9+
window.linkifyHeaderStyle = <%- JSON.stringify(linkifyHeaderStyle) %>
10+
911
window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>'

0 commit comments

Comments
 (0)