summaryrefslogtreecommitdiff
path: root/huh.lua
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-24 00:26:41 +0100
committerAki <please@ignore.pl>2023-01-24 00:26:41 +0100
commit581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0 (patch)
tree906fb830fb947936b5e1ccbc641dd699bfa9e5d0 /huh.lua
downloadhuh-581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0.zip
huh-581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0.tar.gz
huh-581de1e3c688ef9b4e0e4a13aabe1ad63d5762f0.tar.bz2
Sketch that appends elements to headHEADmaster
Diffstat (limited to 'huh.lua')
-rwxr-xr-xhuh.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/huh.lua b/huh.lua
new file mode 100755
index 0000000..8f834ab
--- /dev/null
+++ b/huh.lua
@@ -0,0 +1,21 @@
+#!/usr/bin/env lua
+local gumbo = require "gumbo"
+local config = require "pl.config"
+local args = require "pl.lapp" [[
+Generates an HTML document from another HTML document (huh?).
+
+Options:
+ -c, --config (default huh.conf) Configuration file
+ -h, --help Prints this help message to standard output
+
+Arguments:
+ <input> (optional string) HTML file to process
+]]
+local conf = assert(config.read(args.config))
+local document = assert(gumbo.parseFile(args.input or io.stdin))
+local head = assert(gumbo.parseFile(conf.head, {contextElement="head"}))
+for _, node in pairs(head.documentElement.childNodes) do
+ document:adoptNode(node)
+ document.head:insertBefore(node, document.head.firstChild)
+end
+document:serialize(io.stdout)