diff options
author | Karl Berry <karl@freefriends.org> | 2022-02-18 22:12:39 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-02-18 22:12:39 +0000 |
commit | 45c6e09eb8045e03b06158780f9fde21742d4cb3 (patch) | |
tree | 3503fb0d0e0a5c6006e13c2e33776210b9cabd9f /Master/texmf-dist/scripts | |
parent | a276123bbbc409023c9148d82eae1f94c79fdd13 (diff) |
tex4ebook (18feb22)
git-svn-id: svn://tug.org/texlive/trunk@62076 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/tex4ebook | 2 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua | 58 |
2 files changed, 37 insertions, 23 deletions
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 <a> 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 <li> elements to an <a> element, epubcheck reports -- error for text nodes that are direct child of <li> for _, el in ipairs(tocdom:query_selector("li")) do - local text = {} - local link -- save the <a> element + + local newa = el:create_element("a") + local newchildren = {newa} + -- we want to stop putting content as child of <a> 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 <li> to a new <a> element + if child:is_element() and child_name == "a" then + -- set id and href of the new <a> 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 <a> contents to the new <a> 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 <a> + keep_processing = false + newchildren[#newchildren+1] = child + elseif keep_processing == true then + -- put every node before <ol> or <ul> into the new <a> + newa:add_child_node(child:copy_node()) + else + newchildren[#newchildren+1] = child end end - if link then - local content = table.concat(text, " ") - -- remove the original text - link._children = {} - local text = link:create_text_node(content) - link:add_child_node(text) - end + -- set contents of <li> to be the new <a> + el._children = newchildren end return tocdom |