|
--[[--------------------------< S T R I P _ A P O S T R O P H E _ M A R K U P >--------------------------------
Strip wiki italic and bold markup from argument so that it doesn't contaminate COinS metadata.
This function strips common patterns of apostrophe markup. We presume that editors who have taken the time to
markup a title have, as a result, provided valid markup. When they don't, some single apostrophes are left behind.
]]
function strip_apostrophe_markup (argument)
local pattern='';
local cap='';
local cap2='';
if not is_set (argument) then return argument; end
while true do
while true do -- look for and remove all 5-apostrophe (bold and italic) markup
if argument:match ("%'%'%'%'%'") then -- isbold thereitalic an instance of bold-italic?(5)
if argument=argument:match gsub("%'%'%'%'%'.*%'%'%'%'%'"), then""); -- 5,remove all instances of 5it
pattern, cap =elseif argument:match ("(%'%'%'%'%'(.*)%'%'%'%'%')"); then -- italic start and end without content (4)
pattern, cap argument= argument: match gsub(" (%'%' (.*)%'%' )", "") ;▼
cap2 = ""; -- set to empty string so we do only one replacement at end
elseif argument:match ("%'%'%'%'%'.*%'%'%'.*%'%'") then -- bold italic followed by italic (5, 3, 2)
pattern, cap, cap2 argument= argument:match gsub("(%'%'%'%'%'(.*)%'%'%'(.*)%'%')", "");
elseif argument:match ("%'%'%'%'%'.*%'%'.*%'%'%'") then -- bold italic followed by bold (5, 2, 3)
pattern, cap, cap2 argument= argument:match gsub("(%'%'%'%'%'(.*)%'%'(.*)%'%'%')", "");
elseif argument:match ("%'%'%'.*%'%'.*%'%'%'%'%'") then -- bold italic followed by italic (3, 2, 5)
pattern, cap, cap2 = argument:match ("(%'%'%'(.*)%'%'(.*)%'%'%'%'%')");
elseif argument:match ("%'%'%'.*%'%'%'%'%'.*%'%'") then -- bold italic followed by italic (3, 5, 2)
pattern, cap, cap2 = argument:match ("(%'%'%'(.*)%'%'%'%'%'(.*)%'%')");
elseif argument:match ("%'%'.*%'%'%'%'%'.*%'%'%'") then -- bold italic followed by italic (2, 5, 3)
pattern, cap, cap2 = argument:match ("(%'%'(.*)%'%'%'%'%'(.*)%'%'%')");
elseif argument:match ("%'%'.*%'%'%'.*%'%'%'%'%'") then -- italic followed by bold (2, 3, 5)
pattern, cap, cap2 = argument:match ("(%'%'(.*)%'%'%'(.*)%'%'%'%'%')");
end
cap = escape_lua_magic_chars (cap); -- replace lua magic characters
cap2 = escape_lua_magic_chars (cap2); -- replace lua magic characters
pattern = escape_lua_magic_chars (pattern); -- replace lua magic characters
argument=argument:gsub(pattern, cap..cap2); -- remove the markup
else
break;
break; -- none or no more 5-apostrophe matches
end
end
while true do -- look for and remove all 3-apostrophe (bold) markup
if argument:match ("%'%'%'.*%'%'%'") then -- is there an instance of bold?
pattern, cap = argument:match ("(%'%'%'(.*)%'%'%')")
cap = escape_lua_magic_chars (cap); -- replace lua magic characters
pattern = escape_lua_magic_chars (pattern); -- replace lua magic characters
argument=argument:gsub(pattern, cap); -- remove the markup
else
break; -- none or no more 3 matches
end
end
while true do -- look for and remove all 2-apostrophe (italic) markup
if argument:match ("%'%'.*%'%'") then -- is there an instance of italic?
▲ pattern, cap = argument:match ("(%'%'(.*)%'%')")
cap = escape_lua_magic_chars (cap); -- replace lua magic characters
pattern = escape_lua_magic_chars (pattern); -- replace lua magic characters
argument=argument:gsub(pattern, cap); -- remove the markup
else
break; -- none or no more 2 matches
end
end
|