Difference between pages "Module:Autolink" and "Property:Traditional Chinese name"

From Yugipedia
(Difference between pages)
Jump to: navigation, search
(update from sandbox)
 
(Created page with "This Has type::text property lists the Traditional Chinese name of something. Category:Name properties")
 
Line 1: Line 1:
--
+
This [[Has type::text]] property lists the Traditional Chinese name of something.
-- implements {{Autolink}} and {{Unlink}}
 
--
 
  
local p = {}
+
[[Category:Name properties]]
 
 
function p.link( frame )
 
    local args = frame:getParent().args
 
    -- for testing from console
 
    -- local args = frame
 
    -- marker used for {{nolink}} support (doesn't have to be a zero-width non-joiner, that's just what was used in the template version)
 
    local zwnj = '‌'
 
    local links, listmarkup, el, link, text, formatl, formatr
 
 
 
    -- set default to stop errors
 
    args[1] = args[1] and mw.text.trim( args[1] ) or ''
 
 
 
    if mw.ustring.find( args[1], zwnj ) == 1 then
 
        links = mw.ustring.gsub( args[1], '%[%[[Cc]ategory:', '[[:Category:' )
 
        links = mw.ustring.gsub( links, '%[%[[Ff]ile:', '[[:File:' )
 
        links = mw.ustring.gsub( links, '%[%[[Ii]mage:', '[[:Image:' )
 
        return mw.ustring.gsub( links, zwnj, '' )
 
    else
 
        links = mw.text.split( args[1], '\n' )
 
 
 
        args[2] = #links == 1 and args[2]
 
 
 
        listmarkup = #links == 1 and ''
 
 
 
        for i=1, #links do
 
            el = mw.text.trim( links[i] )
 
 
 
            -- catch empty string at the start of lists
 
            if not mw.ustring.match( el, '^[*#;:]?$' ) then
 
                if listmarkup ~= '' then
 
                    listmarkup = mw.ustring.match( el, '^([*#;:])' ) or '*'
 
                    el = mw.ustring.gsub( el, '^[*#;:]%s*', '' )
 
                end
 
 
 
                if mw.ustring.find( el, zwnj ) or mw.ustring.find( el, '%[%[' ) then
 
                    links[i] = table.concat( { listmarkup, el }, '' )
 
                else
 
                    link = el
 
                    text = args[2] or el
 
                    formatl = ''
 
                    formatr = ''
 
 
 
                    link = mw.ustring.gsub( link, '""', '' )
 
                    link = mw.ustring.gsub( link, "'''?", '' )
 
 
 
                    -- check for formatting that can be moved out of the link entirely
 
                    if mw.ustring.find( text, '^""' ) and mw.ustring.find( text, '""$' ) then
 
                        formatl = '"'
 
                        formatr = '"'
 
                        text = mw.ustring.gsub( text, '""', '' )
 
                    else
 
                        text = mw.ustring.gsub( text, '""', '"' )
 
                    end
 
                    if mw.ustring.find( text, "^'''" ) and mw.ustring.find( text, "'''$" ) then
 
                        formatl = formatl .. "'''"
 
                        formatr = "'''" .. formatr
 
                        text = mw.ustring.gsub( text, "^'''", '' )
 
                        text = mw.ustring.gsub( text, "'''$", '' )
 
                    end
 
                    if mw.ustring.find( text, "^''" ) and mw.ustring.find( text, "''$" ) then
 
                        formatl = formatl .. "''"
 
                        formatr = "''" .. formatr
 
                        text = mw.ustring.gsub( text, "^''", '' )
 
                        text = mw.ustring.gsub( text, "''$", '' )
 
                    end
 
 
 
                    if link == text then
 
                        links[i] = table.concat( { listmarkup, formatl, '[[', link, ']]', formatr }, '' )
 
                    else
 
                        links[i] = table.concat( { listmarkup, formatl, '[[', link, '|', text, ']]', formatr }, '' )
 
                    end
 
                end
 
            end
 
        end
 
 
 
        links = table.concat( links, '\n' )
 
        links = mw.ustring.gsub( links, zwnj, '' )
 
        links = mw.ustring.gsub( links, '%[%[[Cc]ategory:', '[[:Category:' )
 
        links = mw.ustring.gsub( links, '%[%[[Ff]ile:', '[[:File:' )
 
        links = mw.ustring.gsub( links, '%[%[[Ii]mage:', '[[:Image:' )
 
        links = mw.text.trim( links )
 
        return links
 
    end
 
end
 
 
 
function p.unlink( frame )
 
    local args = frame:getParent().args
 
    return args[1] and ( mw.ustring.match( args[1], '%[%[:?(.-)[|%]]' ) or mw.text.trim( args[1] ) )
 
end
 
 
 
return p
 

Latest revision as of 09:59, 2 April 2023

This text property lists the Traditional Chinese name of something.