Pandocのdocx出力する際、任意の位置でセクション区切りを入れる
方法
markdown のコードブロックを使用して
```{=openxml}
<w:p><w:pPr><w:sectPr><w:type w:val="nextPage" /></w:sectPr></w:pPr></w:p>
```
(上のないよう
を本文に挿入すると、その箇所にセクション区切りが挿入されます。
え?そんなことしたらdocx以外の出力できなくなるじゃねーか!だって?
妥協案として、
{"t":"RawBlock","c":["openxml","<w:p><w:pPr><w:sectPr><w:type w:val=\"nextPage\" /></w:sectPr>\</w:pPr></w:p>"]}
な要素を挿入する Pandoc filter 用意すればいいんじゃないのかなぁ。
なんとなく(未実践)。
追記(2021/5/24)
lua filter
を使用することで、動的にセクション区切りを埋め込むことはできた。
例えば、以下のような入力ソースがあったとして
# Header1
Test1
# Header2 {.newsection type="nextPage"}
Test2
newsection
クラスと、セクション区切りのタイプを示すtype
属性あると仮定する。
以下のようなlua filter
を用意することで、
return {
{
Header = function(el)
if not el.classes:includes('newsection') then
return el
else
local section_break = string.format('<w:p><w:pPr><w:sectPr><w:type w:val="%s" /></w:sectPr></w:pPr></w:p>', el.attr.attributes['type'])
local cb = pandoc.RawBlock("openxml", section_break)
return pandoc.List:new({cb, el})
end
end,
}
}
セクション区切りを埋め込むことができる。
しかしページ番号を埋め込む方法は見つけられていない。
仕様上、sectPR
の子要素として、pageNumType
を持たせればよいとあり試してみたが、出力には反映されなかった。
参照元
Author And Source
この問題について(Pandocのdocx出力する際、任意の位置でセクション区切りを入れる), 我々は、より多くの情報をここで見つけました https://qiita.com/ktz_alias/items/9d408d86546925af4f29著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .