-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
filter.rb
100 lines (76 loc) · 1.68 KB
/
filter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
module Docs
class Filter < ::HTML::Pipeline::Filter
def css(*args)
doc.css(*args)
end
def at_css(*args)
doc.at_css(*args)
end
def xpath(*args)
doc.xpath(*args)
end
def at_xpath(*args)
doc.at_xpath(*args)
end
def base_url
context[:base_url]
end
def links
context[:links]
end
def current_url
context[:url]
end
def root_url
context[:root_url]
end
def root_path
context[:root_path]
end
def version
context[:version]
end
def release
context[:release]
end
def subpath
@subpath ||= subpath_to(current_url)
end
def subpath_to(url)
base_url.subpath_to url, ignore_case: true
end
def slug
@slug ||= subpath.sub(/\A\//, '').remove(/\.html\z/)
end
def root_page?
subpath.blank? || subpath == '/' || subpath == root_path
end
def initial_page?
root_page? || context[:initial_paths].include?(subpath)
end
SCHEME_RGX = /\A[^:\/?#]+:/
def fragment_url_string?(str)
str[0] == '#'
end
DATA_URL = 'data:'.freeze
def data_url_string?(str)
str.start_with?(DATA_URL)
end
def relative_url_string?(str)
str !~ SCHEME_RGX && !fragment_url_string?(str) && !data_url_string?(str)
end
def absolute_url_string?(str)
str =~ SCHEME_RGX
end
def parse_html(html)
warn "#{self.class.name} is re-parsing the document" unless ENV['RACK_ENV'] == 'test'
super
end
def clean_path(path)
path = path.gsub %r{[!;:]}, '-'
path = path.gsub %r{\+}, '_plus_'
path
end
end
end