Module:AbilitySection: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
Identify interaction boxes by their data attributes rather than CSS class names, so box styling can change independently (with help from vergir-bot LLM)
Vergir (talk | contribs)
Read the iconbox- data attributes from the box (with help from vergir-bot LLM)
Line 29: Line 29:
local function process_interactions(html, ability_num)
local function process_interactions(html, ability_num)
local manual, idx, seen = {}, 0, {}
local manual, idx, seen = {}, 0, {}
-- Boxes are identified by their data-ai-* attributes, which are the contract
-- Boxes are identified by their data-iconbox-* attributes, which are the
-- with Template:IconBox. Class names are presentational and deliberately not
-- contract with Template:IconBox. Class names are presentational and
-- matched here, so box styling can change without touching this.
-- deliberately not matched here, so box styling can change without touching this.
local out = html:gsub('(<div)([^>]*data%-ai%-icon="[^"]*"[^>]*)(>)', function(pre, attrs, post)
local out = html:gsub('(<div)([^>]*data%-iconbox%-icon="[^"]*"[^>]*)(>)', function(pre, attrs, post)
local file = attrs:match('data%-ai%-icon="([^"]*)"')
local file = attrs:match('data%-iconbox%-icon="([^"]*)"')
if file and file ~= '' then
if file and file ~= '' then
local base  = mw.ustring.lower((file:gsub('%.%w+$', '')))
local base  = mw.ustring.lower((file:gsub('%.%w+$', '')))
Line 43: Line 43:
table.insert(manual, {
table.insert(manual, {
file  = file,
file  = file,
title  = attrs:match('data%-ai%-title="([^"]*)"') or '',
title  = attrs:match('data%-iconbox%-title="([^"]*)"') or '',
state  = attrs:match('data%-ai%-state="([^"]*)"') or 'normal',
state  = attrs:match('data%-iconbox%-state="([^"]*)"') or 'normal',
anchor = box_id,
anchor = box_id,
})
})