Class: Rabbit::Parser::RD::Ext::BlockVerbatim
- Inherits:
-
Base
- Object
- Base
- Rabbit::Parser::RD::Ext::BlockVerbatim
show all
- Includes:
- GetText, Image
- Defined in:
- lib/rabbit/parser/rd/ext/block-verbatim.rb
Constant Summary
Constants included
from GetText
GetText::DOMAIN
Constants included
from Ext::Image
Ext::Image::ALLOWED_IMG_URL_SCHEME
Instance Method Summary
collapse
-
#default_ext_block_verbatim(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_aafigure(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_block_quote(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_blockdiag(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_coderay(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_emacs(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_enscript(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_img(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_LaTeX(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_mimeTeX(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_quote(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_rt(label, source, content, visitor) ⇒ Object
-
#ext_block_verb_wait(label, source, content, visitor) ⇒ Object
Methods included from GetText
included
Methods included from Image
#img, #make_image_from_file
Methods included from Ext::Image
make_image, make_image_from_file
Methods inherited from Base
add_extension, #apply, extensions, #extensions, inherited, method_added
Instance Method Details
#default_ext_block_verbatim(label, source, content, visitor) ⇒ Object
26
27
28
29
30
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 26
def default_ext_block_verbatim(label, source, content, visitor)
content = visitor.apply_to_String(content.rstrip)
text = Text.new(content)
PreformattedBlock.new(PreformattedText.new(text))
end
|
92
93
94
95
96
97
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 92
def ext_block_verb_aafigure(label, source, content, visitor)
return nil unless /^aafigure$/i =~ label
make_image_from_file(source, visitor) do |src_file_path, prop|
Parser::Ext::AAFigure.make_image(src_file_path, prop, visitor)
end
end
|
#ext_block_verb_block_quote(label, source, content, visitor) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 138
def ext_block_verb_block_quote(label, source, content, visitor)
return nil unless /^block[_-]?quote$/i =~ label
src, prop = parse_source(source)
tree = ::RD::RDTree.new("=begin\n#{src}\n=end\n")
elems = tree.root.children.collect do |child|
child.accept(visitor)
end
BlockQuote.new(elems, prop)
end
|
#ext_block_verb_blockdiag(label, source, content, visitor) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 99
def ext_block_verb_blockdiag(label, source, content, visitor)
return nil unless /^blockdiag$/i =~ label
make_image_from_file(source, visitor) do |src_file_path, prop|
Parser::Ext::BlockDiag.make_image(src_file_path, prop, visitor)
end
end
|
#ext_block_verb_coderay(label, source, content, visitor) ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 106
def ext_block_verb_coderay(label, source, content, visitor)
return nil unless /^coderay (\w+)$/i =~ label
lang = $1.downcase.untaint
src, prop = parse_source(source)
logger = visitor.logger
result = Parser::Ext::CodeRay.highlight(lang, src, logger)
result || default_ext_block_verbatim(label, src, src, visitor)
end
|
#ext_block_verb_emacs(label, source, content, visitor) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 117
def ext_block_verb_emacs(label, source, content, visitor)
return nil unless /^emacs(?:\s+(.+))?$/i =~ label
mode_line = $1.untaint
src, prop = parse_source(source)
logger = visitor.logger
result = Parser::Ext::Emacs.highlight(src, logger, mode_line)
result || default_ext_block_verbatim(label, src, src, visitor)
end
|
#ext_block_verb_enscript(label, source, content, visitor) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 63
def ext_block_verb_enscript(label, source, content, visitor)
return nil unless /^enscript (\w+)$/i =~ label
lang = $1.downcase.untaint
src, prop = parse_source(source)
logger = visitor.logger
result = nil
if Parser::Ext::Enscript.check_availability(lang, logger)
result = Parser::Ext::Enscript.highlight(lang, src, logger)
end
result || default_ext_block_verbatim(label, src, src, visitor)
end
|
#ext_block_verb_img(label, source, content, visitor) ⇒ Object
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
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 37
def ext_block_verb_img(label, source, content, visitor)
return nil unless /^(?:image|img)$/i =~ label
src, prop = parse_source(source)
return nil if prop['src'].nil?
if prop['align'] == "right"
body = visitor.current_body
if body["background-image"]
raise ParseError,
_("multiple 'align = right' isn't supported.")
end
prop.each do |name, value|
name = name.gsub(/_/, '-')
if name == "src"
property_name = "background-image"
else
property_name = "background-image-#{name}"
end
body[property_name] = value
end
:no_element
else
make_image(visitor, prop['src'], prop)
end
end
|
#ext_block_verb_LaTeX(label, source, content, visitor) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 77
def ext_block_verb_LaTeX(label, source, content, visitor)
return nil unless /^LaTeX$/i =~ label
make_image_from_file(source, visitor) do |src_file_path, prop|
Parser::Ext::TeX.make_image_by_LaTeX(src_file_path, prop, visitor)
end
end
|
#ext_block_verb_mimeTeX(label, source, content, visitor) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 84
def ext_block_verb_mimeTeX(label, source, content, visitor)
return nil unless /^mimeTeX$/i =~ label
make_image_from_file(source, visitor) do |src_file_path, prop|
Parser::Ext::TeX.make_image_by_mimeTeX(src_file_path, prop,
visitor)
end
end
|
#ext_block_verb_quote(label, source, content, visitor) ⇒ Object
32
33
34
35
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 32
def ext_block_verb_quote(label, source, content, visitor)
return nil unless /^_$/i =~ label
default_ext_block_verbatim("", source, source, visitor)
end
|
#ext_block_verb_rt(label, source, content, visitor) ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 128
def ext_block_verb_rt(label, source, content, visitor)
return nil unless /^rt$/i =~ label
unless defined?(RT2RabbitVisitor)
visitor.logger.warn(_("RTtool isn't available"))
return nil
end
rt_visitor = RT2RabbitVisitor.new(visitor)
rt_visitor.visit(RT::RTParser.parse(content))
end
|
#ext_block_verb_wait(label, source, content, visitor) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/rabbit/parser/rd/ext/block-verbatim.rb', line 148
def ext_block_verb_wait(label, source, content, visitor)
return nil unless /^wait$/i =~ label
src, prop = parse_source(source)
tree = ::RD::RDTree.new("=begin\n#{src}\n=end\n")
wait_block = WaitBlock.new
visitor.register_pause(wait_block)
tree.root.children.each do |child|
wait_block << child.accept(visitor)
end
wait_block
end
|