authorgravatar for strangebug@ineedtojet.comStrangeBug <strangebug@ineedtojet.com> 2020-05-05 18:09:32+02:00
committergravatar for strangebug@ineedtojet.comStrangeBug <strangebug@ineedtojet.com> 2020-05-05 18:09:32+02:00
log54088fe6e11f193590e22a12da2cc95be38129d8
tree7f3a9b702b1aef8442192f9b1c09f25ffc7f2a93
parente6955688ac2255d3813e8d2994b6661bc651369b

Add support for external links and URL to markdown parser.


1 files changed, 39 insertions(+), 0 deletions(-)

lib/std/special/docs/main.js+39
......@@ -1498,6 +1498,22 @@
14981498 }
14991499 ];
15001500
1501 // Links, images and inner links don't use the same marker to wrap their content.
1502 const linksFormat = [
1503 {
1504 prefix: "[",
1505 regex: /\[([^\]]*)\]\(([^\)]*)\)/,
1506 urlIndex: 2, // Index in the match that contains the link URL
1507 textIndex: 1 // Index in the match that contains the link text
1508 },
1509 {
1510 prefix: "h",
1511 regex: /http[s]?:\/\/[^\s]+/,
1512 urlIndex: 0,
1513 textIndex: 0
1514 }
1515 ];
1516
15011517 const stack = [];
15021518
15031519 var innerHTML = "";
......@@ -1548,6 +1564,29 @@
15481564 currentRun += innerText[i];
15491565 in_code = true;
15501566 } else {
1567 var foundMatches = false;
1568
1569 for (var j = 0; j < linksFormat.length; j++) {
1570 const linkFmt = linksFormat[j];
1571
1572 if (linkFmt.prefix == innerText[i]) {
1573 var remaining = innerText.substring(i);
1574 var matches = remaining.match(linkFmt.regex);
1575
1576 if (matches) {
1577 flushRun();
1578 innerHTML += ' <a href="' + matches[linkFmt.urlIndex] + '">' + matches[linkFmt.textIndex] + '</a> ';
1579 i += matches[0].length; // Skip the fragment we just consumed
1580 foundMatches = true;
1581 break;
1582 }
1583 }
1584 }
1585
1586 if (foundMatches) {
1587 continue;
1588 }
1589
15511590 var any = false;
15521591 for (var idx = (stack.length > 0 ? -1 : 0); idx < formats.length; idx++) {
15531592 const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1];