Skip to content

Commit

Permalink
Added nodynamicodt extension
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Feb 3, 2025
1 parent b222819 commit 7ce7f11
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

- 2025/02/03

- added the `nodynamicodt` extension. It removes dynamic content from ODT files.
https://puszcza.gnu.org.ua/bugs/?505#discussion

- 2025/01/15

- fixed handling of commands with number as optional arguments in the `make4ht-indexing` library.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ mjcli
add "mathjax" option on the command line (like `make4ht -f html5+mjcli filename.tex "mathjax"`).
See [the available settings](#mathjaxsettings).

nodynamicodt

: change dynamic content in ODT files (such as tables of contents or bibliographies) to text.

odttemplate

: it automatically loads the `odttemplate` filter (page \pageref{sec:odttemplate}).
Expand Down
52 changes: 52 additions & 0 deletions extensions/make4ht-ext-nodynamicodt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local M = {}

-- this extension covnerts links, tables of contents and other dynamic content in the ODT format to plain text

local filter = require "make4ht-domfilter"

-- this extension only works for the ODT format
M.test = function(format)
return format=="odt"
end

local function nodynamiccontent(dom)
for _,link in ipairs(dom:query_selector("text|a")) do
-- change links to spans
link._name = "text:span"
-- remove attributes
link._attr = {}

end
for _, bibliography in ipairs(dom:query_selector("text|bibliography")) do
-- remove links from bibliography
-- use div instead of bibliography
bibliography._name = "text:div"
-- remove bibliography-source elements
for _, source in ipairs(bibliography:query_selector("text:bibliography-source")) do
source:remove_node()
end
for _, index in ipairs(bibliography:query_selector("text|index-body")) do
-- use div instead of bibliography-entry
index._name = "text:div"
end

end
for _, toc in ipairs(dom:query_selector("text|table-of-content")) do
-- remove links from toc
-- use div instead of table-of-contents
toc._name = "text:div"
for _, entry in ipairs(toc:query_selector("text|index-body, text|index-title")) do
-- use div instead of table-of-contents-entry
entry._name = "text:div"
end
end
return dom
end

M.modify_build = function(make)
local process = filter({nodynamiccontent}, "nodynamiccontent")
Make:match("4oo$",process)
return make
end

return M

0 comments on commit 7ce7f11

Please # to comment.