summaryrefslogtreecommitdiff
path: root/support/make4ht/domfilters/make4ht-fixinlines.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support/make4ht/domfilters/make4ht-fixinlines.lua')
-rw-r--r--support/make4ht/domfilters/make4ht-fixinlines.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/support/make4ht/domfilters/make4ht-fixinlines.lua b/support/make4ht/domfilters/make4ht-fixinlines.lua
index d1b11b123e..02338505b7 100644
--- a/support/make4ht/domfilters/make4ht-fixinlines.lua
+++ b/support/make4ht/domfilters/make4ht-fixinlines.lua
@@ -41,15 +41,33 @@ local function fix_inlines(obj)
local settings = get_filter_settings "fixinlines"
local inline_elements = settings.inline_elements or inline_elements
local nodes = obj:get_path("html body")
+ local new = nil
obj:traverse_node_list(nodes, function(jej)
- if jej._type == "ELEMENT" then
- local name = string.lower(jej._name)
+ if jej._type == "ELEMENT" or jej._type == "TEXT" then
+ local name = string.lower(jej._name or "")
-- local parent = jej:get_parent_node()
- if inline_elements[name] then
- local new = obj:create_element("p" )
- new:add_child_node(obj:copy_node(jej))
- jej:replace_node(new)
+ if inline_elements[name] or jej._type == "TEXT" then
+ if not new then
+ -- start new paragraph
+ if jej._type == "TEXT" and jej._text:match("^%s+$") then
+ -- ignore parts that contain only whitespace and are placed before
+ -- paragraph start
+ else
+ new = obj:create_element("p" )
+ new:add_child_node(obj:copy_node(jej))
+ jej:replace_node(new)
+ end
+ else
+ -- paragraph already exists
+ new:add_child_node(obj:copy_node(jej))
+ jej:remove_node()
+ end
+ else
+ -- close the current paragraph before new block element
+ new = nil
end
+ else
+ new = nil
end
end)
return obj