Class: HParser::Block::SuperPre
- Inherits:
-
Pair
- Object
- Pair
- HParser::Block::SuperPre
show all
- Includes:
- Collectable, Indent, Hatena, Html, Latex
- Defined in:
- lib/hparser/block/super_pre.rb,
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/hatena.rb
Overview
Constant Summary
collapse
- @@class_format_prefix =
nil
- @@use_pygments =
false
Constants included
from Html
Html::ESCAPE_TABLE
Instance Attribute Summary collapse
Attributes inherited from Pair
#content
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Hatena
#to_hatena
Methods included from Indent
#_to_text_, #text_content, #to_text
Methods included from Text
#to_text
Methods included from Html
#escape
Methods inherited from Pair
#==, get, spliter
Constructor Details
#initialize(content, format = nil) ⇒ SuperPre
Returns a new instance of SuperPre.
29
30
31
32
|
# File 'lib/hparser/block/super_pre.rb', line 29
def initialize(content, format = nil)
super content
@format = format
end
|
Instance Attribute Details
Returns the value of attribute format.
28
29
30
|
# File 'lib/hparser/block/super_pre.rb', line 28
def format
@format
end
|
Class Method Details
.<=>(o) ⇒ Object
34
35
36
|
# File 'lib/hparser/block/super_pre.rb', line 34
def self.<=>(o)
-1
end
|
122
123
124
|
# File 'lib/hparser/html.rb', line 122
def self.class_format_prefix
@@class_format_prefix
end
|
125
126
127
|
# File 'lib/hparser/html.rb', line 125
def self.class_format_prefix=(prefix)
@@class_format_prefix = prefix
end
|
.parse(scanner, context, inlines) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/hparser/block/super_pre.rb', line 9
def self.parse scanner,context,inlines
content = format = nil
if scanner.scan(/^>\|([A-Za-z0-9]*)\|\s*?$/)
lines = []
format = scanner.matched_pattern[1]
until scanner.scan(/^\|\|<\s*?$/) do
str = scanner.scan(/.*/)
break if !str
lines << str
end
content = lines.join("\n")
end
if content then
SuperPre.new content, format
end
end
|
.use_pygments ⇒ Object
129
130
131
|
# File 'lib/hparser/html.rb', line 129
def self.use_pygments
@@use_pygments
end
|
.use_pygments=(use_or_not) ⇒ Object
132
133
134
|
# File 'lib/hparser/html.rb', line 132
def self.use_pygments=(use_or_not)
@@use_pygments = use_or_not
end
|
Instance Method Details
#hatena_filter(c) ⇒ Object
73
74
75
|
# File 'lib/hparser/hatena.rb', line 73
def hatena_filter c
">||\n"+c+"\n||<"
end
|
#html_tag ⇒ Object
167
|
# File 'lib/hparser/html.rb', line 167
def html_tag() 'pre' end
|
#to_html ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/hparser/html.rb', line 136
def to_html
content = html_content.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
if format != "" && @@use_pygments
lang = format
case format
when "cs"
lang = "csharp"
when "lisp"
lang = "cl"
when "patch"
lang = "diff"
when "vb"
lang = "vbnet"
end
begin
require 'pygments'
Pygments.highlight(html_content,
:lexer => lang, :options => {:encoding => 'utf-8'})
rescue LoadError
require 'albino'
Albino.new(html_content, lang).colorize
end
elsif format
%(<#{html_tag} class="#{@@class_format_prefix}#{escape(format)}">#{content}</#{html_tag}>)
else
%(<#{html_tag}>#{content}</#{html_tag}>)
end
end
|
#to_latex ⇒ Object
95
96
97
98
|
# File 'lib/hparser/latex.rb', line 95
def to_latex
content = latex_content %Q[\\begin{verbatim}\n#{content}\n\\end{verbatim}\n]
end
|