Content deleted Content added
poke |
update from commons |
||
Line 203:
-- Wiki diff style, currently just for a line
-----------------------------------------------------------------------------
local function wikiDiff(old, new, separator, opts)
opts = opts or {}
local tokens = diff(old, new, separator)
local root = mw.html.create('')
root:wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Module:Diff/styles.css'}))
local token, status
-- Override default border-width for browsers that support them.
-- Needed for RTL support; forbidden in TemplateStyles.
local
local is_different = false
for _, token_record in ipairs(tokens) do
▲ '-webkit-border-end-width: 1px; -webkit-border-start-width: 4px; ' ..
if token_record[2] ~= SAME then
is_different = true
break
end
end
local tbl = root:tag('table'):attr('lang', ''):addClass('diff')
if (opts.oldTitle or opts.newTitle) then
local tr = tbl:tag('tr')
:attr('scope', 'col')
:attr('colspan', '2')
:wikitext(opts.oldTitle)
tr:tag('th')
:attr('scope', 'col')
:attr('colspan', '2')
:wikitext(opts.newTitle)
end
local tr =
tr:tag('td')
:addClass('diff-marker')
:wikitext(is_different and '−' or ' ')
▲ :wikitext('−')
local deleted = tr
:tag('td')
:cssText(
:addClass(is_different and 'diff-deletedline' or 'diff-context')
:tag('div')
for i, token_record in ipairs(tokens) do
Line 240 ⟶ 255:
deleted
:tag('del')
:addClass('diffchange')
:addClass('diffchange-inline')
Line 250 ⟶ 264:
tr:tag('td')
:
:wikitext(is_different and '+' or ' ')
local inserted = tr
:tag('td')
:cssText(
:addClass(is_different and 'diff-addedline' or 'diff-context')
:tag('div')
for i, token_record in ipairs(tokens) do
Line 266 ⟶ 279:
inserted
:tag('ins')
:addClass('diffchange')
:addClass('diffchange-inline')
Line 276 ⟶ 288:
return tostring(root)
end
local function tidyVal(val)
if ((type(val) == 'string') and (val == '')) then
return nil
end
return val
end
local function main(frame)
local args = frame.args
local pargs = (frame:getParent() or {}).args or {}
return wikiDiff(
mw.text.unstrip(mw.text.decode(args[1])),
mw.text.unstrip(mw.text.decode(args[2])),
frame.args[3] or '[%s%.:-]+',
{
oldTitle = tidyVal(args['1title']) or tidyVal(pargs['1title']),
newTitle = tidyVal(args['2title']) or tidyVal(pargs['2title']),
}
)
end
|