File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def extract_anchors(html)
177
177
anchors = Set . new
178
178
html . scan ( /<h\d \s +id="([^"]+)/ ) . flatten . each do |anchor |
179
179
if anchors . member? ( anchor )
180
- puts "*** DUPLICATE ID: #{ anchor } , please make sure that there are no headings with the same name at the same level."
180
+ puts "*** DUPLICATE ID: ' #{ anchor } ' , please make sure that there are no headings with the same name at the same level."
181
181
else
182
182
anchors << anchor
183
183
end
Original file line number Diff line number Diff line change @@ -35,16 +35,15 @@ def render(body)
35
35
def dom_id ( nodes )
36
36
dom_id = dom_id_text ( nodes . last . text )
37
37
38
- # Fix duplicate node by prefix with its parent node
38
+ # Fix duplicate dom_ids by prefixing the parent node dom_id
39
39
if @node_ids [ dom_id ]
40
40
if @node_ids [ dom_id ] . size > 1
41
41
duplicate_nodes = @node_ids . delete ( dom_id )
42
- new_node_id = " #{ duplicate_nodes [ -2 ] [ :id ] } - #{ duplicate_nodes . last [ :id ] } "
42
+ new_node_id = dom_id_with_parent_node ( dom_id , duplicate_nodes [ -2 ] )
43
43
duplicate_nodes . last [ :id ] = new_node_id
44
44
@node_ids [ new_node_id ] = duplicate_nodes
45
45
end
46
-
47
- dom_id = "#{ nodes [ -2 ] [ :id ] } -#{ dom_id } "
46
+ dom_id = dom_id_with_parent_node ( dom_id , nodes [ -2 ] )
48
47
end
49
48
50
49
@node_ids [ dom_id ] = nodes
@@ -60,6 +59,14 @@ def dom_id_text(text)
60
59
. gsub ( /\s +/ , "-" )
61
60
end
62
61
62
+ def dom_id_with_parent_node ( dom_id , parent_node )
63
+ if parent_node
64
+ [ parent_node [ :id ] , dom_id ] . join ( "-" )
65
+ else
66
+ dom_id
67
+ end
68
+ end
69
+
63
70
def engine
64
71
renderer = @epub ? EpubRenderer : Renderer
65
72
@engine ||= Redcarpet ::Markdown . new ( renderer ,
You can’t perform that action at this time.
0 commit comments