From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30541 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Julien Dutant Newsgroups: gmane.text.pandoc Subject: Re: Use --number-sections with markdown output Date: Tue, 10 May 2022 06:59:55 -0700 (PDT) Message-ID: <62577c1f-efe5-45b5-ab27-1d8705643afen@googlegroups.com> References: <98ffebc1-b38b-43f5-8234-e222258abb95n@googlegroups.com> <87zgjpzp6j.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_790_1858472151.1652191195144" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35706"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBC5Y3356IYINZX7JSMDBUBGMZSRT2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue May 10 15:59:59 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f63.google.com ([209.85.161.63]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1noQP9-00095h-86 for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 10 May 2022 15:59:59 +0200 Original-Received: by mail-oo1-f63.google.com with SMTP id r25-20020a4abf19000000b0035e9d44514dsf8616142oop.0 for ; Tue, 10 May 2022 06:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=tsp9FaOjBpwEJWZM9h2s0TXSyaphAPZdaRGznsVk9Jk=; b=EHvsf3tHo0loUOuNy5mLusIoGLwrKoIJ65Fe3MGveBUC7MVT03d9qcWOYGSztsYc7z tCHJ+KOjRC8xcn8GwyEd1py0RAnQ9ynItr8GMcQ5AHqP6sQrrkVaDKy+XTi5ZW4A+tAg 2+lp3BknbyArf3qzfZayejW3mCwUPVB1ctYNUTb05Sg4GbAQ4aPlmQbKF1QOZUgN2k8F fUffxKTq7eBnvE1SEUvkiPEeLXFKtR6NJMQAdHYCLot5NZoiVlo1Re6VtPaZdVvlxYnT cpNiBPbC2l2U0YLqCOg5FqvIv32OU+uf3EEjuOW+JMXf+/d+AP6cXEgyXtIpZENFb7UT iqqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=tsp9FaOjBpwEJWZM9h2s0TXSyaphAPZdaRGznsVk9Jk=; b=Z3yoXXV7ZcjrTw7qwo0/6ScjO6PaIZFDhJqU2T4I5/kD993KH/r1RpQo4qP1xAV2aG IS6gqxN15WHoJAy0shnLKQAK3KiYkpKeSyicDPwaaVeeGh7lo4jNCUOaWqhXRuqXZog9 hrtC60RddWCAcrZFxlvkF9TZsmibpLwRH8f6F2yXb0Dqg1ZxtjtzgyTjso7C3Zer6nX6 qjZ2nCEkaOU7l2pgVACxxHLkIKbcmit7qaI7LUgqmatV1JY8OGcmrhSA6DLsYKtEcej+ +oc96uLWSdmxdtCurCmC7u0zP5fdkTYj/BQFY53SXMVEi0JCZU5uYO4lgds4d+JQpEWZ Rb9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=tsp9FaOjBpwEJWZM9h2s0TXSyaphAPZdaRGznsVk9Jk=; b=umdDiGYHIKtOwDpWCFD8nNAUUdzkQ76bcUultSxL7N1Gp6sYhgYq6BwRGCGGxkeIzs xabqMomUa2WHdIudPzt9fHVHFk84gDo9GV0JsdhEWObwXIe4WrtCQS5DGTuALJlrISkc /BRwctseufhfbhE8VJiATPk+3vamASjlyNsAHH9tcJSmVSfkSbtC2zHaWrANFfYc/ndv dzjTtu8ANuKH82G9uH/fU0ruvYnbtiPHex8+RSGL0I4iOwElugmMRKKbVOhv0kS+hr35 9I14nPlu+rFLpcoFz1qIBsrmqZhKWSQv50FTdgpkMMjrklTPIvVrxuHObiCKwcL5EM1Y mxTA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532APMk+x932U8X/lHO2l648yMaW/kh08illclmZaJckS5n3hpt9 tZ1eer0m60hr10D5MmGCzKM= X-Google-Smtp-Source: ABdhPJwtuQdG+Fuaje5daZuz4mOd1oo7GKgJtZzvu8oGyC5R6vFSH3JimaIQcGbTCk0l0xET92EnHw== X-Received: by 2002:a05:6870:23a7:b0:e2:9f08:3348 with SMTP id e39-20020a05687023a700b000e29f083348mr88795oap.255.1652191198258; Tue, 10 May 2022 06:59:58 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:aca:911:0:b0:325:dd36:9844 with SMTP id 17-20020aca0911000000b00325dd369844ls7080770oij.10.gmail; Tue, 10 May 2022 06:59:55 -0700 (PDT) X-Received: by 2002:a05:6808:6da:b0:325:9a3d:463c with SMTP id m26-20020a05680806da00b003259a3d463cmr98818oih.206.1652191195764; Tue, 10 May 2022 06:59:55 -0700 (PDT) In-Reply-To: <87zgjpzp6j.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: julien.dutant-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:30541 Archived-At: ------=_Part_790_1858472151.1652191195144 Content-Type: multipart/alternative; boundary="----=_Part_791_788117218.1652191195144" ------=_Part_791_788117218.1652191195144 Content-Type: text/plain; charset="UTF-8" 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 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. ------=_Part_791_788117218.1652191195144 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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....@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 config= ured
> 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 r= aw
> 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 =3D pandoc.utils.make_sections(true, nil, doc.blocks):walk= {
Div =3D function (div)
if div.attributes.number then
-- first child should be a heading
local header =3D div.content[1]
header.content =3D {div.attributes.number, pandoc.Space()}
.. header.content
header.attributes.number =3D nil
return div.content
end
end
}
return doc
end

```

--=20
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 &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_791_788117218.1652191195144-- ------=_Part_790_1858472151.1652191195144--