authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-12 15:35:50+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-12 15:35:50+03:00
log08e2e690d75f9c91faf97e3281b95fa9a0aad47d
treedb787937786043a4b903b8e0dd27829297c45c28
parent29b3be4f2f30f756ef0317f79c349f5565b04d19
parent54088fe6e11f193590e22a12da2cc95be38129d8
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #5275 from strangebug/docs-markdown-links

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];