Module:Quote
Jump to navigation
Jump to search
This is the main module for the following templates:
local p = {}
local utilsArg = require("Module:UtilsArg")
local utilsString = require("Module:UtilsString")
function p.Main(frame)
local args, err = utilsArg.parse(frame:getParent().args, p.Templates.Quote)
local categories = err and err.categoryText or ""
local quote, source = args.quote, args.source
local html = mw.html.create("div")
if quote:find("\n") or quote:find("<br") or quote:find("<p") then
html:addClass("quote quote--multiline")
:tag("div")
:addClass("quote__text")
:wikitext(p.multiLine(quote))
else
html:addClass("quote quote--singleline")
:tag("div")
:addClass("quote__container")
:tag("div")
:addClass("quote__quote-mark quote__quote-mark--open")
:wikitext("“")
:done()
:tag("div")
:addClass("quote__text")
:wikitext(quote)
:done()
:tag("div")
:addClass("quote__quote-mark quote__quote-mark--close")
:wikitext("”")
:done()
end
if utilsString.notBlank(source) then
html:tag("div")
:addClass("quote__source")
:wikitext(" — "..source)
end
return tostring(html), categories
end
function p.multiLine(quote)
quote = utilsString.trim(quote, "\n") -- trim leading and trailing lines
quote = mw.getCurrentFrame():extensionTag("poem", quote)
quote = '<blockquote class="quote quote--multiline">'..quote..'</blockquote>'
return quote
end
p.Templates = {
Quote = {
purpose = "This template is used to display a quotation. For transcripts of in-game books, use [[Template:Transcript]] instead.",
params = {
[1] = {
name = "quote",
required = true,
type = "content",
desc = "Quotation text.",
},
[2] = {
name = "source",
required = true,
type = "content",
desc = "The source of the quote.",
},
},
},
}
return p