Side note: !!! I didn't know pandoc Lists could be concatenated with `..`, that's great! Is this a recent addition to the Lua filter module? Would be great to document it (https://pandoc.org/lua-filters.html#pandoc.list:__concat). Happy to submit a PR, but not sure whether small PRs on Pandoc's documentations are welcome.
relayism <tamas....@vlabs.at> writes:
> I know --number-sections does not support markdown output, but how
> could I achieve this:
>
> I am converting a .docx to .md and the headings in word are configured
> to be numbered, when I convert to .md those numbers are lost.
>
> I'd like to have something like this
>
> # 1 title
> ## 1.1 subtitle
>
> ## 1.2 subtitle
>
> # 2 title
>
> ### 2.1.1 subsbutitle
>
> as output, where the numbers are not explicitly part of the docx raw
> text input, but could be appended in same way as --number-sections adds
> it to other formats
Here's a Lua filter that should do what you need. See
https://pandoc.org/lua-filters.html for details.
``` lua
function Pandoc (doc)
doc.blocks = pandoc.utils.make_sections(true, nil, doc.blocks):walk {
Div = function (div)
if div.attributes.number then
-- first child should be a heading
local header = div.content[1]
header.content = {div.attributes.number, pandoc.Space()}
.. header.content
header.attributes.number = nil
return div.content
end
end
}
return doc
end
```
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124