Module:Plain text: Difference between revisions
m
1 revision imported
(implement "encode" option, strip out external link alt text) |
Johnrdorazio (talk | contribs) m (1 revision imported) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
--converts text with wikilinks to plain text, e.g "[[foo|gah]] is [[bar]]" to "gah is bar" | --converts text with wikilinks to plain text, e.g "[[foo|gah]] is [[bar]]" to "gah is bar" | ||
--removes anything enclosed in tags that isn't nested, mediawiki strip markers (references etc), files, italic and bold markup | --removes anything enclosed in tags that isn't nested, mediawiki strip markers (references etc), files, italic and bold markup | ||
require[[strict]] | |||
local p = {} | local p = {} | ||
Line 16: | Line 17: | ||
:gsub('<span.->(.-)</span>', '%1') --remove spans while keeping text inside | :gsub('<span.->(.-)</span>', '%1') --remove spans while keeping text inside | ||
:gsub('<i.->(.-)</i>', '%1') --remove italics while keeping text inside | :gsub('<i.->(.-)</i>', '%1') --remove italics while keeping text inside | ||
:gsub('<b.->(.-)</b>', '%1') --remove bold while keeping text inside | |||
:gsub('<em.->(.-)</em>', '%1') --remove emphasis while keeping text inside | |||
:gsub('<strong.->(.-)</strong>', '%1') --remove strong while keeping text inside | |||
:gsub('<.->.-<.->', '') --strip out remaining tags and the text inside | :gsub('<.->.-<.->', '') --strip out remaining tags and the text inside | ||
:gsub('<.->', '') --remove any other tag markup | :gsub('<.->', '') --remove any other tag markup | ||
:gsub('%[%[%s*[Ff] | :gsub('%[%[%s*[Ff][Ii][Ll][Ee]%s*:.-%]%]', '') --strip out files | ||
:gsub('%[%[%s*[Ii] | :gsub('%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:.-%]%]', '') --strip out use of image: | ||
:gsub('%[%[%s*[Cc] | :gsub('%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:.-%]%]', '') --strip out categories | ||
:gsub('%[%[[^%]]-|', '') --strip out piped link text | :gsub('%[%[[^%]]-|', '') --strip out piped link text | ||
:gsub('([^%[])%[[^%[%]][^%]]-%s', '%1') --strip out external link text | :gsub('([^%[])%[[^%[%]][^%]]-%s', '%1') --strip out external link text | ||
Line 27: | Line 31: | ||
:gsub("'''''", "") --strip out bold italic markup | :gsub("'''''", "") --strip out bold italic markup | ||
:gsub("'''?", "") --not stripping out '''' gives correct output for bolded text in quotes | :gsub("'''?", "") --not stripping out '''' gives correct output for bolded text in quotes | ||
:gsub('----', '') --remove ---- lines | :gsub('----+', '') --remove ---- lines | ||
:gsub("^%s+", "") --strip leading | :gsub("^%s+", "") --strip leading | ||
:gsub("%s+$", "") --and trailing spaces | :gsub("%s+$", "") --and trailing spaces |