Skip to content

Commit 22ec00a

Browse files
committed
Fix link matching
1 parent a3f7fc2 commit 22ec00a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

main.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,21 +343,40 @@ let tags = {
343343
'<li>': '- ',
344344
'</li>': '',
345345
'<ul>': '',
346-
'</ul>': '',
346+
'</ul>': '\n',
347347
'&nbsp;': ' ',
348348
}
349349

350350
function parseTags(input) {
351351
let output = input;
352352
for (const [key, value] of Object.entries(tags)) {
353-
output = output.replace(key, value);
353+
output = output.replaceAll(key, value);
354354
}
355355

356-
// Fix links
357-
output = output.replace(/<a href="([^"]+)">([^<]+)<\/a>/g, '[$2]($1)');
356+
// Fix Links
357+
const linkRegex = /<a href="([^"]+)">([^<]+)<\/a>/g;
358+
let match;
359+
match = linkRegex.exec(output);
360+
while (match != null) {
361+
output = output.replace(match[0], `[${match[2]}](${match[1]})`);
362+
match = linkRegex.exec(output);
363+
}
364+
365+
// Fix Links target black
366+
const linkTargetRegex = /<a href="([^"]+)" target="_blank">([^<]+)<\/a>/g;
367+
match = linkTargetRegex.exec(output);
368+
while (match != null) {
369+
output = output.replace(match[0], `[${match[2]}](${match[1]})`);
370+
match = linkTargetRegex.exec(output);
371+
}
358372

359373
// Fix font color
360-
output = output.replace(/<font color="([^"]+)">([^<]+)<\/font>/g, '$2');
374+
const fontRegex = /<font color="([^"]+)">([^<]+)<\/font>/g;
375+
match = fontRegex.exec(output);
376+
while (match != null) {
377+
output = output.replace(match[0], match[2]);
378+
match = fontRegex.exec(output);
379+
}
361380

362381
return output;
363382
}

0 commit comments

Comments
 (0)