New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove anchor tag in xml #144
Comments
These anchors are usually created by Can you create a MWE that shows these extra anchors? |
Of course :) The following minimal example gives examples of different anchor tags when converting to docbook xml.
|
This local domfilter = require "make4ht-domfilter"
local process = domfilter {
function(dom)
local links = {}
for _, el in ipairs(dom:query_selector("link")) do
-- collect all links
links[el:get_attribute("xlink:href"):gsub("^#", "")] = true
end
for _, el in ipairs(dom:query_selector("anchor")) do
if not links[el:get_attribute("xml:id")] then
el:remove_node()
end
end
return dom
end
}
Make:match("xml$", process) It first saves all links, in order to keep anchors that some links point to. Then it loops over anchors and remove ones that no link points to. Unfortunately, I've found a bug in make4ht, so it is possible that it will fail for you, if you use any links in your document (for example using |
Thank you, this works fine! |
Great! So should I close this issue? |
I use make4ht to convert to docbook. In the resulting xml there are several anchor tags. Is there a way to remove/prevent these tags? (Some anchor tags are self-closing, and some are open-close pairs)
best regards
hcf
The text was updated successfully, but these errors were encountered: