* Use --number-sections with markdown output @ 2022-05-10 8:30 relayism [not found] ` <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: relayism @ 2022-05-10 8:30 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 927 bytes --] Hey! 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 Thanks! -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/98ffebc1-b38b-43f5-8234-e222258abb95n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1959 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Use --number-sections with markdown output [not found] ` <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2022-05-10 9:42 ` Albert Krewinkel [not found] ` <87zgjpzp6j.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Albert Krewinkel @ 2022-05-10 9:42 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <87zgjpzp6j.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Use --number-sections with markdown output [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> 0 siblings, 1 reply; 4+ messages in thread From: Julien Dutant @ 2022-05-10 13:59 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2059 bytes --] 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. J On Tuesday, May 10, 2022 at 10:56:28 AM UTC+1 Albert Krewinkel wrote: > > relayism <tamas....-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 > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/62577c1f-efe5-45b5-ab27-1d8705643afen%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 3180 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <62577c1f-efe5-45b5-ab27-1d8705643afen-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Use --number-sections with markdown output [not found] ` <62577c1f-efe5-45b5-ab27-1d8705643afen-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2022-05-10 14:23 ` Bastien DUMONT 0 siblings, 0 replies; 4+ messages in thread From: Bastien DUMONT @ 2022-05-10 14:23 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw It is the metamethod pandoc.List:__concat. Indeed, it would be good to add examples to the metamethods, since not all Lua users know about metatables, especially those who only learn the basics of the language to write filters! Le Tuesday 10 May 2022 à 06:59:55AM, Julien Dutant a écrit : > 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. > > J > > On Tuesday, May 10, 2022 at 10:56:28 AM UTC+1 Albert Krewinkel wrote: > > > relayism <tamas....-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 > [1]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 > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an email > to [2]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [3]https://groups.google.com/d/msgid/ > pandoc-discuss/62577c1f-efe5-45b5-ab27-1d8705643afen%40googlegroups.com. > > References: > > [1] https://pandoc.org/lua-filters.html > [2] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [3] https://groups.google.com/d/msgid/pandoc-discuss/62577c1f-efe5-45b5-ab27-1d8705643afen%40googlegroups.com?utm_medium=email&utm_source=footer -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/Ynp1a3s2QDrNq0yq%40localhost. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-05-10 14:23 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-05-10 8:30 Use --number-sections with markdown output relayism [not found] ` <98ffebc1-b38b-43f5-8234-e222258abb95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2022-05-10 9:42 ` Albert Krewinkel [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
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).