Skip to content

Commit aa51e31

Browse files
committed
Convert Markdown rather than MediaWiki
1 parent 1404f3b commit aa51e31

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"fast-kde": "0.2.1",
5555
"fflate": "^0.7.3",
5656
"tippy.js": "6.3.7",
57-
"workbox-range-requests": "7.0.0"
57+
"workbox-range-requests": "7.0.0",
58+
"snarkdown": "^2.0.0"
5859
},
5960
"devDependencies": {
6061
"@babel/core": "^7.16.0",

src/js/kit/pathway-viewer.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import snarkdown from 'snarkdown';
2+
13
const PVJS_URL = 'https://cdn.jsdelivr.net/npm/@wikipathways/[email protected]/dist/pvjs.vanilla.js';
24
const SVGPANZOOM_URL = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg-pan-zoom.min.js';
35
const CONTAINER_ID = '_ideogramPathwayContainer';
@@ -163,21 +165,24 @@ function removeCptacAssayPortalClause(inputText) {
163165
return inputText.replace(regex, '').replace(regex2, '');
164166
}
165167

166-
function convertMediaWikiLinks(inputText) {
167-
// Regular expression to match the MediaWiki link format
168-
const regex = /\[([^\s]+)\s+([^\]]+)\]/g;
168+
/** Convert Markdown links to standard <a href="... links */
169+
function convertMarkdownLinks(markdown) {
170+
const html = snarkdown(markdown);
169171

170-
// Replace the MediaWiki link format with an HTML anchor tag
171-
return inputText.replace(regex, (match, url, text) => {
172-
return `<a href="${url}">${text}</a>`;
173-
});
172+
const htmlWithClassedLinks =
173+
html.replace(
174+
/<a href="([^"]+)">/g,
175+
'<a href="$1" class="_ideoPathwayDescriptionLink">'
176+
);
177+
178+
return htmlWithClassedLinks;
174179
}
175180

176181
function formatDescription(rawText) {
177182
rawText = rawText.replaceAll('\r\n\r\n', '\r\n');
178183
rawText = rawText.replaceAll('\r\n', '<br/><br/>');
179184
const denoisedText = removeCptacAssayPortalClause(rawText);
180-
const linkedText = convertMediaWikiLinks(denoisedText);
185+
const linkedText = convertMarkdownLinks(denoisedText);
181186
const trimmedText = linkedText.trim();
182187
return trimmedText;
183188
}

0 commit comments

Comments
 (0)