Module:Transcript
Documentation for this module may be created at Module:Transcript/doc
--<pre>
--| Creates a simple transcript or dialogue
--| Ref https://www.w3.org/TR/html5/common-idioms.html#conversations
-- Syntax :
-- {{#invoke:transcript|main|john|I'm rich|Mary|Me too}}
-- {{#invoke:transcript|main|john:I'm rich|Mary:Me too|#separator=:}}
local p = {}
local strfind = string.find
local strsub = string.sub
--% Main function for users for invoke, entry point
--@ frame (table) A frame object containing the dialogue in the appropriate format
--: (string) Text containing the dialogue
function p.main(frame)
local args = require("Dev:Arguments").getArgs(frame)
local separator = args["#separator"]
return dialogue(args, separator)
end
--% Creates dialogue using template arguments
--@ args (table) A table containing template arguments with dialogue
--@ separator (string) A separator for each quote
--: (string) Text containing the dialogue
function dialogue(args, separator)
local htmlTranscript = mw.html.create("dl")
local text,pos,author, quote = "","","",""
local count = 1
htmlTranscript:addClass("transcript_dialogue")
if separator then
for id,dialogue in ipairs(args) do
if dialogue and dialogue:len() > 0 then
pos = strfind(dialogue, separator)
author = strsub (dialogue, 1, pos-1)
quote = strsub (dialogue, pos+1)
htmlTranscript:tag("dt")
:addClass("transcript_author")
:wikitext(author)
htmlTranscript:tag("dd")
:addClass("transcript_quote")
:wikitext(quote)
end
end
else
while args[count] do
text = args[count]
if count % 2 == 0 then
htmlTranscript:tag("dd")
:addClass("transcript_quote")
:wikitext(text)
else
htmlTranscript:tag("dt")
:addClass("transcript_author")
:wikitext(text)
end
count = count + 1
end
end
return htmlTranscript
end
return p