Module:User:Suzukaze-c/Hani-tab/ko

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Suzukaze-c, for their own experimentation. Items in this module may be added and removed at Suzukaze-c's discretion; do not rely on this module's stability.


local export = {}

--[==[
* cf. [[Module:ja]].kanji_grade()
* (the implementation of .kanji_grade() seem strange to me...)
  (shouldn't $kanji be searched for within $text?)
* XXX: might belong in [[Module:ko]]
]==]
function export.hanja_grade(hanja)
	local ko_data = require('Module:ko/data')
	local grades = { 'junghak', 'gohak' }

	for i, grade in ipairs(grades) do
		if mw.ustring.match(ko_data[grade], hanja) then
			return grade
		end
	end

	return '-' -- XXX: ???
end

function export.main(data)
	local tab_row_b = mw.html.create('tr')
	:done()

	for _, char in ipairs(data.chars) do
		tab_row_b
			:tag('td')
				-- XXX: なんとなくいまいち
				:wikitext('<small>' .. export.hanja_grade(char) .. '</small>')
			:done()
		:done()
	end

	data.hani_tab
		:node(tab_row_b)
	:done()

	return data.hani_tab
end

return export