Module:Wikitext

.mw-parser-output .ombox{margin:4px 0;border-collapse:collapse;border:1px solid #a2a9b1;background-color:var(--background-color-neutral-subtle,#f8f9fa);box-sizi…

Module:Wikitext

Usage


--require "mw.text"
--require "string"
--require "table"

local z = {}

-- This splits a string of name="value" pairs into a table.
-- The common use of this is to parse a single template argument that specifies HTML element attributes all in one lump.
function z.SplitHTMLElementParams(s)
    local params = {}
    for name,value in string.gmatch(s, "([%w_]+)=\"([^\"]*)\"%s*") do
        params[name] = value
    end
    return params
end

-- This returns a string quoted using quotation marks, using HTML character entities for embedded quotation marks and ampersands.
function z.quote(t)
    local chars = {}
    for i=1,#t do
        local char = t:sub(i,i)
        local byte = char:byte()
        if ( byte == 34 or byte == 38 ) then
            table.insert(chars, "&#" .. tostring(byte) .. ";")
        else
            table.insert(chars, char)
        end
    end
    return "\"" .. table.concat(chars) .. "\""
end

function z.CombineHTMLElementParams(params)
    local attrs = {}
    for n,v in pairs(params) do
        table.insert(attrs, n .. "=" .. z.quote(v))
    end
    return table.concat(attrs, " ")
end

function RawOpenHTMLTag(name,params)
    local attr = z.CombineHTMLElementParams(params)
    return "<" .. name .. " " .. attr .. ">"
end

function z.OpenHTMLTag(t)
    local name = t.name or "!-- --"
    if ( "nowiki" == name or "ref" == name or "pre" == name or "gallery" == name or "poem" == name or "references" == name ) then
        error(name .. ": OpenHTMLTag is for non-extension tags only.")
    end
    return RawOpenHTMLTag(name,t.params)
end

-- This returns the canonical form of an editor-supplied time, for use in cleanup category names.
function z.canonicalcleanuptime(t)
    return t -- FIXME: This isn't right.
end

-- This returns a list formatted into a (intended to be human-readable) comma-separated form.
function z.oxfordlist(args,separator,ampersand)
    local text = ""
    separator = separator or ","
    ampersand = ampersand or "and"
    for index,arg in ipairs(args) do
        if (index < 2) then 
            -- Add nothing before the first item.
        elseif (args[index + 1] ~= nil) then
            text = text .. separator .. " " 
        elseif (index > 2) then 
            text = text .. separator .. " " .. ampersand .. " "
        else
            text = text .. " " .. ampersand .. " "
        end
        text = text .. arg
    end
    return text
end

-- These return various CSS strings.
function z.columncountstyle(n)
    return "-moz-column-count:" .. n .. "; -webkit-column-count:" .. n .. "; column-count:" .. n .. ";"
end
function z.columnwidthstyle(n)
    return "-moz-column-width:" .. n .. "; -webkit-column-width:" .. n .. "; column-width:" .. n .. ";"
end
function z.liststyle(n)
    return "list-style-type:" .. n .. ";"
end

return z


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.