aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-08-03 23:59:39 -0700
committerJohn MacFarlane <[email protected]>2022-08-03 23:59:39 -0700
commit0f80284c3d832a43c20f8b8e79fa7485c22c837e (patch)
tree622055274896dc18b7b0163bf3c0120a03efe73f
parent6ffc489395b5a8cee7ba38e74c079c7cff03864d (diff)
Convert tool/extract-changes.hs to a Lua filter.
-rw-r--r--Makefile2
-rwxr-xr-xtools/extract-changes.hs15
-rw-r--r--tools/extract-changes.lua18
3 files changed, 19 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 7518acc7d..b14818c2c 100644
--- a/Makefile
+++ b/Makefile
@@ -75,7 +75,7 @@ fix_spacing: ## Fix trailing newlines and spaces
for f in $(SOURCEFILES); do printf '%s\n' "`cat $$f`" | sed -e 's/ *$$//' > $$f.tmp; mv $$f.tmp $$f; done
changes_github: ## copy this release's changes in gfm
- pandoc --filter tools/extract-changes.hs changelog.md -t gfm --wrap=none --template tools/changes_template.html | sed -e 's/\\#/#/g' | pbcopy
+ pandoc --lua-filter tools/extract-changes.lua changelog.md -t gfm --wrap=none --template tools/changes_template.html | sed -e 's/\\#/#/g' | pbcopy
debpkg: ## create linux package
diff --git a/tools/extract-changes.hs b/tools/extract-changes.hs
deleted file mode 100755
index d0ef35888..000000000
--- a/tools/extract-changes.hs
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env stack
--- stack --stack-yaml=stack.yaml runghc --package pandoc-types
-
--- Extract changes from latest version in changelog.
-import Text.Pandoc.JSON
-
-main = toJSONFilter extractFirst
-
-extractFirst :: Pandoc -> Pandoc
-extractFirst (Pandoc meta bs) =
- let bs' = dropWhile (not . isSubhead) bs
- in Pandoc meta (takeWhile (not . isSubhead) (drop 1 bs'))
-
-isSubhead (Header 2 _ _) = True
-isSubhead _ = False
diff --git a/tools/extract-changes.lua b/tools/extract-changes.lua
new file mode 100644
index 000000000..5d19c8d03
--- /dev/null
+++ b/tools/extract-changes.lua
@@ -0,0 +1,18 @@
+-- Extract changes from latest version in changelog.
+
+function Pandoc(el)
+ local newblocks = {}
+ i = 1
+ while i <= #el.blocks and
+ not (el.blocks[i].t == "Header" and el.blocks[i].level == 2) do
+ i = i+1
+ end
+ while i <= #el.blocks do
+ i = i+1
+ if el.blocks[i].t == "Header" and el.blocks[i].level == 2 then
+ break
+ end
+ table.insert(newblocks, el.blocks[i])
+ end
+ return pandoc.Pandoc(newblocks)
+end