새 문서: -- 예: Module:Dictionary local p = {} local json = mw.text.jsonEncode local data = mw.loadData('Module:Dictionary/data') -- 위키 문법 표 렌더링 function p.render(frame) local out = {} out[#out+1] = '{| class="wikitable mw-dictionary"' out[#out+1] = '! 단어 !! 뜻' for term, def in pairs(data) do out[#out+1] = '|-' out[#out+1] = '| ' .. term .. ' || ' .. def end out[#out+1] = '|}' -- JS가 가져갈 원본 JSON을 숨겨둔다 out[#out+1] = '<script... |
편집 요약 없음 |
||
1번째 줄: | 1번째 줄: | ||
local p = {} | local p = {} | ||
local | local encode = mw.text.encode | ||
local data = mw.loadData('Module:Dictionary/data') | local data = mw.loadData('Module:Dictionary/data') | ||
local json = mw.text.jsonEncode(data) | |||
function p.render(frame) | function p.render(frame) | ||
local out = {} | local out = {} | ||
10번째 줄: | 9번째 줄: | ||
out[#out+1] = '! 단어 !! 뜻' | out[#out+1] = '! 단어 !! 뜻' | ||
for term, def in pairs(data) do | for term, def in pairs(data) do | ||
out[#out+1] = '|- | out[#out+1] = '|-\n| ' .. term .. ' || ' .. def | ||
end | end | ||
out[#out+1] = '|}' | out[#out+1] = '|}' | ||
-- | |||
out[#out+1] = '< | -- ① JSON을 “숨은 <div>”에 넣고 HTML-escape | ||
.. json | out[#out+1] = '<div id="dictionary-json" style="display:none">' | ||
.. encode(json) .. '</div>' | |||
return table.concat(out, '\n') | return table.concat(out, '\n') | ||
end | end |
2025년 6월 29일 (일) 02:58 판
이 모듈에 대한 설명문서는 모듈:Dictionary/설명문서에서 만들 수 있습니다
local p = {}
local encode = mw.text.encode
local data = mw.loadData('Module:Dictionary/data')
local json = mw.text.jsonEncode(data)
function p.render(frame)
local out = {}
out[#out+1] = '{| class="wikitable mw-dictionary"'
out[#out+1] = '! 단어 !! 뜻'
for term, def in pairs(data) do
out[#out+1] = '|-\n| ' .. term .. ' || ' .. def
end
out[#out+1] = '|}'
-- ① JSON을 “숨은 <div>”에 넣고 HTML-escape
out[#out+1] = '<div id="dictionary-json" style="display:none">'
.. encode(json) .. '</div>'
return table.concat(out, '\n')
end
-- API 나 다른 모듈에서 JSON으로만 쓰고 싶을 때 호출
function p.export()
return json(data)
end
return p