From 45c6e09eb8045e03b06158780f9fde21742d4cb3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 18 Feb 2022 22:12:39 +0000 Subject: tex4ebook (18feb22) git-svn-id: svn://tug.org/texlive/trunk@62076 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/doc/support/tex4ebook/changelog.tex | 37 +++++++++++++ .../doc/support/tex4ebook/tex4ebook-doc.pdf | Bin 85304 -> 85759 bytes Master/texmf-dist/scripts/tex4ebook/tex4ebook | 2 +- .../scripts/tex4ebook/tex4ebook-exec_epub3.lua | 58 +++++++++++++-------- .../tex/latex/tex4ebook/tex4ebook-epub3.4ht | 11 ++-- .../texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht | 2 +- 6 files changed, 81 insertions(+), 29 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/support/tex4ebook/changelog.tex b/Master/texmf-dist/doc/support/tex4ebook/changelog.tex index 607249691eb..7eaa4c85ec6 100644 --- a/Master/texmf-dist/doc/support/tex4ebook/changelog.tex +++ b/Master/texmf-dist/doc/support/tex4ebook/changelog.tex @@ -2,6 +2,43 @@ \section{Changes}\label{changes}} \begin{itemize} +\item + 2022/02/18 + + \begin{itemize} + \tightlist + \item + released version \texttt{0.3h}. + \end{itemize} +\item + 2022/01/13 + + \begin{itemize} + \tightlist + \item + fixed issue where child TOC elements were inserted into + \texttt{\textless{}a\textgreater{}} element. + \end{itemize} +\item + 2021/12/07 + + \begin{itemize} + \tightlist + \item + print space after section number in Epub 3 TOC. + \item + keep original elements in Epub 3 TOC. + \end{itemize} +\item + 2021/12/04 + + \begin{itemize} + \tightlist + \item + fixed support for + \href{https://github.com/michal-h21/tex4ebook/issues/85}{appendix + chapters in Epub 3}. + \end{itemize} \item 2021/11/08 diff --git a/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf b/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf index 0e061061602..7e8386af7a7 100644 Binary files a/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf and b/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf differ diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook b/Master/texmf-dist/scripts/tex4ebook/tex4ebook index b170da2ceeb..8f6c8aa3f73 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook @@ -67,7 +67,7 @@ else end if args.version then - print "tex4ebook v0.3g" + print "tex4ebook v0.3h" return end diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua index fc200bd8661..328acaae375 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua @@ -113,6 +113,12 @@ local function add_media_overlays(content) end +-- elements that shouldn't be put inside in TOC +local stop_toc_processing_elements = { + ol = true, + ul = true +} + local function remove_spurious_TOC_elements(tocdom) local function count_child_elements(el) -- count children elements of the current element @@ -127,36 +133,44 @@ local function remove_spurious_TOC_elements(tocdom) for _, el in ipairs(tocdom:query_selector("ol")) do if count_child_elements(el) == 0 then el:remove_node() - -- local newli = el:create_element("li") - -- local newspan = newli:create_element("span") - -- newli:add_child_node(newspan) - -- el:add_child_node(newli) end end -- place child elements of the
  • elements to an element, epubcheck reports -- error for text nodes that are direct child of
  • for _, el in ipairs(tocdom:query_selector("li")) do - local text = {} - local link -- save the element + + local newa = el:create_element("a") + local newchildren = {newa} + -- we want to stop putting content as child of when it + -- finds child TOC entries + local keep_processing = true for i, child in ipairs(el._children) do - if child:is_text() then - -- trim spurious spaces - local childtext = child._text:gsub("^%s*",""):gsub("%s*$","") - -- save the text for the later use - table.insert(text, childtext) - child:remove_node() - elseif child:is_element() and child:get_element_name() == "a" then - link = child - table.insert(text, child:get_text()) + child_name = child:get_element_name() + -- put contents of
  • to a new element + if child:is_element() and child_name == "a" then + -- set id and href of the new element, if it isn't set already + if not newa:get_attribute("href") then + local id = child:get_attribute("id") + local href = child:get_attribute("href") + newa:set_attribute("id", id) + newa:set_attribute("href", href) + end + -- copy contents to the new element + for _, x in ipairs(child._children or {}) do newa:add_child_node(x:copy_node()) end + + elseif stop_toc_processing_elements[child_name] then + -- don't put child toc entries to the new + keep_processing = false + newchildren[#newchildren+1] = child + elseif keep_processing == true then + -- put every node before
      or