From a0a1b05b7480087d63b43a818b486cc0ca16d47a Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 20 Sep 2013 13:17:38 -0400 Subject: [PATCH] Improve mw.text.nowiki, part 2 The following are now correctly escaped: * Blank lines (including those with only tabs) * ---- at the start of a line Bug: 53658 Change-Id: Ib000ff4f21f76c310741de89de0e0b66f6450344 --- engines/LuaCommon/lualib/mw.text.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engines/LuaCommon/lualib/mw.text.lua b/engines/LuaCommon/lualib/mw.text.lua index 1047028d..01914421 100644 --- a/engines/LuaCommon/lualib/mw.text.lua +++ b/engines/LuaCommon/lualib/mw.text.lua @@ -106,6 +106,9 @@ local nowikiRepl2 = { ["\n:"] = "\n:", ["\r:"] = "\r:", ["\n;"] = "\n;", ["\r;"] = "\r;", ["\n "] = "\n ", ["\r "] = "\r ", + ["\n\n"] = "\n ", ["\r\n"] = " \n", + ["\n\r"] = "\n ", ["\r\r"] = "\r ", + ["\n\t"] = "\n ", ["\r\t"] = "\r ", } local nowikiReplMagic = {} @@ -124,7 +127,10 @@ end function mwtext.nowiki( s ) -- string.gsub is safe here, because we're only caring about ASCII chars s = string.gsub( s, '["&\'<=>%[%]{|}]', nowikiRepl1 ) - s = string.sub( string.gsub( '\n' .. s, '[\r\n][#*:; ]', nowikiRepl2 ), 2 ) + s = '\n' .. s + s = string.gsub( s, '[\r\n][#*:; \n\r\t]', nowikiRepl2 ) + s = string.gsub( s, '([\r\n])%-%-%-%-', '%1----' ) + s = string.sub( s, 2 ) s = string.gsub( s, '__', '__' ) s = string.gsub( s, '://', '://' ) s = string.gsub( s, 'ISBN%s', nowikiReplMagic )