git.iko.soy/typeable/pandoc
on master help sign in
lua-filters.md: add documentation for pandoc.List
commit5026dfaedf4a8043fd1d76c1b7da8880770f9255 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 1 Dec 2017, 17:14 (9 years ago) parent8473a15
2 files changed+128−10
doc/lua-filters.md+103 tools/update-lua-docs.lua+25−10
doc/lua-filters.md+103
@@ -1479,3 +1479,106 @@ storage. The "media bag" is used when pandoc is called with the
14791479
14801480 local diagram_url = "https://pandoc.org/diagram.jpg"
14811481 local contents = pandoc.mediabag.fetch(diagram_url, ".")
1482+
1483+# Module pandoc.List
1484+
1485+Pandoc\'s List type and helper methods
1486+
1487+## Metamethods
1488+
1489+[`pandoc.List:__concat (list)`]{#pandoc.List:__concat}
1490+
1491+: Concatenates two lists.
1492+
1493+ Parameters:
1494+
1495+ `list`:
1496+ : second list concatenated to the first
1497+
1498+ Returns: a new list containing all elements from list1 and
1499+ list2
1500+
1501+## Methods
1502+
1503+[`pandoc.List:clone ()`]{#pandoc.List:clone}
1504+
1505+: Returns a (shallow) copy of the list.
1506+
1507+[`pandoc.List:includes (needle, init)`]{#pandoc.List:includes}
1508+
1509+: Checks if the list has an item equal to the given needle.
1510+
1511+ Parameters:
1512+
1513+ `needle`:
1514+ : item to search for
1515+
1516+ `init`:
1517+ : index at which the search is started
1518+
1519+ Returns: true if a list item is equal to the needle, false
1520+ otherwise
1521+
1522+[`pandoc.List:find (needle, init)`]{#pandoc.List:find}
1523+
1524+: Returns the value and index of the first occurrence of the
1525+ given item.
1526+
1527+ Parameters:
1528+
1529+ `needle`:
1530+ : item to search for
1531+
1532+ `init`:
1533+ : index at which the search is started
1534+
1535+ Returns: first item equal to the needle, or nil if no such
1536+ item exists.
1537+
1538+[`pandoc.List:find_if (pred, init)`]{#pandoc.List:find_if}
1539+
1540+: Returns the value and index of the first element for which
1541+ the predicate holds true.
1542+
1543+ Parameters:
1544+
1545+ `pred`:
1546+ : the predicate function
1547+
1548+ `init`:
1549+ : index at which the search is started
1550+
1551+ Returns: first item for which \`test\` succeeds, or nil if
1552+ no such item exists.
1553+
1554+[`pandoc.List:extend (list)`]{#pandoc.List:extend}
1555+
1556+: Adds the given list to the end of this list.
1557+
1558+ Parameters:
1559+
1560+ `list`:
1561+ : list to appended
1562+
1563+[`pandoc.List:map (fn)`]{#pandoc.List:map}
1564+
1565+: Returns a copy of the current list by applying the given
1566+ function to all elements.
1567+
1568+ Parameters:
1569+
1570+ `fn`:
1571+ : function which is applied to all list items.
1572+
1573+[`pandoc.List:filter (pred)`]{#pandoc.List:filter}
1574+
1575+: Returns a new list containing all items satisfying a given
1576+ condition.
1577+
1578+ Parameters:
1579+
1580+ `pred`:
1581+ : condition items must satisfy.
1582+
1583+ Returns: a new list containing all items for which \`test\`
1584+ was true.
tools/update-lua-docs.lua+25−10
@@ -1,14 +1,26 @@
11local in_module_section = false
22
3−function pandoc_module_blocks()
4− local tmp_folder = os.tmpname()
5− os.remove(tmp_folder)
6− os.execute("mkdir -p " .. tmp_folder)
7− os.execute("ldoc -q -l tools -d " .. tmp_folder .. " data/pandoc.lua")
8− local module_file = io.open(tmp_folder .. "/index.html")
9− local module_html = module_file:read("*a")
10− local module_doc = pandoc.read(module_html, "html")
11− return module_doc.blocks
3+-- Generate tmp folder
4+local tmp_folder = os.tmpname()
5+os.remove(tmp_folder)
6+os.execute("mkdir -p " .. tmp_folder)
7+
8+function extend(list1, list2)
9+ for i = 1, #list2 do
10+ list1[#list1 + 1] = list2[i]
11+ end
12+end
13+
14+function module_blocks(module_filenames)
15+ local blocks = {}
16+ for _, filename in pairs(module_filenames) do
17+ os.execute("ldoc -q -l tools -d " .. tmp_folder .. " " .. filename)
18+ local module_file = io.open(tmp_folder .. "/index.html")
19+ local module_html = module_file:read("*a")
20+ local module_doc = pandoc.read(module_html, "html")
21+ extend(blocks, module_doc.blocks)
22+ end
23+ return blocks
1224end
1325
1426function Header (el)
@@ -21,7 +33,10 @@ function Header (el)
2133 end
2234 elseif el.identifier == "module-pandoc" then
2335 in_module_section = true
24− return pandoc_module_blocks()
36+ return module_blocks{'data/pandoc.lua'}
37+ elseif el.identifier == "module-pandoc.list" then
38+ in_module_section = true
39+ return module_blocks{'data/List.lua'}
2540 end
2641end
2742