git.iko.soy/typeable/pandoc
on 2.1.3 help sign in
typeable/pandoc/tools/update-readme.lua
38 lines 1.4 kB history raw
1-- update README.md based on MANUAL.txt
2-- assumes that the README.md has a div with id 'description'.
3-- this gets replaced by the contents of the 'description' section
4-- of the manual.
6function Div(elem)
7 if elem.classes[1] and elem.classes[1] == 'description' then
8 local f = assert(io.open("MANUAL.txt", "r"))
9 local manual = f:read("*all")
10 f:close()
11 local description = {}
12 local i = 1
13 local include = false
14 local mdoc = pandoc.read(manual, "markdown")
15 local blocks = mdoc.blocks
16 while blocks[i] do
17 if blocks[i].t == 'Header' then
18 include = false
19 end
20 if include then
21 table.insert(description, pandoc.walk_block(blocks[i],
22 -- remove internal links
23 { Link = function(el)
24 if el.target:match("^#") then
25 return el.content
26 end
27 end }))
28 end
29 if blocks[i].t == 'Header' and
30 blocks[i].identifier == 'description' then
31 include = true
32 end
33 i = i + 1
34 end
35 return pandoc.Div(description, pandoc.Attr("description",{},{}))
36 end
37end