From c505de59c022e2c02b6b220da0849a4e67394d6a Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Wed, 28 Jun 2017 15:31:42 +0200
Subject: [PATCH] Added link-table example to doc/lua-filters.md.

---
 doc/lua-filters.md | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

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
+```