Skip to content

Commit 0b36c03

Browse files
committed
fix(config): regex improvements for links
1 parent 1547662 commit 0b36c03

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

eleventy.config.tracToHTML.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ module.exports = function tracToHTML(text) {
2929
})
3030
// Linkify http links outside brackets
3131
.replace(/(^|\s)(https?:\/\/[^\s]+)/g, function (_match, space, url) {
32-
return `${space}<a href="${url}" class="ext-link"><span class="icon"></span>${url}</a>`
32+
return `${
33+
space || ''
34+
}<a href="${url}" class="ext-link"><span class="icon"></span>${url}</a>`
3335
})
3436
// Linkify http links in brackets
3537
.replace(
3638
/(^|\s)\[(https?:\/\/[^\s\]]+)(?:\s+([^\]]+))?\]/g,
3739
function (_match, space, url, text) {
38-
return `${space}<a href="${url}" class="ext-link"><span class="icon"></span>${
40+
return `${
41+
space || ''
42+
}<a href="${url}" class="ext-link"><span class="icon"></span>${
3943
text || url
4044
}</a>`
4145
}
@@ -44,7 +48,9 @@ module.exports = function tracToHTML(text) {
4448
.replace(
4549
/(^|\s)\[(#[^\s\]]+)(?:\s+([^\]]+))?\]/g,
4650
function (_match, space, url, text) {
47-
return `${space}<a href="${url}" class="ext-link"><span class="icon"></span>${
51+
return `${
52+
space || ''
53+
}<a href="${url}" class="ext-link"><span class="icon"></span>${
4854
text || url
4955
}</a>`
5056
}
@@ -53,14 +59,14 @@ module.exports = function tracToHTML(text) {
5359
.replace(
5460
/(^|\s)\[([A-Z][a-z]+[A-Z][\w#-]+)(?:\s+([^\]]+))?\]/g,
5561
function (_match, space, page, text) {
56-
return `${space}<a href="/wiki/${page}">${text || page}</a>`
62+
return `${space || ''}<a href="/wiki/${page}">${text || page}</a>`
5763
}
5864
)
5965
// Linkify trac links
6066
.replace(
6167
/(^|\s)(?:\[trac:([^ ]+) "([^"]+)"\])|(?:\[trac:([^\s\]]+)(?: ([^\]]+))?\])/g,
6268
function (_match, space, quotepage, quotedtext, page, text) {
63-
return `${space}<a href="https://trac.edgewall.org/intertrac/${
69+
return `${space || ''}<a href="https://trac.edgewall.org/intertrac/${
6470
quotepage || page
6571
}" class="ext-link"><span class="icon"></span>${
6672
quotedtext || text || page
@@ -74,9 +80,9 @@ module.exports = function tracToHTML(text) {
7480
/(^|\s)(!)?([A-Z][a-z]+[A-Z]\w+(?:#\w+)?)(?!\w)/g,
7581
function (_match, space, excl, page) {
7682
if (excl) {
77-
return `${space}${page}`
83+
return `${space || ''}${page}`
7884
}
79-
return `${space}<a href="/wiki/${page}">${page}</a>`
85+
return `${space || ''}<a href="/wiki/${page}">${page}</a>`
8086
}
8187
)
8288
// Convert ---- to <hr>

0 commit comments

Comments
 (0)