Модуль:GetField: различия между версиями

мНет описания правки
мНет описания правки
Строка 72: Строка 72:
end
end


local function json_flat(v)
local function to_nowiki(v)
     local ok, json = pcall(mw.text.jsonEncode, v)
    local s = tostring(v)
     if not ok or not json then
     local ok, res = pcall(mw.text.nowiki, s)
         return nil
     if ok and res then
         return res
     end
     end
     json = tostring(json):gsub("[\r\n]+", "")
     return mw.text.nowiki(s)
    return json
end
end


Строка 219: Строка 219:
             if type(v) == "table" then
             if type(v) == "table" then
                 if is_array(v) then
                 if is_array(v) then
                     local json = json_flat(v)
                     local ok, json = pcall(mw.text.jsonEncode, v)
                     if json then
                     if ok and json then
                         parts[#parts + 1] = key .. "=" .. json
                         parts[#parts + 1] = key .. "=" .. to_nowiki(json)
                     end
                     end
                 else
                 else
                     local json = json_flat(v)
                     local ok, json = pcall(mw.text.jsonEncode, v)
                     if json then
                     if ok and json then
                         parts[#parts + 1] = key .. "=" .. json
                         parts[#parts + 1] = key .. "=" .. to_nowiki(json)
                     end
                     end
                     walk(v, key)
                     walk(v, key)
                 end
                 end
             else
             else
                 parts[#parts + 1] = key .. "=" .. tostring(v)
                 parts[#parts + 1] = key .. "=" .. to_nowiki(v)
             end
             end
         end
         end