How to align text using pandoc with lua-filters?

半城伤御伤魂 提交于 2020-12-15 01:56:02

问题


How to align all h1 headers of the pdf to center using pandoc with lua-filters?

I have the test.md file bellow:

<center>
# Chapter 1
</center>

<right>
## Sub-1-1
</right>

<left>
### Sub-1-2
</left>

<center>
# Chapter 2
</center>

<right>
## Sub-2-1
</right>

<left>
### Sub-2-2
</left>

And I need to align center all "Chapters" to center, all the "Sub--1" to right and all the "Sub--2" to left using tags as above, to stay like:

            Chapter 1
                          Sub-1-1
Sub-1-2
            Chapter 2
                          Sub-2-1
Sub-2-2

I can uppcase the "Chapters" with the follow filter.lua:

local text = require('text')

function Header(el)
    if el.level == 1 then
      return pandoc.walk_block(el, {
        Str = function(el)
            return pandoc.Str(text.upper(el.text))
        end })
    end
end

So I call the pandoc:

pandoc test.md -o test.pdf --pdf-engine=xelatex --lua-filter=./filter.lua

But I don't know how to align the things with lua-filters.

来源:https://stackoverflow.com/questions/64466021/how-to-align-text-using-pandoc-with-lua-filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!