Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created July 27, 2020 07:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/16967b9f3ed414bb8ceeca2962a7a9c2 to your computer and use it in GitHub Desktop.
Save zr-tex8r/16967b9f3ed414bb8ceeca2962a7a9c2 to your computer and use it in GitHub Desktop.
Pandoc:節番号のスタイルを変えるやつ
input-files:
- test.md
filters:
- numbering.lua
output-file: test_out.html
standalone: true
table-of-contents: true
toc-depth: 2
number-sections: true
local numbers = {}
-- 節番号のスタイル
local number_styles = {
function() return ("第%s章"):format(numbers[1]) end;
function() return ("第%s節"):format(numbers[2]) end;
}
function Header(el)
-- 子カウンタをリセット
if numbers[el.level+1] then
numbers[el.level+1] = 0
end
-- .unnumbered なら変更しない
if el.classes:includes("unnumbered") then
return -- 変更しない
end
-- カウンタをインクリメント
numbers[el.level] = (numbers[el.level] or 0) + 1
-- 番号を生成し'number'属性に設定する
el.attributes['number'] = number_styles[el.level]()
return el
end

まえがき {-}

ゆきだるま

ゆきだるまは素敵

ゆきだるまは本質的

TeXとの関係 {-}

マフラー

ホウキ

アヒル

アヒルは本質的か

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>test</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#まえがき">まえがき</a></li>
<li><a href="#ゆきだるま"><span class="toc-section-number">第1章</span> ゆきだるま</a>
<ul>
<li><a href="#ゆきだるまは素敵"><span class="toc-section-number">第1節</span> ゆきだるまは素敵</a></li>
<li><a href="#ゆきだるまは本質的"><span class="toc-section-number">第2節</span> ゆきだるまは本質的</a></li>
<li><a href="#texとの関係">TeXとの関係</a></li>
<li><a href="#マフラー"><span class="toc-section-number">第3節</span> マフラー</a></li>
<li><a href="#ホウキ"><span class="toc-section-number">第4節</span> ホウキ</a></li>
</ul></li>
<li><a href="#アヒル"><span class="toc-section-number">第2章</span> アヒル</a>
<ul>
<li><a href="#アヒルは本質的か"><span class="toc-section-number">第1節</span> アヒルは本質的か</a></li>
</ul></li>
</ul>
</nav>
<h1 class="unnumbered" data-number="" id="まえがき">まえがき</h1>
<h1 data-number="第1章" id="ゆきだるま"><span class="header-section-number">第1章</span> ゆきだるま</h1>
<h2 data-number="第1節" id="ゆきだるまは素敵"><span class="header-section-number">第1節</span> ゆきだるまは素敵</h2>
<h2 data-number="第2節" id="ゆきだるまは本質的"><span class="header-section-number">第2節</span> ゆきだるまは本質的</h2>
<h2 class="unnumbered" data-number="" id="texとの関係">TeXとの関係</h2>
<h2 data-number="第3節" id="マフラー"><span class="header-section-number">第3節</span> マフラー</h2>
<h2 data-number="第4節" id="ホウキ"><span class="header-section-number">第4節</span> ホウキ</h2>
<h1 data-number="第2章" id="アヒル"><span class="header-section-number">第2章</span> アヒル</h1>
<h2 data-number="第1節" id="アヒルは本質的か"><span class="header-section-number">第1節</span> アヒルは本質的か</h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment