Die Dokumentation für dieses Modul kann unter Modul:Vorlage:Vers/Doku erstellt werden

-- Export
local p = { }

function p.uc_html(c)
  return "&#x" .. mw.ustring.format("%04x;", mw.ustring.codepoint(c))
end

function p.special_escape(c)
  r, n = mw.ustring.gsub(c, "[a-zA-Z]", {
    ["a"] = "<small>&#x25CB;</small>"; -- äoilische Basis u. unbestimmte Silbe
    ["b"] = "&#x0306;"; -- Breve
    ["B"] = "&#x23DC;"; -- Brücke
    ["E"] = "<span style='font-size:xx-small;'>&#x2514;&#x2500;&#x2534;&#x2500;&#x2518;</span>"; -- 5 Mora
    ["f"] = "&#x02CC;"; -- Versfuß
    ["F"] = "<span style='font-size:xx-small;'>&#x2514;&#x2500;&#x2500;&#x2500;&#x2518;</span>"; -- 4 Mora = ganze Note
    ["G"] = "<span style='font-size:xx-small;'>&#x2514;&#x2500;&#x2500;&#x2574;</span>"; -- 3 Mora = 3/4 Note
    ["h"] = "&#x202f;&#x301;"; -- Haupthebung
    ["H"] = "<span style='font-size:xx-small;'>&#x2500;&#x2500;</span>"; -- 2 Mora = halbe Note
    ["i"] = "<span style='text-decoration:underline;'>&#x25E0;</span>"; -- Indifferenz
    ["I"] = "&#x25E0;<span style='line-height:100%;font-size:150%;'>&#x0323;</span>"; -- Indifferenz (alternativ)
    ["k"] = "<span style='line-height:100%;vertical-align:-40%;text-decoration:overline'><span style='vertical-align:45%;'>&#x25E1;</span></span>"; -- Kürze oder Länge
    ["l"] = "<span style='line-height:100%;vertical-align:30%;text-decoration:underline'><span style='vertical-align:25%;'>&#x25E1;</span></span>"; -- Länge oder Kürze
    ["m"] = "&#x0304;"; -- Macron
    ["M"] = "&#x035E;"; -- doppelter Macron
    ["n"] = "&#x202f;&#x300;"; -- Nebenhebung
    ["o"] = "<span style='vertical-align:-15%;font-size:small;'>(</span>&#x25E1;<span style='vertical-align:-15%;font-size:small;'>)</span>"; -- optionale kurze Silbe
    ["s"] = "&#x2AFD;"; -- Strophenende
    ["u"] = "&#x202f;"; -- unbetont (Platzhalter für Betonungszeichen)
    ["v"] = "&#x002F;"; -- Versende
    ["w"] = "&#x00A6;"; -- häufiges Wortende
    -- [""] = ""; --
  })
  if n ~= 0 then return r end
  return p.uc_html(c) 
end

function p.do_convert (str)
  str,_ = mw.ustring.gsub(str, "\\([^a-zA-Z])", p.uc_html) 
  str,_ = mw.ustring.gsub(str, "!!", "&#x2009;&#x2016;&#x2009;"); -- THIN SPACE + DOUBLE VERTICAL LINE + THIN SPACE
  str,_ = mw.ustring.gsub(str, ".", {
    ["/"] = "&#x2014;"; -- EM DASH
    ["-"] = "&#x25E1;"; -- LOWER HALF CIRCLE
    ["'"] = "&#x0301;"; -- COMBINING ACUTE ACCENT
    ["~"] = "&#x0300;"; -- COMBINING GRAVE ACCENT
    ["_"] = "&#x0331;"; -- COMBINING MACRON BELOW
    -- ["^"] = "&#x2227;"; -- LOGICAL AND
    ["\n"] = "<br/>\n"; -- Line break + new line
    ["!"] = "&#x2009;&#x007C;&#x2009;"; -- THIN SPACE + VERTICAL BAR + THIN SPACE
  })
  str,_ = mw.ustring.gsub(str, "%%", "&#x00D7;"); -- MULTIPLICATION SIGN
  str,_ = mw.ustring.gsub(str, "[§$+*]", {
    ["§"] = "<span style='line-height:100%;vertical-align:30%;text-decoration:underline'><span style='vertical-align:25%;'>&#x25E1;&#x25E1;</span></span>"; 
    ["$"] = "<span style='line-height:100%;vertical-align:-40%;text-decoration:overline'><span style='vertical-align:45%;'>&#x25E1;&#x25E1;</span></span>"; 
    ["+"] = "<span style='font-size:x-small;vertical-align:10%;'>&#x25E1;</span>"; 
    ["*"] = "<span style='font-size:x-small;vertical-align:-10%;'>&#x25E0;</span>"; 
  })
  str,_ = mw.ustring.gsub(str, "\\([a-zA-Z])", p.special_escape) 
  return str
end

function p.convert (frame)
  local str = frame.args[1]
  return p.do_convert(str)
end

return p