Jump to content

Module:Delink

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence

Documentation for this module may be created at Module:Delink/doc

-- Module:Delink
-- Removes wiki markup from text (links, formatting, etc.)

local p = {}

function p.delink(frame)
    local text = frame.args[1] or frame:getParent().args[1] or ''
    
    -- Remove file/image links
    text = text:gsub('%[%[%s*[Ff]ile%s*:[^%]]*%]%]', '')
    text = text:gsub('%[%[%s*[Ii]mage%s*:[^%]]*%]%]', '')
    
    -- Remove category links
    text = text:gsub('%[%[%s*[Cc]ategory%s*:[^%]]*%]%]', '')
    
    -- Convert [[link|text]] to text
    text = text:gsub('%[%[[^%]|]*|([^%]]*)%]%]', '%1')
    
    -- Convert [[link]] to link
    text = text:gsub('%[%[([^%]]*)%]%]', '%1')
    
    -- Remove external links formatting [http://example.com text] -> text
    text = text:gsub('%[https?://[^%s]+ ([^%]]*)%]', '%1')
    
    -- Remove plain external links [http://example.com]
    text = text:gsub('%[https?://[^%]]*%]', '')
    
    -- Remove bold '''text''' -> text
    text = text:gsub("'''([^']+)'''", '%1')
    
    -- Remove italics ''text'' -> text
    text = text:gsub("''([^']+)''", '%1')
    
    -- Remove <br>, <br/>, <br />
    text = text:gsub('<br%s*/?>', ' ')
    
    return text
end

return p