From: Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Use --number-sections with markdown output
Date: Tue, 10 May 2022 11:42:45 +0200 [thread overview]
Message-ID: <87zgjpzp6j.fsf@zeitkraut.de> (raw)
In-Reply-To: <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
relayism <tamas.harkai-fWcQWCtGVWc@public.gmane.org> 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
next prev parent reply other threads:[~2022-05-10 9:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 8:30 relayism
[not found] ` <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-05-10 9:42 ` Albert Krewinkel [this message]
[not found] ` <87zgjpzp6j.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-05-10 13:59 ` Julien Dutant
[not found] ` <62577c1f-efe5-45b5-ab27-1d8705643afen-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-05-10 14:23 ` Bastien DUMONT
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zgjpzp6j.fsf@zeitkraut.de \
--to=albert+pandoc-9eawchwdxg8hfhg+jk9f0w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).