Module:ApplyLinkAnnotations
Appearance
Usage
See documentation at the {{AnnotatedListOfLinks}}
template which calls this module.
local p = {};
function p.replaceLinksInUnorderedList(markup)
-- provided for convenience to make console testing easier for development
--
-- matches any wikilinks that are
-- 1. at the beginning of a list item
-- 2. with no existing annotation (or any text) following them
--
-- must run twice because match utilizes the newlines on *both* sides
-- of wikilinks and thus, "consumes" those chars during the first match
-- such that every-other line is ineligible for matching until the second
-- run. (which does the same thing but for all the other lines)
-- Test case(s?):
-- =p.replaceLinksInUnorderedList("\n*[[TEst|teST]] \n:* [[name]]\n::*[[link]] - with existing annotation\n::* [[for|a friend]] \n*[[t]]\n")
local anls, cnt1, cnt2
local regex = "\n(:*)%*%s?%[%[([^%]:]*)%]%]%s*\n"
local repl = "\n%1* {{Annotated link |%2}}\n"
anls, cnt1 = mw.ustring.gsub(markup, regex, repl)
anls, cnt2 = mw.ustring.gsub(anls, regex, repl)
mw.log("Replaced " .. cnt1+cnt2 .. " links without existing annotations")
return anls
end
function p.bySubstitutionInUnorderedList(frame)
return p.replaceLinksInUnorderedList(frame.args[1])
end
return p