Module:Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 27: Line 27:
         return nil
         return nil
     end
     end
end
-- Helper function to preprocess text with proper newline handling
local function preprocess_text(text)
    if not text then return text end
    -- First replace \"n with actual newlines
    text = text:gsub('\\"n', '\n')
    -- Then let MediaWiki's preprocess handle the newlines and other wikitext
    return mw.text.preprocess(text)
end
end


Line 78: Line 87:
     end
     end
      
      
     -- Replace \"n with HTML line breaks
     -- Preprocess the text (handles newlines and other wikitext)
    label = label:gsub('\\"n', '<br>')
     return preprocess_text(label)
   
     return label
end
end


Line 118: Line 125:
     -- Default to input label if localized string is not found
     -- Default to input label if localized string is not found
     if (key == nil) then
     if (key == nil) then
         return label
         return preprocess_text(label)
     end
     end
     if (data_lang[key] == nil) then
     if (data_lang[key] == nil) then
         return label
         return preprocess_text(label)
     end
     end


     -- Replace \"n with HTML line breaks in the result
     -- Preprocess the text (handles newlines and other wikitext)
     local result = data_lang[key]
     return preprocess_text(data_lang[key])
    result = result:gsub('\\"n', '<br>')
   
    return result
end
end