From 7e012d364a67549b4820f40a4b928c71f05d02f7 Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Mon, 14 Jun 2021 12:14:46 +0200 Subject: [PATCH] show anchor name in display text --- build.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/build.js b/build.js index 74cfd433..91c1fa6f 100644 --- a/build.js +++ b/build.js @@ -63,7 +63,7 @@ function convert(content, file) { } // convert wiki links - // [[href#anchor|title] -> [title](href#anchor) + // [[href#anchor|title] -> [title > anchor](href#anchor) matches = content.match(wikiLink) || [] for (i = 0; i < matches.length; i++) { let match = matches[i] @@ -72,19 +72,23 @@ function convert(content, file) { let title = match.match(/\[\[([^\]|#]*)/)[1] let anchor = null - // set anchor - if (match.indexOf('#') > 0) { - anchor = match.match(/#([^\||\]]*)/)[1] - // sanitize anchor link - anchor = sanitizeName(anchor) - } - // set title and href if (match.indexOf('|') > 0) { href = match.match(/\[\[([^\||#]*)/)[1] title = match.match(/\|(.*)\]\]/)[1] } + // set anchor + if (match.indexOf('#') > 0) { + anchor = match.match(/#([^\||\]]*)/)[1] + + // combine title and href text + title = `${title} > ${anchor}` + + // sanitize anchor link + anchor = sanitizeName(anchor) + } + // sanitize href href = sanitizeName(href ? href : file.replace('\.md', ''))