편집 요약 없음
편집 요약 없음
태그: 되돌려진 기여
1번째 줄: 1번째 줄:
-- Module:Dictionary  ▼전체 교체
-- Module:Dictionary  (전체 교체)
local p     = {}
local p, data = {}, mw.loadData('Module:Dictionary/data')
local encode = mw.text.encode
local frame  = mw.getCurrentFrame()
local data  = mw.loadData('Module:Dictionary/data')


function p.render(frame)
-- 위키텍스트 → HTML → plain-text 를 얻기 위한 헬퍼
-- ① 검색 UI가 들어갈 빈 컨테이너
local function toPlain(html)
local out = { '<div class="dictionary-container dict-card"></div>' }
-- strip strip-markers ⇒ 태그 ⇒ decode 엔티티
local txt = mw.text.killMarkers(html):gsub('<[^>]+>', '')
return mw.text.decode(txt)
end


-- ② 숨겨 둔 JSON (XSS 방지 HTML-escape)
function p.render()
out[#out+1] = '<div id="dictionary-json" style="display:none">'
local dict = {}              -- { plainLower → HTML 카드 }
              .. encode(mw.text.jsonEncode(data))
for term, defi in pairs(data) do
              .. '</div>'
local termHTML = frame:preprocess(term)
return table.concat(out, '\n')
local defHTML  = frame:preprocess(defi)
 
-- 보기 좋은 카드형 HTML (style 은 JS 쪽 CSS 로)
local card = '<div class="dict-card"><div class="term">'
            .. termHTML .. '</div> <div class="def">' .. defHTML
            .. '</div></div>'
 
dict[toPlain(termHTML):lower()] = card
end
 
-- 숨은 JSON 삽입
return '<script type="application/json" id="dictionary-json">'
      .. mw.text.encode(mw.text.jsonEncode(dict)) .. '</script>'
end
end


return p
return p

2025년 6월 29일 (일) 03:53 판

이 모듈에 대한 설명문서는 모듈:Dictionary/설명문서에서 만들 수 있습니다

-- Module:Dictionary  (전체 교체)
local p, data = {}, mw.loadData('Module:Dictionary/data')
local frame   = mw.getCurrentFrame()

-- 위키텍스트 → HTML → plain-text 를 얻기 위한 헬퍼
local function toPlain(html)
	-- strip strip-markers ⇒ 태그 ⇒ decode 엔티티
	local txt = mw.text.killMarkers(html):gsub('<[^>]+>', '')
	return mw.text.decode(txt)
end

function p.render()
	local dict = {}               -- { plainLower → HTML 카드 }
	for term, defi in pairs(data) do
		local termHTML = frame:preprocess(term)
		local defHTML  = frame:preprocess(defi)

		-- 보기 좋은 카드형 HTML (style 은 JS 쪽 CSS 로)
		local card = '<div class="dict-card"><div class="term">'
		             .. termHTML .. '</div> <div class="def">' .. defHTML
		             .. '</div></div>'

		dict[toPlain(termHTML):lower()] = card
	end

	-- 숨은 JSON 삽입
	return '<script type="application/json" id="dictionary-json">'
	       .. mw.text.encode(mw.text.jsonEncode(dict)) .. '</script>'
end

return p