aboutsummaryrefslogtreecommitdiff
path: root/doc/lua-filters.md
diff options
context:
space:
mode:
authorMarc Schreiber <marc.schreiber@fh-aachen.de>2017-07-13 11:35:35 +0200
committerMarc Schreiber <marc.schreiber@fh-aachen.de>2017-07-13 11:51:40 +0200
commitf93d7d06f688654137b5e728601441881ff5aebf (patch)
treee36c6fe213491dfe97e3b9de47a773ebfff8c133 /doc/lua-filters.md
parent635f299b441e238ccd34e3ad61c5e36f0ca30067 (diff)
parent8b502dd50ff842bdbbf346a67a607d1a7905bda3 (diff)
downloadpandoc-f93d7d06f688654137b5e728601441881ff5aebf.tar.gz
Merge branch 'master' of https://github.com/jgm/pandoc into textcolor-support
Diffstat (limited to 'doc/lua-filters.md')
-rw-r--r--doc/lua-filters.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 145a1517f..34165a791 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -107,3 +107,40 @@ return {
end,
}
```
+
+### Extracting information about links
+
+This filter prints a table of all the URLs linked to
+in the document, together with the number of links to
+that URL.
+
+```lua
+links = {}
+
+function Link (el)
+ if links[el.target] then
+ links[el.target] = links[el.target] + 1
+ else
+ links[el.target] = 1
+ end
+ return el
+end
+
+function Doc (blocks, meta)
+ function strCell(str)
+ return {pandoc.Plain{pandoc.Str(str)}}
+ end
+ local caption = {pandoc.Str "Link", pandoc.Space(), pandoc.Str "count"}
+ local aligns = {pandoc.AlignDefault, pandoc.AlignLeft}
+ local widths = {0.8, 0.2}
+ local headers = {strCell "Target", strCell "Count"}
+ local rows = {}
+ for link, count in pairs(links) do
+ rows[#rows + 1] = {strCell(link), strCell(count)}
+ end
+ return pandoc.Doc(
+ {pandoc.Table(caption, aligns, widths, headers, rows)},
+ meta
+ )
+end
+```