
Crossref.pudu
Pudu32 lines1.5 KB
1/** @Docgen.Markdown.Crossref — cross references with display options read from their written forms */2module PuduLangDocgen.Markdown.Crossref34import PuduLangDocgen.Markdown.Lexicon as Lexicon5import PuduLangDocgen.Markdown.Syntax as Syntax6789export fn span(written: Str, children: Array[Syntax.Inline], line: Int, optional: Bool) -> Syntax.Inline {10 let parts = written.split("?")11 var display = "name"12 var text = children13 if parts.length() > 1 {14 for option in parts[1].split("&") {15 let pair = option.split("=")16 if pair.length() == 2 && pair[0] == "displayProperty" { display = pair[1] }17 if pair.length() == 2 && pair[0] == "text" && text.isEmpty() { text = [Syntax.Text(pair[1].replace("+", " ").replace("%20", " "))] }18 }19 }20 Syntax.Xref(Syntax.XrefSpan{uid: parts[0].replace("%2A", "*").replace("%60", "`"), text: text, display: display, line: line, optional: optional})21}222324export fn element(inner: Str, line: Int) -> Option[Syntax.Inline] {25 let uid = Lexicon.attribute(inner, "uid")26 if uid.isEmpty() { return None }27 let text = Lexicon.attribute(inner, "text")28 let display = Lexicon.attribute(inner, "displayProperty")29 let children: Array[Syntax.Inline] = if text.isEmpty() { [] } else { [Syntax.Text(text)] }30 Some(Syntax.Xref(Syntax.XrefSpan{uid: uid, text: children, display: if display.isEmpty() { "name" } else { display }, line: line, optional: false}))31}32