Starting from @WojtekMyszka's nice answer (you should take a little time away from your computer more often, @michal.h21), I dealt with these issues and some html cleanup issues of getting rid of empty <p class="indent></p>
elements, empty <a></a>
elements and empty <div></div>
elements. I missed the fact that you can invoke tidy
programmatically--I had been using the "-t" option which tidies a the end--and I think an earlier application of tidy
would make some of this a little more straightforward. Anyway, I like it because the "splicer" helper function is... well, helpful. I think it would be better lua programming practice to say return (s:gsub(from,to))
which I believe is the idiom to return only the first value from gsub
and discard the number of substitutions, but I didn't test it that way and this seems to work.
local filter = require "make4ht-filter"
local splicer = function(from,to)
return function(s)
return s:gsub(from,to)
end
end
--html fixes
local afix = splicer("<a%s*></a>","")
local pfix = splicer("<p%s+[^>]*>%s*</p>", "")
local divfix = splicer("<div%s+[^>]*>%s*</div>", "")
--take out the cover image display
local snipcover = splicer('<div class="cover%-image">.-</div>',"")
--css fix
local cssfix = splicer("%,%s*%{","{")
--opf fix
local insertguide = splicer("</package>",[[
<guide>
<reference type="toc" title="Contents" href="RefBookli1.html" />
<reference type="text" title="Preface" href="RefBookch1.html" />
</guide>
</package>]])
--ncx fix
local insertcontents = splicer('<navPoint id="navPoint%-1" playOrder="1">',[[
<navPoint id="navPoint-0" playOrder="0">
<navLabel>
<text>Contents</text>
</navLabel>
<content src="RefBookli1.html" />
</navPoint>
<navPoint id="navPoint-1" playOrder="1">]])
local htmlprocess = filter{afix, pfix, divfix, "nkcleanspan", "fixligatures", "hruletohr"}
local cssprocess = filter{cssfix}
local coverprocess = filter{snipcover}
local opfprocess = filter{insertguide}
local ncxprocess = filter{insertcontents}
Make:htlatex()
Make:htlatex()
Make:htlatex()
Make:match("html$",htmlprocess)
Make:match("^RefBook%.html$", coverprocess)
Make:match("css$",cssprocess)
Make:match("opf$",opfprocess)
Make:match("ncx$",ncxprocess)
As I mention in my comment above, it is pure luck that I could deal with the ncx TOC this way--it is possible to insert one extra element at the very beginning.
Anyway, I thought it was worth posting this because the more examples that people can see of working .mk4
files the better, I think.