Module:Diff/sandbox: Difference between revisions

Content deleted Content added
test
poke
Line 9:
-----------------------------------------------------------------------------
 
local SKIP_SEPARATOR = true -- a constant
 
IN = "in"; OUT = "out"; SAME = "same" -- token statuses
local IN = "in"
local OUT = "out"
local SAME = "same"
 
-----------------------------------------------------------------------------
Line 23 ⟶ 26:
-- @return A list of tokens.
-----------------------------------------------------------------------------
local function split(text, separator, skip_separator)
separator = separator or "%s+"
local parts = {}
Line 53 ⟶ 56:
-- @return the least common subsequence as a matrix.
-----------------------------------------------------------------------------
local function quick_LCS(t1, t2)
local m = #t1
local n = #t2
Line 98 ⟶ 101:
-- @return an HTML string.
-----------------------------------------------------------------------------
local function format_as_html(tokens)
local diff_buffer = ""
local token, status
Line 125 ⟶ 128:
-- @return A list of annotated tokens.
-----------------------------------------------------------------------------
local function diff(old, new, separator)
assert(old); assert(new)
new = split(new, separator); old = split(old, separator)
Line 200 ⟶ 203:
-- Wiki diff style, currently just for a line
-----------------------------------------------------------------------------
local function wikiDiff(old, new, separator)
local tokens = diff(old, new, separator)
--[[local root = mw.html.create('')
 
local token, status
Line 271 ⟶ 274:
end
end
 
return root]]--
return tokenstostring(root)
end
 
local function main(frame)
local wD =return wikiDiff(mw.text.unstrip(mw.text.decode(frame.args[1])), mw.text.decode(mw.text.unstrip(frame.args[2])), frame.args[3] or '[%s%.:-]+')
wD = string.gsub(wD[3][1], '</ins><ins class="diffchange diffchange-inline" style="background: #d8ecff; padding: 0.25em 0; font-weight: bold; text-decoration: initial;">', "")
return wD
end