Class: HTML::Pipeline::SVGTeX::PreFilter
Constant Summary
collapse
- BLOCK_SVGTEX =
/^\$\$([^$]+)\$\$\s*$/
- INLINE_SVGTEX =
/(?<!\p{Word})\$([^$\n]+)\$(?!\p{Word})/
- INDENTED_CODE =
/(\A|\n\r?\n)(((\t|\s{4}).*(\n|\Z))+)(\r?\n|\Z)/
- FENCED_CODE =
/^``` ?(.*?)\r?\n(.+?)\r?\n```\r?$/m
- INLINE_CODE =
/`(.*)`/
Instance Attribute Summary
Attributes inherited from TextFilter
#text
Attributes inherited from Filter
#context, #result
Instance Method Summary
collapse
Methods inherited from Filter
#base_url, call, #current_user, #doc, #has_ancestor?, #html, #needs, #parse_html, #repository, to_document, to_html, #validate
Constructor Details
#initialize(text, context = nil, result = nil) ⇒ PreFilter
Returns a new instance of PreFilter.
17
18
19
20
21
22
|
# File 'lib/html/pipeline/svgtex.rb', line 17
def initialize(text, context = nil, result = nil)
super text, context, result
@text = @text.gsub "\r", ''
@inline = {}
@codemap = {}
end
|
Instance Method Details
#call ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/html/pipeline/svgtex.rb', line 24
def call
@text.gsub!(BLOCK_SVGTEX) do
"\n\n```mathjax\n\\displaystyle{#{$1.gsub "\\", "\\\\\\\\"}}\n```\n\n"
end
@text.gsub!(INLINE_SVGTEX) do
"`{mathjax} #{$1}`"
end
reinsert_code!
@text
end
|
57
58
59
60
61
62
63
|
# File 'lib/html/pipeline/svgtex.rb', line 57
def
@text.gsub!(FENCED_CODE) do
id = Digest::SHA1.hexdigest($2)
@codemap[id] = { :lang => $1, :code => $2 }
id
end
end
|
47
48
49
50
51
52
53
54
|
# File 'lib/html/pipeline/svgtex.rb', line 47
def
@text.gsub!(INDENTED_CODE) do
code = $2.gsub(/^(\t|\s{4})/, '').sub(/\r?\n\Z/, '')
id = Digest::SHA1.hexdigest(code)
@codemap[id] = { :code => code }
"\n#{id}"
end
end
|
39
40
41
42
43
44
45
|
# File 'lib/html/pipeline/svgtex.rb', line 39
def
@text.gsub!(INLINE_CODE) do
id = Digest::SHA1.hexdigest($1)
@inline[id] = $1
id
end
end
|
#reinsert_code! ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/html/pipeline/svgtex.rb', line 65
def reinsert_code!
@inline.each do |id, code|
@text.gsub!(id) { "`#{code}`" }
end
@codemap.each do |id, spec|
@text.gsub!(id) { "```#{spec[:lang]}\n#{spec[:code]}\n```" }
end
end
|