Class: Kitabu::Footnotes::HTML
- Inherits:
-
Base
- Object
- Base
- Kitabu::Footnotes::HTML
show all
- Defined in:
- lib/kitabu/footnotes/html.rb
Instance Attribute Summary
Attributes inherited from Base
#content, #footnote_index, #html
Instance Method Summary
collapse
Methods inherited from Base
#increment_footnote_index!, #initialize, process
Instance Method Details
#process ⇒ Object
6
7
8
|
# File 'lib/kitabu/footnotes/html.rb', line 6
def process
html.css(".chapter").each(&method(:process_chapter))
end
|
#process_chapter(chapter) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/kitabu/footnotes/html.rb', line 10
def process_chapter(chapter)
= chapter.css(".footnotes").first
return unless
list = .css("ol").first
list.set_attribute "start",
chapter.css(".footnotes li").each do ||
(chapter, )
end
end
|
23
24
25
26
27
28
29
30
|
# File 'lib/kitabu/footnotes/html.rb', line 23
def (chapter, )
current_index = .get_attribute("id").gsub(/[^\d]/m, "")
.set_attribute "id", "fn#{}"
(chapter, current_index)
process_rev_links(chapter, current_index)
process_ref_elements(chapter, current_index)
end
|
32
33
34
35
36
|
# File 'lib/kitabu/footnotes/html.rb', line 32
def (chapter, current_index)
chapter.css("a[href='#fn#{current_index}']").each do |link|
link.set_attribute "href", "#fn#{}"
end
end
|
#process_ref_elements(chapter, current_index) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/kitabu/footnotes/html.rb', line 44
def process_ref_elements(chapter, current_index)
selector = "sup[id=fnref#{current_index}]"
chapter.css(selector).each_with_index do |sup, index|
if index.zero?
sup.set_attribute "id", "fnref#{}"
else
sup.remove_attribute "id"
end
sup.css("a").first.content =
end
end
|
#process_rev_links(chapter, current_index) ⇒ Object
38
39
40
41
42
|
# File 'lib/kitabu/footnotes/html.rb', line 38
def process_rev_links(chapter, current_index)
chapter.css("a[href='#fnref#{current_index}']").each do |link|
link.set_attribute "href", "#fnref#{}"
end
end
|