Module:RQ:pi:Sai Kam Mong

local export = {}; local gsub = string.gsub -- Can pretend it's all Latin-1! local trim = mw.text.trim -- Except for trimmming strings.

function export.quote(frame) -- Convert from string if decimal, and trim if not. local fa1 = frame.args[1] local pageno = tonumber(fa1) or fa1 and trim(fa1) if not pageno or pageno == "" then return "Invalid or missing page number" end local quotid = frame.args[2] if quotid then quotid = trim(quotid) if string.len(quotid) == 0 then quotid = nil end end if not quotid then return "Passage ID is missing" end local wordid = tonumber(frame.args[3]) or 0 local passages = frame.args["passages"] or 'RQ:pi:Sai Kam Mong/passages' passages = mw.loadData('Module:'..passages) local passage = passages[pageno] if passage then passage=passage[quotid] if passage then local highlight = function end local function consider_word(m1) if string.find(m1, "^{"..wordid.."%-") then return ""..m1.."" else return "{"..highlight(string.sub(m1, 2)) end end highlight = function(m2) return gsub(m2, "%b{}", consider_word) end local function process(line) if line then line = highlight(line) line = gsub(line, "{%d%d*-", "") line = gsub(line, "}", "") line = gsub(line, "", "") line = gsub(line, '⧁', " ") line = gsub(line, '⧀', " ") end return line end local text, tran, xlit, lit, norm, ts			text = process(passage[1]) tran = process(passage[2]) xlit = process(passage[3]) lit = process(passage.lit) norm = process(passage.norm) ts  = process(passage.ts) local reference = frame.args.reference or passages.reference return frame:expandTemplate{title = trim(reference), args = { pageno, text, tran, xlit, lang = passage.lang or passages[pageno].lang or passages.lang, p1 = passage.p1 or passages[pageno].p1 or passages.p1, p2 = passage.p2 or passages[pageno].p2 or passages.p2, brackets = frame.args.brackets, norm = norm, lit = lit, ts = ts				} } else return "No passage dubbed \"" .. quotid .. "\" on page " .. pageno end else return "There are no passages from page " .. pageno end end return export