commit | author | age
|
f2839f
|
1 |
-- Dieses Skript iteriert durch die übergebenen Markdown-Dateien |
JUH |
2 |
-- und verändert die Gliederungstiefe der Überschrift |
|
3 |
-- anhand der Ordnertiefe. |
|
4 |
-- Es wird als Reader aufgerufen mit der --from/-f Option: |
|
5 |
-- pandoc -f project.lua |
|
6 |
-- |
|
7 |
-- Danke an Albert Krewinkel aus der pandoc Mailingliste |
|
8 |
|
|
9 |
local format = 'markdown+smart' |
|
10 |
|
|
11 |
function Reader (sources, opts) |
|
12 |
local doc = pandoc.Pandoc{} |
|
13 |
for _, source in ipairs(sources) do |
|
14 |
local path_components = #pandoc.path.split(source.name) |
|
15 |
-- last path component is the filename |
|
16 |
local depth = path_components - 1 |
|
17 |
doc = doc .. pandoc.read(source, format, opts):walk { |
|
18 |
Header = function (h) |
|
19 |
h.level = h.level + depth |
|
20 |
return h |
|
21 |
end |
|
22 |
} |
|
23 |
end |
|
24 |
return doc |
|
25 |
end |
|
26 |
|
|
27 |
if PANDOC_VERSION <= {2, 18} then |
|
28 |
local mt = debug.getmetatable(pandoc.Pandoc{}) |
|
29 |
mt.__concat = function (a, b) |
|
30 |
local result = pandoc.Pandoc(a.blocks, a.meta) |
|
31 |
result.blocks:extend(b.blocks) |
0677b7
|
32 |
for k, v in pairs(b.meta) do |
f2839f
|
33 |
result.meta[k] = v |
JUH |
34 |
end |
|
35 |
return result |
|
36 |
end |
|
37 |
end |
|
38 |
|