* manipulating headline level
@ 2022-06-29 8:30 'juh' via pandoc-discuss
2022-06-29 12:08 ` Albert Krewinkel
0 siblings, 1 reply; 8+ messages in thread
From: 'juh' via pandoc-discuss @ 2022-06-29 8:30 UTC (permalink / raw)
To: Pandoc Mailinglist
[-- Attachment #1: Type: text/plain, Size: 926 bytes --]
Dear all,
I this use-case:
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?
So that the first headline in 01/01/00.md is regarded as '###' not as
'#'?
Or shall I go an other way and write a prebuild script that converts the headline
level in these files according to their position in the folder
hierarchy?
Any hints?
juh
--
Autoren-Homepage: ......... http://literatur.hasecke.com
Satiren & Essays: ......... http://www.sudelbuch.de
Privater Blog: ............ http://www.hasecke.eu
Netzliteratur-Projekt: .... http://www.generationenprojekt.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
2022-06-29 8:30 manipulating headline level 'juh' via pandoc-discuss
@ 2022-06-29 12:08 ` Albert Krewinkel
[not found] ` <87ilojbqsp.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2022-06-29 12:08 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Dear juh,
"'juh' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
[not found] ` <87ilojbqsp.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-06-29 16:18 ` BPJ
[not found] ` <CADAJKhAWO5D23ChNizSGSuO-ouwOibBFTs0MmyBwJPGpQZYsVg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: BPJ @ 2022-06-29 16:18 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 2720 bytes --]
Super cool!
Den ons 29 juni 2022 14:25Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
skrev:
> Dear juh,
>
> "'juh' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 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.
[-- Attachment #2: Type: text/html, Size: 4029 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
[not found] ` <CADAJKhAWO5D23ChNizSGSuO-ouwOibBFTs0MmyBwJPGpQZYsVg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-06-30 8:43 ` 'juh' via pandoc-discuss
2022-06-30 12:11 ` Albert Krewinkel
0 siblings, 1 reply; 8+ messages in thread
From: 'juh' via pandoc-discuss @ 2022-06-30 8:43 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 738 bytes --]
Dear Albert,
Am Wed, Jun 29, 2022 at 06:18:31PM +0200 schrieb BPJ:
> Super cool!
yes indeed. Tremendously neat.
This looks exactly what I need, but I don't use the dev
version of pandoc.
So when I call it like this:
pandoc -f script.lua -o test.html 00.md 01/00.md ...
I get:
Error running Lua:
input.lua:9: attempt to concatenate a Pandoc value (local 'doc')
stack traceback:
Is there a timeline for the dev version to become stable?
I can't adapt the script to be used with current stable.
TIA
juh
--
Autoren-Homepage: ......... http://literatur.hasecke.com
Satiren & Essays: ......... http://www.sudelbuch.de
Privater Blog: ............ http://www.hasecke.eu
Netzliteratur-Projekt: .... http://www.generationenprojekt.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
2022-06-30 8:43 ` 'juh' via pandoc-discuss
@ 2022-06-30 12:11 ` Albert Krewinkel
[not found] ` <871qv6bb4n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2022-06-30 12:11 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
"'juh' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> writes:
> [...] I don't use the dev version of pandoc.
>
> So when I call it like this:
>
> pandoc -f script.lua -o test.html 00.md 01/00.md ...
>
> I get:
>
> Error running Lua:
> input.lua:9: attempt to concatenate a Pandoc value (local 'doc')
> stack traceback:
Here's a polyfill for the missing feature. Adding it before or after
the other code should make the reader work with pandoc 2.18.
``` lua
if PANDOC_VERSION <= {2, 18} then
local mt = debug.getmetatable(pandoc.Pandoc{})
mt.__concat = function (a, b)
local result = pandoc.Pandoc(a.blocks, a.meta)
result.blocks:extend(b.blocks)
for k, v in ipairs(b.meta) do
result.meta[k] = v
end
return result
end
end
```
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
[not found] ` <871qv6bb4n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-06-30 14:10 ` 'Jan Ulrich Hasecke' via pandoc-discuss
[not found] ` <edfc1a65-e8ee-7e0e-f953-a4d75b19d8cb-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: 'Jan Ulrich Hasecke' via pandoc-discuss @ 2022-06-30 14:10 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Thank you Albert,
it works.
Now I have to finetune the folder hierarchy.
juh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
[not found] ` <edfc1a65-e8ee-7e0e-f953-a4d75b19d8cb-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
@ 2022-06-30 14:37 ` 'Jan Ulrich Hasecke' via pandoc-discuss
[not found] ` <da9e1abc-97aa-339f-0eb6-720a5072e653-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: 'Jan Ulrich Hasecke' via pandoc-discuss @ 2022-06-30 14:37 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
One thing.
A metadata block in the first included file is not interpreted.
My workaround is to use a metadata file.
juh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: manipulating headline level
[not found] ` <da9e1abc-97aa-339f-0eb6-720a5072e653-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
@ 2022-06-30 14:43 ` Albert Krewinkel
0 siblings, 0 replies; 8+ messages in thread
From: Albert Krewinkel @ 2022-06-30 14:43 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
"'Jan Ulrich Hasecke' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> writes:
> One thing.
>
> A metadata block in the first included file is not interpreted.
There was a typo in my code: `ipairs` should have been `pairs`.
Here's the fixed version:
``` lua
if PANDOC_VERSION <= {2, 18} then
local mt = debug.getmetatable(pandoc.Pandoc{})
mt.__concat = function (a, b)
local result = pandoc.Pandoc(a.blocks, a.meta)
result.blocks:extend(b.blocks)
for k, v in pairs(b.meta) do
result.meta[k] = v
end
return result
end
end
```
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-06-30 14:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 8:30 manipulating headline level 'juh' via pandoc-discuss
2022-06-29 12:08 ` Albert Krewinkel
[not found] ` <87ilojbqsp.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-06-29 16:18 ` BPJ
[not found] ` <CADAJKhAWO5D23ChNizSGSuO-ouwOibBFTs0MmyBwJPGpQZYsVg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-06-30 8:43 ` 'juh' via pandoc-discuss
2022-06-30 12:11 ` Albert Krewinkel
[not found] ` <871qv6bb4n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-06-30 14:10 ` 'Jan Ulrich Hasecke' via pandoc-discuss
[not found] ` <edfc1a65-e8ee-7e0e-f953-a4d75b19d8cb-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2022-06-30 14:37 ` 'Jan Ulrich Hasecke' via pandoc-discuss
[not found] ` <da9e1abc-97aa-339f-0eb6-720a5072e653-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2022-06-30 14:43 ` Albert Krewinkel
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).