Documentation for this module may be created at Module:BreakAll/doc

-- Used by {{BreakAll}} template

local p = {}

function p.main(frame)
    local inputText = frame.args[1] or ''
    local outputHtml = ''
    local lines = mw.text.split(inputText, '\n')

    for _, line in ipairs(lines) do
        if line:match("^=+[^=]") then
            -- Do nothing for heading lines
            outputHtml = outputHtml .. line .. '\n'
        elseif line:match("^[#%-]+") then
            -- For list items, apply style after the list marker
            local marker = line:match("^([#%-]+)")
            local content = line:sub(marker:len() + 1)
            local styledContent = mw.text.tag('span', {style = 'word-break: break-all;'}, content)
            outputHtml = outputHtml .. marker .. styledContent .. '\n'
        else
            -- Apply style to the whole line for other texts
            outputHtml = outputHtml .. mw.text.tag('span', {style = 'word-break: break-all;'}, line) .. '\n'
        end
    end

    outputHtml = outputHtml:sub(1, -2) -- Remove the last added line break
    return outputHtml
end

return p