Module:图书排版:修订间差异
外观
删除的内容 添加的内容
以 heti 官方规则为底补齐版式类,并把版式改为模板参数开关({{图书排版|行间注}} 等) |
以 heti 官方规则为底补齐版式类,并把版式改为模板参数开关({{图书排版|行间注}} 等) |
||
| 第6行: | 第6行: | ||
1) 收集全部位置参数,因此支持叠加:{{图书排版|古籍|楷体}} |
1) 收集全部位置参数,因此支持叠加:{{图书排版|古籍|楷体}} |
||
→ <div class="tushu-body heti--ancient heti--kai">。 |
→ <div class="tushu-body heti--ancient heti--kai">。 |
||
重复的类名会被去重(|诗词|诗 |
重复的类名会被去重(如 {{图书排版|双栏|诗词|诗词}} 不会产出重复类)。 |
||
2) 容器类一律沿用 heti 官方类名(.heti--*),不另造前缀。 |
2) 容器类一律沿用 heti 官方类名(.heti--*),不另造前缀。 |
||
分栏诗词用 |诗词|双栏 组合即可(其诗句左对齐由样式表按类集合匹配,与参数顺序无关)。 |
|||
3) **总是输出基础容器 tushu-body**(即使一个参数都没传)。原因:153 个页面已于 |
3) **总是输出基础容器 tushu-body**(即使一个参数都没传)。原因:153 个页面已于 |
||
2026-09 加上 {{图书排版/尾}},若模板不输出容器,那些 </div> 会变成孤立的 |
2026-09 加上 {{图书排版/尾}},若模板不输出容器,那些 </div> 会变成孤立的 |
||
| 第30行: | 第30行: | ||
['三栏'] = 'heti--columns-3', ['columns-3'] = 'heti--columns-3', |
['三栏'] = 'heti--columns-3', ['columns-3'] = 'heti--columns-3', |
||
['四栏'] = 'heti--columns-4', ['columns-4'] = 'heti--columns-4', |
['四栏'] = 'heti--columns-4', ['columns-4'] = 'heti--columns-4', |
||
-- 便捷组合:分栏诗词。诗句左对齐(样式表对「诗词 + 多栏」另有对齐规则) |
|||
['诗栏'] = 'heti--poetry heti--columns-2', ['shilan'] = 'heti--poetry heti--columns-2', |
|||
} |
} |
||
| 第42行: | 第40行: | ||
local val = CLASS[key] |
local val = CLASS[key] |
||
if key ~= '' and val then |
if key ~= '' and val then |
||
-- 展开为单个类名后按名去重,避免 |
-- 展开为单个类名后按名去重,避免重复写法产出重复类 |
||
for cls in val:gmatch('%S+') do |
for cls in val:gmatch('%S+') do |
||
if not seen[cls] then |
if not seen[cls] then |
||
2026年9月19日 (六) 19:00的版本
--[[
Module:图书排版 —— 解析 {{图书排版}} 的位置参数,拼出版式容器。
设计见 content/tushu/DESIGN.md。要点:
1) 收集全部位置参数,因此支持叠加:{{图书排版|古籍|楷体}}
→ <div class="tushu-body heti--ancient heti--kai">。
重复的类名会被去重(如 {{图书排版|双栏|诗词|诗词}} 不会产出重复类)。
2) 容器类一律沿用 heti 官方类名(.heti--*),不另造前缀。
分栏诗词用 |诗词|双栏 组合即可(其诗句左对齐由样式表按类集合匹配,与参数顺序无关)。
3) **总是输出基础容器 tushu-body**(即使一个参数都没传)。原因:153 个页面已于
2026-09 加上 {{图书排版/尾}},若模板不输出容器,那些 </div> 会变成孤立的
闭合标签而破坏页面结构。容器本身不带样式——限宽由 |限宽 参数触发
(见样式表里的 .heti--line-length)。
4) 竖排(|竖排 / .heti--vertical)及其锚点、横直排切换条已于 2026-09 移除。
样式表内的 .heti--vertical 官方类仍保留,页面手写 <div class="heti--vertical">
仍可用,只是不再有模板参数入口。
]]
local p = {}
-- 参数 → 容器类(中文为主,英文为别名)。值可以含多个类名,用空格分隔。
local CLASS = {
['行间注'] = 'heti--annotation', ['annotation'] = 'heti--annotation',
['古籍'] = 'heti--ancient', ['ancient'] = 'heti--ancient',
['诗词'] = 'heti--poetry', ['poetry'] = 'heti--poetry',
['楷体'] = 'heti--kai', ['kai'] = 'heti--kai',
['限宽'] = 'heti--line-length', ['line-length'] = 'heti--line-length',
['双栏'] = 'heti--columns-2', ['columns-2'] = 'heti--columns-2',
['三栏'] = 'heti--columns-3', ['columns-3'] = 'heti--columns-3',
['四栏'] = 'heti--columns-4', ['columns-4'] = 'heti--columns-4',
}
function p.main(frame)
local args = frame:getParent().args
local seen, ordered = {}, {}
for _, v in ipairs(args) do
local key = mw.text.trim(v)
local val = CLASS[key]
if key ~= '' and val then
-- 展开为单个类名后按名去重,避免重复写法产出重复类
for cls in val:gmatch('%S+') do
if not seen[cls] then
seen[cls] = true
ordered[#ordered + 1] = cls
end
end
end
end
-- 基础容器始终在前
local cls = { 'tushu-body' }
for _, c in ipairs(ordered) do
cls[#cls + 1] = c
end
return string.format('<div class="%s">', table.concat(cls, ' '))
end
return p