Skip to content
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

converters/h: Work around an issue and clean up the code #131

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading