Jump to content

Editing Module:Quote

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 7: Line 7:


-- =========================================================
-- =========================================================
-- Parameters
-- Helpers
-- =========================================================
-- =========================================================


Line 22: Line 22:


     return nil
     return nil
end
local function paragraph(text)
    return '\n' .. text .. '\n'
end
end


Line 29: Line 34:
-- =========================================================
-- =========================================================


local function getOptions(args)
local function parseOptions(args)
 
     local options = {
     local options = {
         classes = {},
         classes = {},
Line 47: Line 51:
         options.extraStyles = extraStyles
         options.extraStyles = extraStyles
     end
     end
    -- Alignment


     local align = parameter(args, 'align')
     local align = parameter(args, 'align')
Line 57: Line 58:


         if align == 'left' or align == 'right' then
         if align == 'left' or align == 'right' then
             options.classes[#options.classes + 1] =
            options.align = align
                'pp-quote--' .. align
             options.classes[#options.classes + 1] = 'pp-quote--' .. align


             local width =
             local width = parameter(args, 'width', 'quotewidth')
                parameter(args, 'width', 'quotewidth')


             if width then
             if width then
                 options.styles.width = width
                 options.styles['width'] = width
             end
             end
         end
         end
Line 74: Line 74:


-- =========================================================
-- =========================================================
-- Build quote
-- Quote builder
-- =========================================================
-- =========================================================


local function build(quoteContents, quoteSource, options)
local function build(quoteContents, quoteSource, options)


     local quote = mw.html.create('blockquote')
     local quote = mw.html.create('div')
         :addClass('pp-quote')
         :addClass('pp-quote')


     -- Alignment classes
     -- Alignment
     for _, className in ipairs(options.classes) do
     for _, className in ipairs(options.classes) do
         quote:addClass(className)
         quote:addClass(className)
     end
     end


     -- Extra classes
     -- User-supplied classes
     if options.extraClasses then
     if options.extraClasses then
         quote:addClass(options.extraClasses)
         quote:addClass(options.extraClasses)
     end
     end


     -- Explicit styles
     -- User-supplied styles
     for property, value in pairs(options.styles) do
     for property, value in pairs(options.styles) do
         quote:css(property, value)
         quote:css(property, value)
Line 101: Line 101:
     end
     end


     -- Quote content
     -- Quote text
     quote:node(quoteContents)
     quote:node(quoteContents)


Line 124: Line 124:


     local args = getArgs(frame)
     local args = getArgs(frame)
     local options = getOptions(args)
     local options = parseOptions(args)


     local quoteText =
     local quoteText =
Line 133: Line 133:
     local person =
     local person =
         args[2]
         args[2]
         or parameter(
         or parameter(args, 'person', 'speaker', 'personquoted')
            args,
            'person',
            'speaker',
            'personquoted'
        )


     local source =
     local source =
         args[3]
         args[3]
         or parameter(
         or parameter(args, 'source', 'quote_source')
            args,
            'source',
            'quote_source'
        )
 


     -- Quote text
     -- Quote text container
     local quoteContents = mw.html.create('div')
     local quoteContents = mw.html.create('div')
         :addClass('pp-quote__text')
         :addClass('pp-quote__text')
         :wikitext(quoteText)
         :wikitext(quoteText)


 
     -- Build source
     -- Source
     local quoteSource
     local quoteSource


Line 165: Line 154:
         quoteSource = source
         quoteSource = source
     end
     end


     return build(
     return build(
Line 182: Line 170:


     local args = getArgs(frame)
     local args = getArgs(frame)
     local options = getOptions(args)
     local options = parseOptions(args)


     local quoteContents = mw.html.create('div')
     local quoteContents = mw.html.create('div')
         :addClass('pp-quote__text')
         :addClass('pp-quote__text')
         :addClass('pp-quote__text--dialogue')
         :addClass('pp-quote__text--dialogue')


     -- Dialogue lines
     -- Dialogue lines
Line 196: Line 183:


         if speaker and line then
         if speaker and line then
             quoteContents
             quoteContents
                 :tag('div')
                 :tag('div')
Line 206: Line 192:
                         :done()
                         :done()


                     :wikitext(' ' .. line)
                     :wikitext(' ' .. paragraph(line))


                     :done()
                     :done()
         end
         end
     end
     end


     -- Dialogue source
     -- Dialogue source
     local context =
     local context = parameter(args, 'context')
        parameter(args, 'context')
     local source = parameter(args, 'source')
 
     local source =
        parameter(args, 'source')


     local quoteSource
     local quoteSource
Line 229: Line 211:
         quoteSource = source
         quoteSource = source
     end
     end


     return build(
     return build(
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;