Module:User:Benwing2/references

local export = {}

local rsplit = mw.text.split

-- Parse a references spec as used in the |ref= param to and  and soon the |fNref= param to. -- Multiple references are separated by !!! (optionally with spaces around it), and the equivalent of -- can be specified using a syntax like the following: -- -- To include a group as in, use: -- -- To reference a prior name, as in, leave the reference text blank: -- -- Similarly, to reference a prior name in a particular group, as in, use: -- function export.parse_references(text) local refs = {} local raw_notes = rsplit(text, "%s*!!!%s*") for _, raw_note in ipairs(raw_notes) do		local note if raw_note:find("<<") then local splitvals = require("Module:string utilities").capturing_split(raw_note, "(<<[a-z]+:.->>)") note = {text = splitvals[1]} for i = 2, #splitvals, 2 do				local key, value = splitvals[i]:match("^<<([a-z]+):(.*)>>$") if not key then error("Internal error: Can't parse " .. splitvals[i]) end if key == "name" or key == "group" then note[key] = value else error("Unrecognized key '" .. key .. "' in " .. splitvals[i]) end if splitvals[i + 1] ~= "" then error("Extraneous text '" .. splitvals[i + 1] .. "' after " .. splitvals[i]) end end else note = raw_note end table.insert(refs, note) end return refs end

return export