Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-docgen

Documentation publishing for Pudu: articles, API references, navigation, search, and static websites

0.1.0Apache-2.01

InstallClose

Crossref.pudu

Pudu32 lines1.5 KB

GitHub ↗
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 Syntax67/// A cross reference written as `uid?displayProperty=fullName&text=Label`; given link text8/// wins over the `text` option.9export 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}2223/// The `<xref uid="..." />` element form, read from the text between its angle brackets.24export 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