From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30868 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: manipulating headline level Date: Wed, 29 Jun 2022 18:18:31 +0200 Message-ID: References: <87ilojbqsp.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000b72ff205e2988166" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26586"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBZHW6GKQMGQEQ2XWTTI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 29 18:18:47 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f64.google.com ([209.85.128.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o6aOt-0006hy-Nh for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 29 Jun 2022 18:18:47 +0200 Original-Received: by mail-wm1-f64.google.com with SMTP id p6-20020a05600c358600b003a0483b3c2esf5472866wmq.3 for ; Wed, 29 Jun 2022 09:18:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1656519527; cv=pass; d=google.com; s=arc-20160816; b=D21JaUNxYzY8aEs4iO33RsKLQ52DzH3hbacATnFndZiieYxjL2rItKRl6ErZLibEok enQ9M6twp/d93HmqMfqi//UTyGXMW24kCsUukosj2Tm+fnPQJZiExKnYrZEWQNw93e/F tgYR1Add3FLI1gjz6AELgA3YYqDnGLp0aEKbv3k6uyAFt96S4+l625k/qSQ9J6E231JB 1gyfSNwF7nH65MqOnw5qdrtzmHIPv7gSYD4mQMmH3KU2yNHydaFLIKViZKjk3MoEcpD+ I58c4bTMfeXrNSAi9AZeAKzdSm4HGgZxR0bOTlbTmC9lVGOyjG4/NfEiSc32ks3kH3ML lOjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date :from:in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=iyXKc8rvSNuQZGpCMXmWyNmQWYe9tj9f8IXdClT6tRA=; b=kMtBBPRU/EiDFA0Koax7/PG8Qru9c6vUBTG7Ai7tLxjdHBAvkowkxiBnVqr2emHrsI 4QO3YkuV7aga9luZ/4TQT0tlSNs2H/fb/mpq2qwaVGpa3eEEv7oaTsTow8NqrmysyBeU F6MEmk5ZoV55R9KQED9qxIVWXmQlkIzjNzIR8y6xI+4KnZNO3NbsZ7JmCIdeMZcg8q1/ 9Od5IxcwYRn2ohhhUvlmpCIYZral1GXD+NawJt5teJDnQ8THjXGax4rapHL6nyUv1bnd Hwj937fxP2f+QL3LSJx7YBQS/JaWBcAtV3vRwl2kVy6onAoBiITznRObzDgDeJL0+d3H oeGg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oaBZy28U; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:mime-version:references:in-reply-to:from:date:message-id :subject:to:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=iyXKc8rvSNuQZGpCMXmWyNmQWYe9tj9f8IXdClT6tRA=; b=CqFY6EFRpo9sR7qPx5RKf7iJuoeME7vLr2Dc+o2Ijd7BMNN6BOyu/7uVOwqAXLHm+z +FgP6SYb1825sCu62M/0WgZvuOX/HJ60zrpP8S9oLqHR4sqGaJancp4q5H6AabXzRL6u gjW5YnUSKn2HA2+6+kU9uS42e3uwe871cVHdOBH+kNuNdL/HUz2xZywHWs2vgi3bMi4e f/jmxv2OQHbB86PYPHWcbn0GAg6dpE6DQPlUnSk0WuaV59MmIQrWv2jFc6DUJ4YWiBhD 6xbR0uQzFDZjfa37CKSR3wK8GJ53i165OLiqJEggXa/oNxa1VepMfIGWbxtvp0+ESxxD Y6ng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iyXKc8rvSNuQZGpCMXmWyNmQWYe9tj9f8IXdClT6tRA=; b=KK33SmQ+t94ylm3gsNIqMtNBMq1uJTK3YBUqyVAYYAS+Gz8qg99LSlTWL2nHS8ieQL kZ5HZKCT86w2sk3ZZvTRs5Zup2HrphUzD4y1ckJSKgZ/BA4zbS6cAeGjj7rDlUp+KkeX h88xQwOCN9smrQASx8ldY9kHHi4/sTb1c3j+rIHSeSOnY2ho8zhuXM8l/3XIv1rv3mdt rgBbMdq0NS3VrKi/NDAjYK8sDgDQAPlxMDZdyAoyKlJZ8HAdhC5bIZa1bvUPg38zedX3 GUc16oaZ6vXezp+ENlG6wMexBSb+VYd6rCw4ZsdBktbT4PT+7j9bfTL/17nhUoDW3oNH 5iyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:mime-version:references:in-reply-to:from :date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iyXKc8rvSNuQZGpCMXmWyNmQWYe9tj9f8IXdClT6tRA=; b=dpfNPgln0o+RACqflVNA4b3JPMvw24OHx0mxP6bnL0j0x0VrAU+QKpA48ghdb7FpQx cqw7LhU2uOqCb8f6UQ/1d9Psphp43ncXf8d55kpO9vnLcF12h8ymG+s1hxZrmMd5HCVP i7D07k3uNdHnyjEfoqMNlqCfCKef4gtCDx4wewpYaN8qvulZ/caUIXRZf9DIQY1PD809 /fHDaLct5INWaQGySOGyprade+ARBoZdcyN99/wAmqS+TwUikYkqV0NiRkoVEjXtXG4W IDqfFw+zezl9z9rlh6VK5pu4DJojTMnTkwPsJ/bWsIxiwsnZNlLIPd7mbp3UDNQkpwsE XtqQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AJIora95CVwRNNSypUzgXvSh1GddmDmypuzBnZ33V0KyFcElJzWcywF+ PJfzNYVBJzjvV+V4aXQYM+Y= X-Google-Smtp-Source: AGRyM1tpsa6yUK3EJ89pYThSg8Sr1RoHT7zRpkAhMRIa4RqsKdnlD7I2UN+cZ3pkWKbsIHzF/uMlvQ== X-Received: by 2002:a05:6000:144a:b0:21b:c9bc:ec87 with SMTP id v10-20020a056000144a00b0021bc9bcec87mr4190398wrx.178.1656519527023; Wed, 29 Jun 2022 09:18:47 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a5d:6d88:0:b0:21d:338c:fc18 with SMTP id l8-20020a5d6d88000000b0021d338cfc18ls167584wrs.2.gmail; Wed, 29 Jun 2022 09:18:43 -0700 (PDT) X-Received: by 2002:a5d:44ca:0:b0:21b:8998:43e7 with SMTP id z10-20020a5d44ca000000b0021b899843e7mr4086115wrr.613.1656519523166; Wed, 29 Jun 2022 09:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656519523; cv=none; d=google.com; s=arc-20160816; b=aduO6uxJSj62/bX677RrpYY/ywwiq8sXqRlmOjigL++pF++EqSl9boRZLUNppclIFY ioPmYyBKglWRXvlPKwEm3eRO2xuG12HkawFgb5lE4uJYbcueMPjw2wvrbiv53aIwcA8I xcMahNm/mtZH/JKVE6QfkkDuVQPmBSKWKoAmiwY5tLTANP8lWLeMd7Ae3enhgjcK1jE9 nkzaDnLDMKwwxSlpBJIAL2CyfuOJ/86QqneBfOXiV/0jaJVXeiRZqhXFOPZswkdfOMim n5lM1800RN9nsbNniEyUgMfqF2DbZPnw+lMOGJDGaEm9lkubsY2MWiRRCdUwFAv0aAZG 9FJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=jjHV4SryqSfulCYGHwnzr05skdImQULl9Ll9NQJ0BAw=; b=U0ddmk/tzY2X1l34w6aY9MbPqZ+4BCEuU68XADOq6djIZcbU6VaJxdyto/cuXzStRd 1tYdNZWrxROZBi11Zni+UJGXfzBirMexU/c9CE+ud33RWl41Eiu6EL898wdHd0XI2RI0 98yoM6SuTcyVChK/n37+f50ymKYqIp/y6Yku2l1RKxZMS39a8umtb5dXoTYDMDyRtO4O VHS+P/uUDbV8alCwGMkkWvX25bzo/wXC4cdeEF92AY4BHbk62FisLOJzq5zBw/IxYZ0n gx2mVBNs/GX5nQeTYQpOw10tJ2lsd86Buq7/N8VuD9VofPsAvAQQDg+zJgLEEIomWb6g xV+A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oaBZy28U; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com. [2a00:1450:4864:20::62c]) by gmr-mx.google.com with ESMTPS id a1-20020a05600c348100b003a0312d8760si312410wmq.2.2022.06.29.09.18.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jun 2022 09:18:43 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) client-ip=2a00:1450:4864:20::62c; Original-Received: by mail-ej1-x62c.google.com with SMTP id d2so21875586ejy.1 for ; Wed, 29 Jun 2022 09:18:43 -0700 (PDT) X-Received: by 2002:a17:906:378e:b0:726:38df:6f75 with SMTP id n14-20020a170906378e00b0072638df6f75mr3884629ejc.577.1656519522724; Wed, 29 Jun 2022 09:18:42 -0700 (PDT) In-Reply-To: <87ilojbqsp.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oaBZy28U; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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:30868 Archived-At: --000000000000b72ff205e2988166 Content-Type: text/plain; charset="UTF-8" Super cool! Den ons 29 juni 2022 14:25Albert Krewinkel skrev: > Dear juh, > > "'juh' via pandoc-discuss" writes: > > > Many markdown-files hierarchically ordered in folders. > > Every file starts with the top-level headline mark "#". > > > > I want to convert these files like this: > > > > pandoc $(cat outline.txt) -o target.html > > > > where outline.txt contains the relative pathes to all files. > > > > > > 00.md > > 01/00.md > > 01/01/00.md > > 01/01/01.md > > 01/01/02.md > > > > Is there a way to tell pandoc that it should regard the headline levels > > according to the folder structure? > > Pandoc can't do this out of the box, but you could use a custom reader > to correct the headings. The below requires the current dev version > (nightly build), but could be rewritten to work with a released version, > too. > > The script > > - iterates over all input files, > - parses their contents as a separate document, > - shifts headers in each document by the number of subdirs the > respective file is in, and > - concatenates the individual per-file documents into a single > document that is then returned. > > Pass the reader file to pandoc via the `--from` parameter. > > ``` lua > local format = 'markdown+smart' > > function Reader (sources, opts) > local doc = pandoc.Pandoc{} > for _, source in ipairs(sources) do > local path_components = #pandoc.path.split(source.name) > -- last path component is the filename > local depth = path_components - 1 > doc = doc .. pandoc.read(source, format, opts):walk { > Header = function (h) > h.level = h.level + depth > return h > 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/87ilojbqsp.fsf%40zeitkraut.de > . > -- 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/CADAJKhAWO5D23ChNizSGSuO-ouwOibBFTs0MmyBwJPGpQZYsVg%40mail.gmail.com. --000000000000b72ff205e2988166 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Super cool!

Den ons 29 juni 2022 14:25Albert Krewinkel &l= t;albert+pandoc@zeitkraut.d= e> skrev:
Dear juh,

"'juh' via pandoc-discuss" <pandoc-discus= s@googlegroups.com> writes:

> Many markdown-files hierarchically ordered in folders.
> Every file starts with the top-level headline mark "#".
>
> I want to convert these files like this:
>
> pandoc $(cat outline.txt) -o target.html
>
> where outline.txt contains the relative pathes to all files.
>
>
> 00.md
> 01/00.md
> 01/01/00.md
> 01/01/01.md
> 01/01/02.md
>
> Is there a way to tell pandoc that it should regard the headline level= s
> according to the folder structure?

Pandoc can't do this out of the box, but you could use a custom reader<= br> to correct the headings. The below requires the current dev version
(nightly build), but could be rewritten to work with a released version, too.

The script

=C2=A0- iterates over all input files,
=C2=A0- parses their contents as a separate document,
=C2=A0- shifts headers in each document by the number of subdirs the
=C2=A0 =C2=A0respective file is in, and
=C2=A0- concatenates the individual per-file documents into a single
=C2=A0 =C2=A0document that is then returned.

Pass the reader file to pandoc via the `--from` parameter.

``` lua
local format =3D 'markdown+smart'

function Reader (sources, opts)
=C2=A0 local doc =3D pandoc.Pandoc{}
=C2=A0 for _, source in ipairs(sources) do
=C2=A0 =C2=A0 local path_components =3D #pandoc.path.split(source.name<= /a>)
=C2=A0 =C2=A0 -- last path component is the filename
=C2=A0 =C2=A0 local depth =3D path_components - 1
=C2=A0 =C2=A0 doc =3D doc .. pandoc.read(source, format, opts):walk {
=C2=A0 =C2=A0 =C2=A0 Header =3D function (h)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 h.level =3D h.level + depth
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return h
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 }
=C2=A0 end
=C2=A0 return doc
end
```

--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe=C2=A0 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
pandoc-discuss+unsubscribe@googlegroups.= com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-disc= uss/87ilojbqsp.fsf%40zeitkraut.de.

--
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/CADAJKhAWO5D23ChNizSGSuO-ouwOibBFTs0MmyBw= JPGpQZYsVg%40mail.gmail.com.
--000000000000b72ff205e2988166--