Module:Kanbun
Appearance
Usage
[edit source]Example:
{{#invoke:Kanbun|kanbun|
桃 之 夭 夭{タル} \O 灼 灼{タリ} 其{ノ} 華 \\
之{ノ} 子 于{キ} 帰{グ} \O 宜[二]{シカラン} 其{ノ} 室 家[一]{ニ} \\ \\
桃 之{ノ} 夭 夭{タル} \O 有{リ}[レ] 蕡{タル} 其{ノ} 実 \\
之{ノ} 子 于{キ} 帰{グ} \O 宜{シカラン}[二] 其{ノ} 家 室{ニ}[一] \\ \\
桃 之 夭 夭{タル} \O 其{ノ} 葉 蓁 蓁{タリ} \\
之{ノ} 子 于{キ} 帰{グ} \O 宜[二]{シカラン} 其{ノ} 家 人[一]{ニ}
}}
Appears:
桃之夭夭タル 灼灼タリ其ノ華
之ノ子于キ帰グ 宜㆓シカラン其ノ室家㆒ニ
桃之ノ夭夭タル 有㆑リ蕡タル其ノ実
之ノ子于キ帰グ 宜㆓シカラン其ノ家室㆒ニ
桃之夭夭タル 其ノ葉蓁蓁タリ
之ノ子于キ帰グ 宜㆓シカラン其ノ家人㆒ニ
之ノ子于キ帰グ 宜㆓シカラン其ノ室家㆒ニ
桃之ノ夭夭タル 有㆑リ蕡タル其ノ実
之ノ子于キ帰グ 宜㆓シカラン其ノ家室㆒ニ
桃之夭夭タル 其ノ葉蓁蓁タリ
之ノ子于キ帰グ 宜㆓シカラン其ノ家人㆒ニ
Kanji are separated by a half-width space.
The part enclosed in {} represents the sending kana or reading kana, and the part surrounded by [] represents the return point.
The line break during input does not affect the output if it is the part of the kanji separater. If you want to insert a new line in the output, use \\.
Special symbol
- \\: Insert a new line.
- \O: Insert a blank space.
- \H: Used when hyphens are included.
local p = {}
local kunten = {
["レ"] = "㆑", -- 返り点には U+3191からU+319Fを使う。
["一"] = "㆒",
["二"] = "㆓",
["三"] = "㆔",
["四"] = "㆕",
["上"] = "㆖",
["中"] = "㆗",
["下"] = "㆘",
["甲"] = "㆙",
["乙"] = "㆚",
["丙"] = "㆛",
["丁"] = "㆜",
["天"] = "㆝",
["地"] = "㆞",
["人"] = "㆟",
["一レ"] = "㆒㆑",
["上レ"] = "㆖㆑",
["甲レ"] = "㆙㆑",
["天レ"] = "㆝㆑"
}
function p.kanbun(frame)
local input_text = frame.args[1]
local html_output =
'<div style="writing-mode: vertical-rl; font-size: 150%; white-space: nowrap; font-family: serif">'
local shift = 0
local style = ""
for char in string.gmatch(input_text, "%S+") do
local kanzi = char:match("^(.-)[\\%[%{]") or char
kanzi = kanzi:gsub("。", "")
kanzi = kanzi:gsub("、", "")
kanzi = kanzi:gsub("「", "")
kanzi = kanzi:gsub("」", "")
kanzi = kanzi:gsub("『", "")
kanzi = kanzi:gsub("』", "")
local okurigana = char:match("{(.-)}")
local kaeriten = char:match("%[(.-)%]")
local saidoku = char:match("%((.-)%)")
local symbol = char:match("\\(begin)") or char:match("\\(end)") or char:match("\\(.)")
if symbol == "O" then
kanzi = " "
end
if symbol == "\\" then
html_output = html_output .. "<br>"
shift = 0
elseif symbol == "begin" then
style = style .. char:match("\\begin{(.-)}")
elseif symbol == "end" then
style = style:gsub(char:match("\\end{(.-)}"), "")
else
-- 漢字
html_output = html_output .. string.format(
'<span style="display: inline-block; position: relative; margin-left: 0.5em; margin-right: 0.5em; margin-top: 0.4em; margin-bottom: 0.5em; bottom: -%sem; %s">%s',
shift, style, kanzi)
if char:find("。」") then
html_output = html_output ..
[[<span style="position: absolute; bottom: -1em;">。</span><span style="position: absolute; bottom: -1.25em;">」</span>]]
end
if char:find("。』") then
html_output = html_output ..
[[<span style="position: absolute; bottom: -1em;">。</span><span style="position: absolute; bottom: -1.25em;">』</span>]]
end
if char:find("。") then
html_output = html_output .. [[<span style="position: absolute; bottom: -1em;">。</span>]]
end
if char:find("、") then
html_output = html_output .. [[<span style="position: absolute; bottom: -1em;">、</span>]]
end
if char:find("「") then
html_output = html_output .. [[<span style="position: absolute; top: -1em;">「</span>]]
end
if char:find("」") then
html_output = html_output .. [[<span style="position: absolute; bottom: -1em;">」</span>]]
end
if char:find("『") then
html_output = html_output .. [[<span style="position: absolute; top: -1em;">『</span>]]
end
if char:find("』") then
html_output = html_output .. [[<span style="position: absolute; bottom: -1em;">』</span>]]
end
-- 返り点
if kaeriten then
kaeriten = kunten[kaeriten] or kaeriten
if symbol == "H" then
html_output = html_output ..
string.format(
'<span style="position: absolute; font-size: 50%%; top: 1.8em; left: -0.25em;">%s</span>',
kaeriten)
else
if kaeriten == "㆒㆑" then
html_output = html_output ..
[[<span style="position: absolute; font-size: 50%; bottom: -1em; left: 0.25em;">㆒</span><span style="position: absolute; font-size: 50%; bottom: -1.35em; left: 0.25em;">㆑</span>]]
elseif kaeriten == "㆖㆑" then
html_output = html_output ..
[[<span style="position: absolute; font-size: 50%; bottom: -1em; left: 0.25em; transform: scaleY(0.6);">㆖</span><span style="position: absolute; font-size: 50%; bottom: -1.45em; left: 0.25em; transform: scaleY(0.6);">㆑</span>]]
elseif kaeriten == "㆙㆑" then
html_output = html_output ..
[[<span style="position: absolute; font-size: 50%; bottom: -1em; left: 0.25em; transform: scaleY(0.6);">㆙</span><span style="position: absolute; font-size: 50%; bottom: -1.4em; left: 0.25em; transform: scaleY(0.6);">㆑</span>]]
elseif kaeriten == "㆝㆑" then
html_output = html_output ..
[[<span style="position: absolute; font-size: 50%; bottom: -1em; left: 0.25em; transform: scaleY(0.6);">㆝</span><span style="position: absolute; font-size: 50%; bottom: -1.4em; left: 0.25em; transform: scaleY(0.6);">㆑</span>]]
else
html_output = html_output ..
string.format(
'<span style="position: absolute; font-size: 50%%; bottom: -1em; left: 0.25em;">%s</span>',
kaeriten)
end
end
end
-- 送り仮名
if okurigana then
-- ひらがなとカタカナの個数を計算
local hiraganumber = 0
local katakanumber = 0
local i = 1
while i <= #okurigana do
local byte = string.byte(okurigana, i)
local second = string.byte(okurigana, i + 1)
local third = string.byte(okurigana, i + 2)
local codepoint = ((byte % 16) * 2 ^ 12) + ((second % 64) * 2 ^ 6) + (third % 64)
if codepoint >= 0x3041 and codepoint <= 0x309F then
hiraganumber = hiraganumber + 1
elseif codepoint >= 0x30A0 and codepoint <= 0x30FF then
katakanumber = katakanumber + 1
end
i = i + 3
end
-- 位置の調整
local bottom = nil
local top = nil
if hiraganumber == 0 and katakanumber == 5 then
bottom = "-1"
local first_line = okurigana:sub(1, 9)
local second_line = okurigana:sub(10)
html_output = html_output .. string.format(
'<span style="position: absolute; font-size: 50%%; bottom: %sem; right: -1.5em; white-space: nowrap;">%s</span>',
bottom, first_line)
html_output = html_output .. string.format(
'<span style="position: absolute; font-size: 50%%; bottom: %sem; right: -0.5em; white-space: nowrap;">%s</span>',
bottom, second_line)
else
if hiraganumber == 0 and katakanumber == 1 then
bottom = "-0.5"
elseif hiraganumber == 0 and katakanumber == 2 then
bottom = "-1"
elseif hiraganumber == 0 and katakanumber == 3 then
bottom = "-2"
elseif hiraganumber == 0 and katakanumber == 4 then
bottom = "-2.5"
elseif hiraganumber == 1 and katakanumber == 0 then
bottom = "0.5"
elseif hiraganumber == 2 and katakanumber == 0 then
bottom = "0"
elseif hiraganumber == 3 and katakanumber == 0 then
bottom = "-0.5"
elseif hiraganumber == 4 and katakanumber == 0 then
bottom = "-1"
elseif hiraganumber == 1 and katakanumber == 1 then
bottom = "-0.5"
elseif hiraganumber + katakanumber >= 5 then
top = "0"
shift = shift + 0.5 * (hiraganumber + katakanumber - 4)
else
bottom = "-1"
end
if bottom then
html_output = html_output .. string.format(
'<span style="position: absolute; font-size: 50%%; bottom: %sem; right: -0.5em; white-space: nowrap;">%s</span>',
bottom, okurigana)
else
html_output = html_output .. string.format(
'<span style="position: absolute; font-size: 50%%; top: %sem; right: -0.5em; white-space: nowrap;">%s</span>',
top, okurigana)
end
end
end
if saidoku then
html_output = html_output .. string.format(
'<span style="position: absolute; font-size: 50%%; bottom: 0em; left: -0.5em; white-space: nowrap;">%s</span>',
saidoku)
end
html_output = html_output .. "</span>"
end
end
html_output = html_output .. "</div>"
return html_output
end
return p