diff options
Diffstat (limited to 'support')
29 files changed, 418 insertions, 73 deletions
diff --git a/support/make4ht/README b/support/make4ht/README index 78ec73056c..8851c4d99f 100644 --- a/support/make4ht/README +++ b/support/make4ht/README @@ -888,14 +888,12 @@ modules options - : additional command line options for the Makeindex command. ### The `xindex` command options - : additional command line options for the Xindex command. language diff --git a/support/make4ht/changelog.tex b/support/make4ht/changelog.tex index 13effe5fd0..9752285cf3 100644 --- a/support/make4ht/changelog.tex +++ b/support/make4ht/changelog.tex @@ -3,12 +3,112 @@ \begin{itemize} \item + 2020/09/07 + + \begin{itemize} + \tightlist + \item + version \texttt{0.3f} released. + \end{itemize} +\item + 2020/08/26 + + \begin{itemize} + \tightlist + \item + \texttt{fixinlines} DOM filter: added + \texttt{\textless{}a\textgreater{}} element into list of inline + elements. + \end{itemize} +\item + 2020/08/24 + + \begin{itemize} + \tightlist + \item + initialize attributes in new element in \texttt{mathmlfixes} DOM + extension. + \end{itemize} +\item + 2020/07/18 + + \begin{itemize} + \tightlist + \item + changed CSS for the HTML documentation. + \end{itemize} +\item + 2020/07/17 + + \begin{itemize} + \tightlist + \item + fixed bug in index parsing. + \end{itemize} +\item + 2020/07/10 + + \begin{itemize} + \tightlist + \item + use the \texttt{joincharacters} DOM filter for TEI output. + \end{itemize} +\item + 2020/07/08 + + \begin{itemize} + \tightlist + \item + don't fail when filename cannot be detected in + \texttt{make4ht-errorlogparser.lua}. + \end{itemize} +\item + 2020/05/27 + + \begin{itemize} + \tightlist + \item + test if copied file exists in \texttt{mkutils.cp}. + \end{itemize} +\item + 2020/05/19 + + \begin{itemize} + \tightlist + \item + fixed image filename replace in \texttt{dvisvgm\_hashes} extension. + \end{itemize} +\item + 2020/05/16 + + \begin{itemize} + \tightlist + \item + fixed HTML filename matching in extensions. + \end{itemize} +\item + 2020/05/08 + + \begin{itemize} + \tightlist + \item + use global environment in the build files. + \end{itemize} +\item + 2020/03/03 + + \begin{itemize} + \tightlist + \item + added \texttt{jats} format. + \end{itemize} +\item 2020/02/28 \begin{itemize} \tightlist \item - version \texttt{0.3e\ released} + version \texttt{0.3e\ released}. \end{itemize} \item 2020/02/24 diff --git a/support/make4ht/domfilters/make4ht-fixinlines.lua b/support/make4ht/domfilters/make4ht-fixinlines.lua index 25489f59ca..d1b11b123e 100644 --- a/support/make4ht/domfilters/make4ht-fixinlines.lua +++ b/support/make4ht/domfilters/make4ht-fixinlines.lua @@ -1,4 +1,5 @@ local inline_elements = { + a=true, b=true, big=true, i=true, diff --git a/support/make4ht/domfilters/make4ht-mathmlfixes.lua b/support/make4ht/domfilters/make4ht-mathmlfixes.lua index a52b0e5d6b..3e044b9445 100644 --- a/support/make4ht/domfilters/make4ht-mathmlfixes.lua +++ b/support/make4ht/domfilters/make4ht-mathmlfixes.lua @@ -28,6 +28,7 @@ local function fix_nested_mstyle(el) -- if parent doesn't have the mathvariant attribute copy it from <mstyle> if not parent:get_attribute("mathvariant") then local mathvariant = el:get_attribute("mathvariant") + parent._attr = parent._attr or {} parent:set_attribute("mathvariant", mathvariant) end -- copy the contents of <mstyle> to the parent element diff --git a/support/make4ht/extensions/make4ht-ext-common_domfilters.lua b/support/make4ht/extensions/make4ht-ext-common_domfilters.lua index 63232b22ce..802902d48d 100644 --- a/support/make4ht/extensions/make4ht-ext-common_domfilters.lua +++ b/support/make4ht/extensions/make4ht-ext-common_domfilters.lua @@ -27,7 +27,7 @@ function M.modify_build(make) count = 2 else local process = filter {"fixinlines", "idcolons", "joincharacters", "mathmlfixes", "tablerows","booktabs"} - make:match("html$", process) + make:match("html?$", process) count = 1 end return make diff --git a/support/make4ht/extensions/make4ht-ext-common_filters.lua b/support/make4ht/extensions/make4ht-ext-common_filters.lua index 513fbed34e..9b3e7f3f74 100644 --- a/support/make4ht/extensions/make4ht-ext-common_filters.lua +++ b/support/make4ht/extensions/make4ht-ext-common_filters.lua @@ -11,7 +11,7 @@ function M.test(format) end function M.modify_build(make) - make:match("html$", process) + make:match("html?$", process) local matches = make.matches -- the filters should be first match to be executed, especially if tidy -- should be executed as well diff --git a/support/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua b/support/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua index 87f58abd57..8bf82e0588 100644 --- a/support/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua +++ b/support/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua @@ -244,11 +244,11 @@ function M.modify_build(make) -- fix src attributes local process = filter { - function(str) - return str:gsub('src="([^"]+)', function(filename) + function(str, filename) + return str:gsub('src=["\'](.-)(["\'])', function(filename, endquote) local newname = output_map[filename] or filename log:debug("newname", newname) - return 'src="'.. newname + return 'src=' .. endquote .. newname .. endquote end) end } diff --git a/support/make4ht/extensions/make4ht-ext-join_colors.lua b/support/make4ht/extensions/make4ht-ext-join_colors.lua index 182661fbdb..4d72b0e15b 100644 --- a/support/make4ht/extensions/make4ht-ext-join_colors.lua +++ b/support/make4ht/extensions/make4ht-ext-join_colors.lua @@ -10,7 +10,7 @@ end function M.modify_build(make) local process = filter {"joincolors"} - make:match("html$", process) + make:match("html?$", process) return make end return M diff --git a/support/make4ht/extensions/make4ht-ext-mathjaxnode.lua b/support/make4ht/extensions/make4ht-ext-mathjaxnode.lua index cbad897d4e..c2c4928aeb 100644 --- a/support/make4ht/extensions/make4ht-ext-mathjaxnode.lua +++ b/support/make4ht/extensions/make4ht-ext-mathjaxnode.lua @@ -9,7 +9,7 @@ end function M.modify_build(make) local mathjax = filter { "mathjaxnode"} - make:match("html$",mathjax) + make:match("html?$",mathjax) return make end diff --git a/support/make4ht/extensions/make4ht-ext-tidy.lua b/support/make4ht/extensions/make4ht-ext-tidy.lua index b381a05a8f..8318a8b894 100644 --- a/support/make4ht/extensions/make4ht-ext-tidy.lua +++ b/support/make4ht/extensions/make4ht-ext-tidy.lua @@ -38,7 +38,7 @@ end function M.modify_build(make) - make:match("html$", function(filename, par) + make:match("html?$", function(filename, par) local settings = get_filter_settings "tidy" or {} par.options = par.options or settings.options or "-utf8 -w 512 -ashtml -q" local command = "tidy ${options} ${filename}" % par diff --git a/support/make4ht/formats/make4ht-jats.lua b/support/make4ht/formats/make4ht-jats.lua new file mode 100644 index 0000000000..13bcd86d41 --- /dev/null +++ b/support/make4ht/formats/make4ht-jats.lua @@ -0,0 +1,14 @@ +local M = {} +local xtpipeslib = require "make4ht-xtpipes" + +function M.prepare_parameters(settings, extensions) + settings.tex4ht_sty_par = settings.tex4ht_sty_par ..",jats" + settings = mkutils.extensions_prepare_parameters(extensions, settings) + return settings +end + +function M.prepare_extensions(extensions) + return extensions +end + +return M diff --git a/support/make4ht/formats/make4ht-tei.lua b/support/make4ht/formats/make4ht-tei.lua index f81953a8b3..660f6d49d8 100644 --- a/support/make4ht/formats/make4ht-tei.lua +++ b/support/make4ht/formats/make4ht-tei.lua @@ -1,6 +1,8 @@ local M = {} local xtpipeslib = require "make4ht-xtpipes" +local domfilter = require "make4ht-domfilter" + function M.prepare_parameters(settings, extensions) settings.tex4ht_sty_par = settings.tex4ht_sty_par ..",tei" settings = mkutils.extensions_prepare_parameters(extensions, settings) @@ -11,4 +13,19 @@ function M.prepare_extensions(extensions) return extensions end +function M.modify_build(make) + local process = domfilter { + "joincharacters" + } + + -- we use <hi> elements for characters styled using HTF fonts in TEI + -- use the `joincharacters` DOM filter to join them + filter_settings "joincharacters" { + charclasses = { hi=true, mn = true} + } + + make:match("xml$", process) + return make +end + return M diff --git a/support/make4ht/make4ht b/support/make4ht/make4ht index 50917bd57e..079c464ecd 100755 --- a/support/make4ht/make4ht +++ b/support/make4ht/make4ht @@ -29,7 +29,7 @@ make4ht [options] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex op"] -- set version number. the template should be replaced by the -- actual version number by the build script -local version = "v0.3e" +local version = "v0.3f" mkparams.version_number = version local args = mkparams.get_args() @@ -43,7 +43,7 @@ local mode = parameters.mode local build_file = parameters.build_file -- handle output formats -local allowed_output_formats = {xhtml = true, html5=true, odt = true, docbook=true, tei=true} +local allowed_output_formats = {xhtml = true, html5=true, odt = true, docbook=true, tei=true, jats=true} -- formatter is Lua library which must provide at least prepare_parameters -- and process_build_sequence functions local formatter diff --git a/support/make4ht/make4ht-doc.pdf b/support/make4ht/make4ht-doc.pdf Binary files differindex 371e3e3fb8..7399a5b879 100644 --- a/support/make4ht/make4ht-doc.pdf +++ b/support/make4ht/make4ht-doc.pdf diff --git a/support/make4ht/make4ht-errorlogparser.lua b/support/make4ht/make4ht-errorlogparser.lua index b48957c651..e536370ac9 100644 --- a/support/make4ht/make4ht-errorlogparser.lua +++ b/support/make4ht/make4ht-errorlogparser.lua @@ -1,7 +1,10 @@ local m = {} local function get_filename(chunk) - local filename = chunk:match("([^\n^%(]+)") + local filename = chunk:match("([^\n^%(]+)") + if not filename then + return false, "No filename detected" + end local first = filename:match("^[%./\\]+") if first then return filename end return false diff --git a/support/make4ht/make4ht-indexing.lua b/support/make4ht/make4ht-indexing.lua index a86fd139aa..eb9c9b5017 100644 --- a/support/make4ht/make4ht-indexing.lua +++ b/support/make4ht/make4ht-indexing.lua @@ -75,7 +75,7 @@ local parse_idx = function(content) if line:match("^\\beforeentry") then -- increment index entry number current_entry = current_entry + 1 - local file, dest = line:match("\\beforeentry{(.-)}{(.-)}") + local file, dest = line:match("\\beforeentry%s*{(.-)}{(.-)}") map[current_entry] = {file = file, dest = dest} elseif line:match("^\\indexentry") then -- replace the page number with the current diff --git a/support/make4ht/make4ht-odtfilter.lua b/support/make4ht/make4ht-odtfilter.lua deleted file mode 100644 index 97f0b8df67..0000000000 --- a/support/make4ht/make4ht-odtfilter.lua +++ /dev/null @@ -1,33 +0,0 @@ -local mkutils = require "mkutils" -local zip = require "zip" - - --- use function to change contents of the ODT file -local function update_odt(odtfilename, file_path, fn) - -- get name of the odt file - local odtname = mkutils.remove_extension(odtfilename) .. ".odt" - -- open and read contents of the requested file inside ODT file - local odtfile = zip.open(odtname) - local local_file = odtfile:open(file_path) - local content = local_file:read("*all") - local_file:close() - odtfile:close() - -- update the content using user function - content = fn(content) - -- write the updated file - local local_file_file = io.open(file_path,"w") - local_file_file:write(content) - local_file_file:close() - os.execute("zip " .. odtname .. " " .. file_path) - os.remove(file_path) -end - -Make:match("tmp$", function(name, par) - update_odt(name, "content.xml", function(content) - return content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity) - -- convert hexadecimal entity to Unicode - print(entity,utfchar(tonumber(entity, 16))) - return utfchar(tonumber(entity, 16)) - end) - end) -end) diff --git a/support/make4ht/mkutils.lua b/support/make4ht/mkutils.lua index a4f16fb71a..38a4966315 100644 --- a/support/make4ht/mkutils.lua +++ b/support/make4ht/mkutils.lua @@ -118,6 +118,9 @@ function cp(src,dest) local command = string.format('%s "%s" "%s"', cp_func, src, dest) if cp_func == "copy" then command = command:gsub("/",'\\') end log:info("Copy: "..command) + if not file_exists(src) then + log:error("File " .. src .. " doesn't exist") + end os.execute(command) end @@ -264,9 +267,11 @@ end local main_settings = {} main_settings.fonts = {} -local env = {} +-- use global environment in the build file +-- it used to be sandboxed, but it proved not to be useful at all +local env = _G ---{} --- We make sandbox for make script, all functions must be explicitely declared +-- explicitly enale some functions and modules in the sandbox -- Function declarations: env.pairs = pairs env.ipairs = ipairs diff --git a/support/make4ht/readme.tex b/support/make4ht/readme.tex index b221473e02..25c4b99064 100644 --- a/support/make4ht/readme.tex +++ b/support/make4ht/readme.tex @@ -950,19 +950,18 @@ table with names of additional \texttt{Xindy} modules to be used. \subsubsection{\texorpdfstring{The \texttt{makeindex} command}{The makeindex command}}\label{the-makeindex-command}} -options - -: additional command line options for the Makeindex command. +\begin{description} +\item[options] +additional command line options for the Makeindex command. +\end{description} \hypertarget{the-xindex-command}{% \subsubsection{\texorpdfstring{The \texttt{xindex} command}{The xindex command}}\label{the-xindex-command}} -options - -: additional command line options for the Xindex command. - \begin{description} +\item[options] +additional command line options for the Xindex command. \item[language] document language \end{description} diff --git a/support/tex4ebook/README b/support/tex4ebook/README index 796445674a..3634974ab8 100644 --- a/support/tex4ebook/README +++ b/support/tex4ebook/README @@ -81,7 +81,7 @@ But it is optional. You shouldn't need to modify your \TeX\ files `-f,--format (default epub)` -: Output format. Possible values are `epub`, `epub3` and `mobi`. +: Output format. Possible values are `epub`, `epub3`, `mobi`, `azw` and `azw3`. `-j,--jobname` @@ -304,7 +304,7 @@ Type - WARNING: filename.epub: item (OEBPS/foo.boo) exists in the zip file, but is not declared in the OPF file - Delete the `filename-(epub|epub3|mobi)` folder and `filename.epub`. Then + Delete the `filename-(epub|epub3|mobi|azw|azw3)` folder and `filename.epub`. Then run `tex4ebook` again. - WARNING(ACC-009): hsmmt10t.epub/OEBPS/hsmmt10tch17.xhtml(235,15): diff --git a/support/tex4ebook/changelog.tex b/support/tex4ebook/changelog.tex index 4cb5c8c7ca..f77423e85b 100644 --- a/support/tex4ebook/changelog.tex +++ b/support/tex4ebook/changelog.tex @@ -3,6 +3,60 @@ \begin{itemize} \item + 2020/09/07 + + \begin{itemize} + \tightlist + \item + released version \texttt{0.3b} + \end{itemize} +\item + 2020/08/26 + + \begin{itemize} + \tightlist + \item + fixed hiearchical structure in NCX TOC for chapters in backmatter + and appendix + \item + load \texttt{common\_domfilters} extension by default. + \end{itemize} +\item + 2020/07/09 + + \begin{itemize} + \tightlist + \item + addded \texttt{AZW} and \texttt{AZW3} format support. + \end{itemize} +\item + 2020/06/21 + + \begin{itemize} + \tightlist + \item + save \texttt{\textbackslash{}title} element + \item + save contents of \texttt{\textbackslash{}author} in macro directly + \end{itemize} +\item + 2020/06/15 + + \begin{itemize} + \tightlist + \item + remove child elements from elements that don't allow them in the OPF + and NCX file. + \end{itemize} +\item + 2020/03/14 + + \begin{itemize} + \tightlist + \item + explicitly list supported section types in the NCX table + \end{itemize} +\item 2019/11/01 \begin{itemize} diff --git a/support/tex4ebook/readme.tex b/support/tex4ebook/readme.tex index 13b064bf31..0fdb16c1c9 100644 --- a/support/tex4ebook/readme.tex +++ b/support/tex4ebook/readme.tex @@ -92,8 +92,8 @@ Specify make4ht build file\footnote{\url{https://github.com/michal-h21/make4ht\# Defaulf build file filename is \texttt{filename.mk4}, use this option if you use different filename. \item[\texttt{-f,-\/-format\ (default\ epub)}] -Output format. Possible values are \texttt{epub}, \texttt{epub3} and -\texttt{mobi}. +Output format. Possible values are \texttt{epub}, \texttt{epub3}, +\texttt{mobi}, \texttt{azw} and \texttt{azw3}. \item[\texttt{-j,-\/-jobname}] Specify the output file name, without file extension. \item[\texttt{-l,-\/-lua}] @@ -371,8 +371,9 @@ issues:}\label{common-validation-issues}} but is not declared in the OPF file \end{itemize} -Delete the \texttt{filename-(epub\textbar{}epub3\textbar{}mobi)} folder -and \texttt{filename.epub}. Then run \texttt{tex4ebook} again. +Delete the +\texttt{filename-(epub\textbar{}epub3\textbar{}mobi\textbar{}azw\textbar{}azw3)} +folder and \texttt{filename.epub}. Then run \texttt{tex4ebook} again. \begin{itemize} \item diff --git a/support/tex4ebook/tex4ebook b/support/tex4ebook/tex4ebook index ebd7485c2d..dc602c4e72 100755 --- a/support/tex4ebook/tex4ebook +++ b/support/tex4ebook/tex4ebook @@ -23,7 +23,7 @@ local tex4ht_sty_par="" local tex4ht_par="" local t4ht_par="" local latex_par="" -local output_formats={epub=true,mobi=true,epub3=true} +local output_formats={epub=true,mobi=true,epub3=true,azw=true, azw3=true} local executor=nil local tidy = false local include_fonts = false @@ -67,7 +67,7 @@ else end if args.version then - print "tex4ebook v0.3a" + print "tex4ebook v0.3b" return end @@ -129,7 +129,9 @@ log:status("Input file: ".. params.tex_file) local output_format = params.output_format -- use epub as default output_format output_format = output_format or "epub" -local extensions = ebookutils.load_extensions(params.extensions, output_format) +-- load common_domfilters extension by default +local extensions = ebookutils.add_extensions("+common_domfilters", params.extensions) +extensions = ebookutils.load_extensions(extensions, output_format) -- but also support tex4ebook!s own parameters local oldparams = { -- htlatex=latex_cmd diff --git a/support/tex4ebook/tex4ebook-doc.pdf b/support/tex4ebook/tex4ebook-doc.pdf Binary files differindex 1f95636713..942a92df29 100644 --- a/support/tex4ebook/tex4ebook-doc.pdf +++ b/support/tex4ebook/tex4ebook-doc.pdf diff --git a/support/tex4ebook/tex4ebook-exec_azw.lua b/support/tex4ebook/tex4ebook-exec_azw.lua new file mode 100644 index 0000000000..397292b648 --- /dev/null +++ b/support/tex4ebook/tex4ebook-exec_azw.lua @@ -0,0 +1,35 @@ +module(...,package.seeall) +local eb = require("tex4ebook-exec_epub") +local ebookutils = require("mkutils") +local log = logging.new "exec_azw" + +function prepare(params) + return eb.prepare(params) +end + +function run(out,params) + return eb.run(out, params) +end + +function writeContainer() + local ret = eb.writeContainer() + -- convert the epub file to azw + local epubpath = eb.basedir .. "/" .. eb.outputfile + + -- find the azw filename + local azwfile = eb.outputfile:gsub("epub$", "azw") + local azwdist = eb.destdir .. azwfile + local command = "kindlegen " .. epubpath .. " -o " .. azwfile + log:info("Pack azw ".. command) + local status, output = ebookutils.execute(command) + -- copy the azw file to the destination directory + -- the destination directory will be created by the epub writer, so it is possible to use + -- the cp function which doesn't try to create directory + ebookutils.cp(eb.basedir .. "/" .. azwfile, azwdist) + + return ret +end + +function clean() + return eb.clean() +end diff --git a/support/tex4ebook/tex4ebook-exec_azw3.lua b/support/tex4ebook/tex4ebook-exec_azw3.lua new file mode 100644 index 0000000000..33e8a1182c --- /dev/null +++ b/support/tex4ebook/tex4ebook-exec_azw3.lua @@ -0,0 +1,35 @@ +module(...,package.seeall) +local eb = require("tex4ebook-exec_epub") +local ebookutils = require("mkutils") +local log = logging.new "exec_azw" + +function prepare(params) + return eb.prepare(params) +end + +function run(out,params) + return eb.run(out, params) +end + +function writeContainer() + local ret = eb.writeContainer() + -- convert the epub file to azw + local epubpath = eb.basedir .. "/" .. eb.outputfile + + -- find the azw filename + local azwfile = eb.outputfile:gsub("epub$", "azw3") + local azwdist = eb.destdir .. azwfile + local command = "kindlegen " .. epubpath .. " -o " .. azwfile + log:info("Pack azw ".. command) + local status, output = ebookutils.execute(command) + -- copy the azw file to the destination directory + -- the destination directory will be created by the epub writer, so it is possible to use + -- the cp function which doesn't try to create directory + ebookutils.cp(eb.basedir .. "/" .. azwfile, azwdist) + + return ret +end + +function clean() + return eb.clean() +end diff --git a/support/tex4ebook/tex4ebook-exec_epub.lua b/support/tex4ebook/tex4ebook-exec_epub.lua index 52e2ab6134..b0ccee6202 100644 --- a/support/tex4ebook/tex4ebook-exec_epub.lua +++ b/support/tex4ebook/tex4ebook-exec_epub.lua @@ -5,6 +5,7 @@ local io = require("io") local log = logging.new("exec_epub") --local ebookutils = require("ebookutils") local ebookutils = require "mkutils" +local dom = require("luaxml-domobject") local outputdir_name="OEBPS" local metadir_name = "META-INF" local mimetype_name="mimetype" @@ -319,11 +320,123 @@ function pack_container() ebookutils.cp(basedir .."/"..outputfile, destdir .. outputfile) end +local function update_file(filename, fn) + -- update contents of a filename using function + local f = io.open(filename, "r") + local content = f:read("*all") + f:close() + local newcontent = fn(content) + local f = io.open(filename, "w") + f:write(newcontent) + f:close() +end + +local function fix_ncx_toc_levels(dom) + -- OK, this is a weird hack. The problem is that when \backmatter + -- follows \part, the subsequent chapters are listed under part + -- in the NCX TOC + -- I've added special element <navmark> to the ncx file to detect mark numbers. + -- chapters in backmatter should have empty mark number + + -- get current <navpoint> section type and mark number + local get_navpoint_info = function(navpoint) + local navmarks = navpoint:query_selector("navmark") + if navmarks and #navmarks > 0 then + -- we are interested only in the first navmark, because it contains the current navPoint info + local navmark = navmarks[1] + return navmark:get_attribute("type"), navmark:get_text() + end + return nil, "Cannot find navLabel" + end + + local fix_chapters = function(part) + -- move chapters from backmatter and appendix from the current part + -- find part position in the element list, it will be place where backmatter will be moved + local part_pos = part:find_element_pos() + 1 + local part_parent = part:get_parent() + -- child chapters + local children = part:get_children() + -- loop over children from back, where backmatter or appendix may be placed + for i = #children, 1, -1 do + local current = children[i] + local sect_type, mark = get_navpoint_info(current) + if sect_type then + -- remove spaces from mark + mark = mark:gsub("%s", "") + if sect_type == "appendix" or (sect_type == "chapter" and mark=="") then + -- move chapter at the same level as part, after part + -- the correct order will be kept, because we move from the back of the node list + -- and every new node is placed before previous added nodes + part_parent:add_child_node(current:copy_node(), part_pos) + current:remove_node() + else + -- break processing if we find normal chapter + break + end + end + end + end + + -- find the last part in the ncx table. it can contain incorrectly nested chapters + local parts = {} + for _, navpoint in ipairs(dom:query_selector("navMap navPoint")) do + -- we are not able to match just direct navPoint ancestors, so we will use this trick + if navpoint:get_parent():get_element_name() == "navMap" then + local sec_type, navmark = get_navpoint_info(navpoint) + if sec_type == "part" then table.insert(parts, navpoint) end + end + end + if #parts > 0 then + -- fix chapters in the last part + fix_chapters(parts[#parts]) + end + return dom +end + +local function clean_xml_files() + local opf_file = outputdir .. "/content.opf" + update_file(opf_file, function(content) + -- remove wrong elements from the OPF file + -- open opf file and create LuaXML DOM + local opf_dom = dom.parse(content) + -- remove child elements from elements that don't allow them + for _, el in ipairs(opf_dom:query_selector("dc|title, dc|creator")) do + -- get text content + local text = el:get_text() + -- replace element text with a new text node containing original text + el._children = {el:create_text_node(text)} + end + return opf_dom:serialize() + end) + local ncxfilename = outputdir .. "/" .. outputfilename .. ".ncx" + update_file(ncxfilename, function(content) + -- remove spurious spaces at the beginning + content = content:gsub("^%s*","") + local ncx_dom = dom.parse(content) + fix_ncx_toc_levels(ncx_dom) + -- remove child elements from <text> element + for _, el in ipairs(ncx_dom:query_selector("text")) do + local text = el:get_text() + -- replace element text with a new text node containing original text + el._children = {el:create_text_node(text)} + end + for _, el in ipairs(ncx_dom:query_selector("navPoint")) do + -- fix attribute names. this issue is caused by a LuaXML behavior + -- that makes all attributes lowercase + el._attr["playOrder"] = el._attr["playorder"] + el._attr["playorder"] = nil + end + return ncx_dom:serialize() + end) + +end function writeContainer() make_opf() + clean_xml_files() pack_container() end + local function deldir(path) for entry in lfs.dir(path) do if entry~="." and entry~=".." then diff --git a/support/tex4ebook/tex4ebook.4ht b/support/tex4ebook/tex4ebook.4ht index e623ac8bc2..6ee87ed3ae 100644 --- a/support/tex4ebook/tex4ebook.4ht +++ b/support/tex4ebook/tex4ebook.4ht @@ -157,7 +157,7 @@ href="#1" media-type="\a:CoverMimeType" />}} "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">\Hnewline}} %Get sanitized value of \title -%\def\Title{\Ref{TITLE+}} +\ifTag{TITLE+}{\def\Title{\LikeRef{TITLE+}}}{} % If title contains macros, SafeTitle should be configured % in the custom cfg file \NewConfigure{SafeTitle}[1]{\gdef\Title{#1}} @@ -255,7 +255,7 @@ href="#1" media-type="\a:CoverMimeType" />}} \def\navsection#1#2{ \ConfigureToc{#1}% {\expandafter\closelevels\expandafter{#2} - \a:NavSection\Ncx:Mark} + \def\curr:sect:type{#1}\a:NavSection\Ncx:Mark} {\c:NavSection} {} {\b:NavSection% @@ -361,16 +361,16 @@ href="#1" media-type="\a:CoverMimeType" />}} \Configure{toTocLink}{}{}% \Configure{NavSection}{\booltrue{tocnoempty}\HCode{\Hnewline<navPoint id="navPoint-}% \stepnavpoint\HCode{" playOrder="}% - \the\navpoint\HCode{">\Hnewline<navLabel>\Hnewline<text>}% + \the\navpoint\HCode{">\Hnewline<navLabel>\Hnewline<text><navmark type="\curr:sect:type">}% }{\HCode{</text>\Hnewline% </navLabel>\Hnewline}% \HCode{<content src="\navmapsrc" />}% -}{ }{\HCode{</navPoint>\Hnewline}} +}{\HCode{</navmark>}}{\HCode{</navPoint>\Hnewline}} % Meta inf \ncx:head % Book title \ncx:title -\tableofcontents%[part,chapter,likechapter,section,likesection,subsection,likesubsection]% +\tableofcontents[part,appendix,chapter,likechapter,appendixsec,section,likesection,appendixsubsec,subsection,likesubsection]% %Hack to get close tag working \HCode{</ncx>} \EndNoFonts diff --git a/support/tex4ebook/tex4ebook.sty b/support/tex4ebook/tex4ebook.sty index 27a46b756e..1b0114748c 100644 --- a/support/tex4ebook/tex4ebook.sty +++ b/support/tex4ebook/tex4ebook.sty @@ -144,12 +144,12 @@ \let\tf@orig@author\author \newcommand\tf@author[1]{% \tf@orig@author{#1}% - \let\Author\@author% + \def\Author{#1}% } \newcommand\tf@optauthor[2][]{% \tf@orig@author[#1]{#2}% - \let\Author\@author% + \def\Author{#2}% } % support optiona argument for \author as well |