autodoc: allow function descriptions expansion

This commit is contained in:
Clement Espeute 2023-01-10 14:00:11 +01:00 committed by Valden
parent f7ade7e63b
commit b63a771e18
2 changed files with 61 additions and 4 deletions

View File

@ -266,6 +266,42 @@
font-weight: bold;
}
details[open] summary .sum-less {
display: none;
}
details[open] summary .sum-more {
display: block;
}
details summary .sum-more {
display: none;
}
details summary {
list-style-type: none;
position: relative;
pointer-events: none;
}
details summary::before {
content: "[+] ";
font-family: var(--mono);
color: var(--link-color);
position: sticky;
float: left;
top: 0px;
right: -16px;
z-index: 1;
margin-left: -2em;
pointer-events: all;
cursor: pointer;
}
details[open] summary::before {
content: "[-] ";
}
.examples {
list-style-type: none;
margin: 0;

View File

@ -2466,9 +2466,19 @@ var zigAnalysis;
let docs = getAstNode(decl.src).docs;
if (docs != null) {
tdDesc.innerHTML = shortDescMarkdown(docs);
docs = docs.trim();
var short = shortDesc(docs);
if (short != docs) {
short = markdown(short);
var long = markdown(docs);
tdDesc.innerHTML =
"<details><summary><div class=\"sum-less\">" + short + "</div>" + "<div class=\"sum-more\">" + long + "</div></summary></details>";
}
else {
tdDesc.innerHTML = markdown(short);
}
} else {
tdDesc.textContent = "";
tdDesc.innerHTML = "<p><i>No documentation provided.</i><p>";
}
}
domSectFns.classList.remove("hidden");
@ -2897,7 +2907,7 @@ var zigAnalysis;
});
}
function shortDescMarkdown(docs) {
function shortDesc(docs){
const trimmed_docs = docs.trim();
let index = trimmed_docs.indexOf("\n\n");
let cut = false;
@ -2913,7 +2923,11 @@ var zigAnalysis;
let slice = trimmed_docs.slice(0, index);
if (cut) slice += "...";
return markdown(slice);
return slice;
}
function shortDescMarkdown(docs) {
return markdown(shortDesc(docs));
}
function markdown(input) {
@ -3110,6 +3124,13 @@ var zigAnalysis;
}
flushRun();
if (in_code) {
in_code = false;
parsing_code = false;
innerHTML += "</code>";
codetag = "";
}
while (stack.length > 0) {
const fmt = stack.pop();
innerHTML += "</" + fmt.tag + ">";