|
| 1 | +import snarkdown from 'snarkdown'; |
| 2 | + |
1 | 3 | const PVJS_URL = 'https://cdn.jsdelivr.net/npm/@wikipathways/[email protected]/dist/pvjs.vanilla.js'; |
2 | 4 | const SVGPANZOOM_URL = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/svg-pan-zoom.min.js'; |
3 | 5 | const CONTAINER_ID = '_ideogramPathwayContainer'; |
@@ -163,21 +165,24 @@ function removeCptacAssayPortalClause(inputText) { |
163 | 165 | return inputText.replace(regex, '').replace(regex2, ''); |
164 | 166 | } |
165 | 167 |
|
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); |
169 | 171 |
|
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; |
174 | 179 | } |
175 | 180 |
|
176 | 181 | function formatDescription(rawText) { |
177 | 182 | rawText = rawText.replaceAll('\r\n\r\n', '\r\n'); |
178 | 183 | rawText = rawText.replaceAll('\r\n', '<br/><br/>'); |
179 | 184 | const denoisedText = removeCptacAssayPortalClause(rawText); |
180 | | - const linkedText = convertMediaWikiLinks(denoisedText); |
| 185 | + const linkedText = convertMarkdownLinks(denoisedText); |
181 | 186 | const trimmedText = linkedText.trim(); |
182 | 187 | return trimmedText; |
183 | 188 | } |
|
0 commit comments