모듈:DotEmphasis

 관련 문서: 틀:강조점2

편집

local p = {}

function p.addDots(frame)
    local input = frame.args[1] or ''
    local dot = frame.args['dot'] or '•'

    input = mw.text.decode(tostring(input))

    if mw.ustring.len(input) == 0 then
        return '<span style="color:red;">[오류: 입력값 없음]</span>'
    end

    local result = {}

    for i = 1, mw.ustring.len(input) do
        local ch = mw.ustring.sub(input, i, i)

        -- 공백 문자는 그대로 출력 (강조점 생략)
        if mw.ustring.match(ch, '%s') then
            table.insert(result, ch)
        else
            table.insert(result, string.format('<ruby>%s<rt>%s</rt></ruby>', ch, dot))
        end
    end

    return table.concat(result)
end

return p