summaryrefslogtreecommitdiff
path: root/huh.lua
blob: 8f834aba1e046621b41c1e5ac9d84d1f9bb0ecd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)