Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Hatnote group
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local mHatnote = require('Module:Hatnote') local p = {} --Collates key-based table of classes into usable class list function collateClassList (listTable) local list = {} for k, v in pairs(listTable) do if v and type(k) == "string" then table.insert(list, k) end end return table.concat(list, " ") end --Passes through single argument from parent frame function p.group (frame) return p._group(frame:getParent().args[1], frame:getParent().args.category) end function p._group (inputText, category) --If there's an error element, pass everything through unchanged for easier --error resolution if string.find(inputText, '<%a- class="error"', 1, true) then return inputText end --Heavily reused hatnote data capture pattern local hatnotePattern = '(<div role="note" class="' .. string.gsub(mHatnote.defaultClasses(false), "%-", "%%-") .. '%s?(.-)">(.-)</div>)' --Capture hatnote divs and "loose" categories; we'll ignore everything else local rawDivs = {} local looseCategories = '' for x in string.gmatch(inputText, hatnotePattern) do table.insert(rawDivs, x) end for x in string.gmatch(inputText, '%[%[Category:.-%]%]') do looseCategories = looseCategories .. x end --if no inner hatnotes, return an error if not rawDivs[1] then return mHatnote.makeWikitextError( 'no inner hatnotes detected', 'Template:Hatnote group', category ) end --Preprocess divs into strings and classes local innerHatnotes = {} for k, v in pairs(rawDivs) do row = {} row.text = string.gsub(v, hatnotePattern, '%3') --Here we set class names as keys for easier intersection later row.classes = {} for m, w in ipairs( mw.text.split( string.gsub(v, hatnotePattern, '%2'), ' ', true ) ) do row.classes[mw.text.trim(w)] = true end table.insert(innerHatnotes, row) end --Identify any universal classes ("hatnote" ignored by omission earlier) local universalClasses = {} --clone first classes table to force passing by value rather than reference for k, v in pairs(innerHatnotes[1].classes) do universalClasses[k] = v end for k, v in ipairs(innerHatnotes) do for m, w in pairs(universalClasses) do universalClasses[m] = (universalClasses[m] and v.classes[m]) end end --Remove universal classes from div items, then create class strings per row for k, v in ipairs(innerHatnotes) do for m, w in pairs(v.classes) do if universalClasses[m] then v.classes[m] = nil end end v.classString = collateClassList(v.classes) end --Process div items into classed span items local innerSpans = {} for k, v in ipairs(innerHatnotes) do table.insert( innerSpans, tostring( mw.html.create("span") :addClass(v.classString ~= '' and v.classString or nil) :wikitext(v.text) ) ) end --Concatenate spans and categories, and return wrapped as a single hatnote local outputText = table.concat(innerSpans, " ") .. looseCategories local hnOptions = {extraclasses = collateClassList(universalClasses)} return mHatnote._hatnote(outputText, hnOptions) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Sandbox other
(
edit
)
Template:Tl
(
edit
)
Module:Hatnote group/doc
(
edit
)
Module:String
(
edit
)