| ... | ... | @@ -2762,7 +2762,7 @@ const NAV_MODES = { |
| 2762 | 2762 | if (container.src != null) { |
| 2763 | 2763 | let docs = getAstNode(container.src).docs; |
| 2764 | 2764 | if (docs != null) { |
| 2765 | | domTldDocs.innerHTML = markdown(docs); |
| 2765 | domTldDocs.innerHTML = markdown(docs, container); |
| 2766 | 2766 | domTldDocs.classList.remove("hidden"); |
| 2767 | 2767 | } |
| 2768 | 2768 | } |
| ... | ... | @@ -2845,13 +2845,13 @@ const NAV_MODES = { |
| 2845 | 2845 | docs = docs.trim(); |
| 2846 | 2846 | var short = shortDesc(docs); |
| 2847 | 2847 | if (short != docs) { |
| 2848 | | short = markdown(short); |
| 2849 | | var long = markdown(docs); |
| 2848 | short = markdown(short, container); |
| 2849 | var long = markdown(docs, container); // TODO: this needs to be the file top lvl struct |
| 2850 | 2850 | tdDesc.innerHTML = |
| 2851 | 2851 | "<div class=\"expand\" ><span class=\"button\" onclick=\"toggleExpand(event)\"></span><div class=\"sum-less\">" + short + "</div>" + "<div class=\"sum-more\">" + long + "</div></details>"; |
| 2852 | 2852 | } |
| 2853 | 2853 | else { |
| 2854 | | tdDesc.innerHTML = markdown(short); |
| 2854 | tdDesc.innerHTML = markdown(short, container); |
| 2855 | 2855 | } |
| 2856 | 2856 | } else { |
| 2857 | 2857 | tdDesc.innerHTML = "<p><i>No documentation provided.</i><p>"; |
| ... | ... | @@ -3389,7 +3389,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3389 | 3389 | return markdown(shortDesc(docs)); |
| 3390 | 3390 | } |
| 3391 | 3391 | |
| 3392 | | function markdown(input) { |
| 3392 | function markdown(input, contextType) { |
| 3393 | 3393 | const raw_lines = input.split("\n"); // zig allows no '\r', so we don't need to split on CR |
| 3394 | 3394 | |
| 3395 | 3395 | const lines = []; |
| ... | ... | @@ -3474,7 +3474,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3474 | 3474 | // Render HTML from markdown lines. |
| 3475 | 3475 | // Look at each line and emit fitting HTML code |
| 3476 | 3476 | |
| 3477 | | function markdownInlines(innerText) { |
| 3477 | function markdownInlines(innerText, contextType) { |
| 3478 | 3478 | // inline types: |
| 3479 | 3479 | // **{INLINE}** : <strong> |
| 3480 | 3480 | // __{INLINE}__ : <u> |
| ... | ... | @@ -3521,6 +3521,10 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3521 | 3521 | let codetag = ""; |
| 3522 | 3522 | let in_code = false; |
| 3523 | 3523 | |
| 3524 | // state used to link decl references |
| 3525 | let quote_start = undefined; |
| 3526 | let quote_start_html = undefined; |
| 3527 | |
| 3524 | 3528 | for (let i = 0; i < innerText.length; i++) { |
| 3525 | 3529 | if (parsing_code && in_code) { |
| 3526 | 3530 | if (innerText.substr(i, codetag.length) == codetag) { |
| ... | ... | @@ -3537,6 +3541,16 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3537 | 3541 | parsing_code = false; |
| 3538 | 3542 | innerHTML += "</code>"; |
| 3539 | 3543 | codetag = ""; |
| 3544 | |
| 3545 | // find out if this is a decl that should be linked |
| 3546 | const maybe_decl_path = innerText.substr(quote_start, i-quote_start); |
| 3547 | const decl_hash = detectDeclPath(maybe_decl_path, contextType); |
| 3548 | if (decl_hash) { |
| 3549 | const anchor_opening_tag = "<a href='"+ decl_hash +"'>"; |
| 3550 | innerHTML = innerHTML.slice(0, quote_start_html) |
| 3551 | + anchor_opening_tag |
| 3552 | + innerHTML.slice(quote_start_html) + "</a>"; |
| 3553 | } |
| 3540 | 3554 | } else { |
| 3541 | 3555 | currentRun += innerText[i]; |
| 3542 | 3556 | } |
| ... | ... | @@ -3546,6 +3560,8 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3546 | 3560 | if (innerText[i] == "`") { |
| 3547 | 3561 | flushRun(); |
| 3548 | 3562 | if (!parsing_code) { |
| 3563 | quote_start = i + 1; |
| 3564 | quote_start_html = innerHTML.length; |
| 3549 | 3565 | innerHTML += "<code>"; |
| 3550 | 3566 | } |
| 3551 | 3567 | parsing_code = true; |
| ... | ... | @@ -3600,6 +3616,44 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3600 | 3616 | return innerHTML; |
| 3601 | 3617 | } |
| 3602 | 3618 | |
| 3619 | function detectDeclPath(text, context) { |
| 3620 | let result = ""; |
| 3621 | let separator = ":"; |
| 3622 | const components = text.split("."); |
| 3623 | let curDeclOrType = undefined; |
| 3624 | |
| 3625 | if (context) { |
| 3626 | curDeclOrType = findSubDecl(context, components[0]); |
| 3627 | if (curDeclOrType) { |
| 3628 | separator = '.'; |
| 3629 | result = location.hash + separator + components[0]; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | if (!curDeclOrType) { |
| 3634 | for (let i = 0; i < zigAnalysis.packages.length; i += 1){ |
| 3635 | const p = zigAnalysis.packages[i]; |
| 3636 | if (p.name == components[0]) { |
| 3637 | curDeclOrType = getType(p.main); |
| 3638 | result += "#A;" + components[0]; |
| 3639 | break; |
| 3640 | } |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | if (!curDeclOrType) return null; |
| 3645 | |
| 3646 | for (let i = 1; i < components.length; i += 1) { |
| 3647 | curDeclOrType = findSubDecl(curDeclOrType, components[i]); |
| 3648 | if (!curDeclOrType) return null; |
| 3649 | result += separator + components[i]; |
| 3650 | separator = '.'; |
| 3651 | } |
| 3652 | |
| 3653 | return result; |
| 3654 | |
| 3655 | } |
| 3656 | |
| 3603 | 3657 | function previousLineIs(type, line_no) { |
| 3604 | 3658 | if (line_no > 0) { |
| 3605 | 3659 | return lines[line_no - 1].type == type; |
| ... | ... | @@ -3647,7 +3701,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3647 | 3701 | "<" + |
| 3648 | 3702 | line.type + |
| 3649 | 3703 | ">" + |
| 3650 | | markdownInlines(line.text) + |
| 3704 | markdownInlines(line.text, contextType) + |
| 3651 | 3705 | "</" + |
| 3652 | 3706 | line.type + |
| 3653 | 3707 | ">\n"; |
| ... | ... | @@ -3662,7 +3716,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3662 | 3716 | html += "<" + line.type + ">\n"; |
| 3663 | 3717 | } |
| 3664 | 3718 | |
| 3665 | | html += "<li>" + markdownInlines(line.text) + "</li>\n"; |
| 3719 | html += "<li>" + markdownInlines(line.text, contextType) + "</li>\n"; |
| 3666 | 3720 | |
| 3667 | 3721 | if ( |
| 3668 | 3722 | !nextLineIs(line.type, line_no) || |
| ... | ... | @@ -3676,7 +3730,7 @@ function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) { |
| 3676 | 3730 | if (!previousLineIs("p", line_no)) { |
| 3677 | 3731 | html += "<p>\n"; |
| 3678 | 3732 | } |
| 3679 | | html += markdownInlines(line.text) + "\n"; |
| 3733 | html += markdownInlines(line.text, contextType) + "\n"; |
| 3680 | 3734 | if (!nextLineIs("p", line_no)) { |
| 3681 | 3735 | html += "</p>\n"; |
| 3682 | 3736 | } |