최근 바뀜
도구
업로드
도움말
길라잡이
위키 문법
특수 문서
문의·신고
디스코드
IP 사용자
216.73.216.135
로그인
모듈:Style 문서 원본 보기
←
모듈:Style
편집
토론
역사
새로고침
주시
역링크
정보
문서 편집 권한이 없습니다. 다음 이유를 확인해주세요:
요청한 명령은 다음 권한을 가진 사용자에게 제한됩니다:
사용자
.
문서의 원본을 보거나 복사할 수 있습니다.
local p = {} local function getArgs(frame) local args = {} local parent = frame:getParent() if parent then for k, v in pairs(parent.args) do if v ~= nil and v ~= "" then args[k] = v end end end for k, v in pairs(frame.args) do if v ~= nil and v ~= "" then args[k] = v end end return args end local function convertValue(val) if not val then return val end -- <...> 감싸기 제거 if mw.ustring.sub(val, 1, 1) == "<" and mw.ustring.sub(val, -1) == ">" then val = mw.ustring.sub(val, 2, -2) end -- $var → var(--var) if mw.ustring.sub(val, 1, 1) == "$" then return "var(--" .. mw.ustring.sub(val, 2) .. ")" end -- ##ffffff → {{adt|#ffffff}} if mw.ustring.sub(val, 1, 2) == "##" and mw.ustring.match(val, "^##[%x%X][%x%X][%x%X][%x%X][%x%X][%x%X]$") then return "{{adt|#" .. mw.ustring.sub(val, 3) .. "}}" end return val end local mapSingle = { c = "color", bg = "background", bgc = "background-color", fs = "font-size", fw = "font-weight", ff = "font-family", lh = "line-height", fd = "flex-direction", ls = "letter-spacing", ta = "text-align", gap = "gap", op = "opacity", w = "width", h = "height", maxw = "max-width", minw = "min-width", fl = "float", p = "padding", pt = "padding-top", pr = "padding-right", pb = "padding-bottom", pl = "padding-left", m = "margin", mt = "margin-top", mr = "margin-right", mb = "margin-bottom", ml = "margin-left", ovf = "overflow", ovfx = "overflow-x", ovfy = "overflow-y", dsp = "display", pos = "position", zi = "z-index", va = "vertical-align", bdrad = "border-radius", wb = "word-break", } local borderMap = { bd = "border", bdt = "border-top", bdr = "border-right", bdb = "border-bottom", bdl = "border-left", bdw = "border-width", } local borderTypeMap = { sld = "solid", dsh = "dashed", dot = "dotted", db = "double", grv = "groove", rdg = "ridge", ins = "inset", ous = "outset", } local function addStyle(list, name, value) if not name or name == "" then return end if not value or value == "" then return end value = convertValue(value) table.insert(list, name .. ":" .. value .. ";") end local function buildBorder(token, cssName, styles) local parts = mw.text.split(token, "-") table.remove(parts, 1) local result = {} for _, part in ipairs(parts) do if borderTypeMap[part] then table.insert(result, borderTypeMap[part]) else table.insert(result, convertValue(part)) end end addStyle(styles, cssName, table.concat(result, " ")) end local function tokenizeSpec(spec) local tokens = {} local i = 1 local len = mw.ustring.len(spec) while i <= len do local ch = mw.ustring.sub(spec, i, i) if ch == "<" then local j = i + 1 while j <= len and mw.ustring.sub(spec, j, j) ~= ">" do j = j + 1 end table.insert(tokens, mw.ustring.sub(spec, i, j)) i = j + 1 elseif ch:match("%s") then i = i + 1 else local j = i while j <= len do local c = mw.ustring.sub(spec, j, j) if c:match("%s") then break elseif c == "<" then -- <...> 블록 통째로 포함 j = j + 1 while j <= len and mw.ustring.sub(spec, j, j) ~= ">" do j = j + 1 end j = j + 1 else j = j + 1 end end table.insert(tokens, mw.ustring.sub(spec, i, j - 1)) i = j end end return tokens end local function parseSpec(spec) local styles = {} local colspan, rowspan for _, token in ipairs(tokenizeSpec(spec)) do token = mw.text.trim(token) if token ~= "" then local dashPos = token:find("-") if dashPos then local key = token:sub(1, dashPos - 1) local val = token:sub(dashPos + 1) if key == "px" then val = convertValue(val) addStyle(styles, "padding-left", val) addStyle(styles, "padding-right", val) elseif key == "py" then val = convertValue(val) addStyle(styles, "padding-top", val) addStyle(styles, "padding-bottom", val) elseif key == "mx" then val = convertValue(val) addStyle(styles, "margin-left", val) addStyle(styles, "margin-right", val) elseif key == "my" then val = convertValue(val) addStyle(styles, "margin-top", val) addStyle(styles, "margin-bottom", val) elseif borderMap[key] then buildBorder(token, borderMap[key], styles) elseif key == "col" then colspan = val elseif key == "row" then rowspan = val else local cssName = mapSingle[key] if cssName then val = convertValue(val) addStyle(styles, cssName, val) end end end end end return table.concat(styles, " "), colspan, rowspan end function p.attr(frame) local args = getArgs(frame) local spec = mw.text.trim(args[1] or "") if spec == "" then return "" end local css, cToken, rToken = parseSpec(spec) local colspan = args.col or cToken local rowspan = args.row or rToken local attrs = {} if css ~= "" then table.insert(attrs, 'style="' .. css .. '"') end if colspan and colspan ~= "" then table.insert(attrs, 'colspan="' .. colspan .. '"') end if rowspan and rowspan ~= "" then table.insert(attrs, 'rowspan="' .. rowspan .. '"') end return table.concat(attrs, " ") end function p.css(frame) local args = getArgs(frame) local spec = mw.text.trim(args[1] or "") if spec == "" then return "" end local css = parseSpec(spec) return css end return p
이 문서에 포함된 문서:
모듈:Style/설명문서
(
원본 보기
)
모듈:Style
문서로 돌아갑니다.