Skip to content

Commit

Permalink
converters/h: Work around an issue and clean up the code
Browse files Browse the repository at this point in the history
Ref: #128
  • Loading branch information
hmdne committed Sep 18, 2024
1 parent a03d112 commit a6273d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/coradoc/input/html/converters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def convert(node, state = {})

# Note: treat_children won't run plugin hooks
def treat_children(node, state)
node.children.inject("") do |memo, child|
memo << treat(child, state)
end
node.children.map do |child|
treat(child, state)
end.join
end

def treat(node, state)
Converters.process(node, state)
end

def treat_children_coradoc(node, state)
node.children.inject([]) do |memo, child|
memo << treat_coradoc(child, state)
end.flatten.reject { |x| x == "" || x.nil? }
node.children.map do |child|
treat_coradoc(child, state)
end.flatten.reject { |x| x.to_s.empty? }
end

def treat_coradoc(node, state)
Expand Down
12 changes: 7 additions & 5 deletions lib/coradoc/input/html/converters/h.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def to_coradoc(node, state = {})
internal_anchor = treat_children_anchors(node, state)

if id.to_s.empty? && internal_anchor.size.positive?
id = internal_anchor.first.id
if internal_anchor.first.respond_to? :id
id = internal_anchor.first.id
end
end

level = node.name[/\d/].to_i
Expand All @@ -16,14 +18,14 @@ def to_coradoc(node, state = {})
end

def treat_children_no_anchors(node, state)
node.children.reject { |a| a.name == "a" }.inject([]) do |memo, child|
memo << treat_coradoc(child, state)
node.children.reject { |a| a.name == "a" }.map do |child|
treat_coradoc(child, state)
end
end

def treat_children_anchors(node, state)
node.children.select { |a| a.name == "a" }.inject([]) do |memo, child|
memo << treat_coradoc(child, state)
node.children.select { |a| a.name == "a" }.map do |child|
treat_coradoc(child, state)
end
end
end
Expand Down

0 comments on commit a6273d7

Please sign in to comment.