Class: SM::ToHtml
- Inherits:
-
Object
show all
- Defined in:
- lib/rdoc/markup/simple_markup/to_html.rb
Defined Under Namespace
Classes: InlineTag
Constant Summary
collapse
- LIST_TYPE_TO_HTML =
{
ListBase::BULLET => [ "<ul>", "</ul>" ],
ListBase::NUMBER => [ "<ol>", "</ol>" ],
ListBase::UPPERALPHA => [ "<ol>", "</ol>" ],
ListBase::LOWERALPHA => [ "<ol>", "</ol>" ],
ListBase::LABELED => [ "<dl>", "</dl>" ],
ListBase::NOTE => [ "<table>", "</table>" ],
}
Instance Method Summary
collapse
-
#accept_blank_line(am, fragment) ⇒ Object
-
#accept_heading(am, fragment) ⇒ Object
-
#accept_list_end(am, fragment) ⇒ Object
-
#accept_list_item(am, fragment) ⇒ Object
-
#accept_list_start(am, fragment) ⇒ Object
-
#accept_paragraph(am, fragment) ⇒ Object
-
#accept_rule(am, fragment) ⇒ Object
-
#accept_verbatim(am, fragment) ⇒ Object
-
#add_tag(name, start, stop) ⇒ Object
Add a new set of HTML tags for an attribute.
-
#annotate(tag) ⇒ Object
Given an HTML tag, decorate it with class information and the like if required.
-
#end_accepting ⇒ Object
-
#init_tags ⇒ Object
Set up the standard mapping of attributes to HTML tags.
-
#initialize ⇒ ToHtml
constructor
A new instance of ToHtml.
-
#start_accepting ⇒ Object
Here's the client side of the visitor pattern.
-
#wrap(txt, line_len = 76) ⇒ Object
This is a higher speed (if messier) version of wrap.
Constructor Details
#initialize ⇒ ToHtml
Returns a new instance of ToHtml.
21
22
23
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 21
def initialize
init_tags
end
|
Instance Method Details
#accept_blank_line(am, fragment) ⇒ Object
105
106
107
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 105
def accept_blank_line(am, fragment)
end
|
#accept_heading(am, fragment) ⇒ Object
109
110
111
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 109
def accept_heading(am, fragment)
@res << convert_heading(fragment.head_level, am.flow(fragment.txt))
end
|
#accept_list_end(am, fragment) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 89
def accept_list_end(am, fragment)
if tag = @in_list_entry.pop
@res << annotate(tag) << "\n"
end
@res << html_list_name(fragment.type, false) <<"\n"
end
|
#accept_list_item(am, fragment) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 96
def accept_list_item(am, fragment)
if tag = @in_list_entry.last
@res << annotate(tag) << "\n"
end
@res << list_item_start(am, fragment)
@res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
@in_list_entry[-1] = list_end_for(fragment.type)
end
|
#accept_list_start(am, fragment) ⇒ Object
84
85
86
87
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 84
def accept_list_start(am, fragment)
@res << html_list_name(fragment.type, true) <<"\n"
@in_list_entry.push false
end
|
#accept_paragraph(am, fragment) ⇒ Object
66
67
68
69
70
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 66
def accept_paragraph(am, fragment)
@res << annotate("<p>") + "\n"
@res << wrap(convert_flow(am.flow(fragment.txt)))
@res << annotate("</p>") + "\n"
end
|
#accept_rule(am, fragment) ⇒ Object
78
79
80
81
82
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 78
def accept_rule(am, fragment)
size = fragment.param
size = 10 if size > 10
@res << "<hr size=\"#{size}\"></hr>"
end
|
#accept_verbatim(am, fragment) ⇒ Object
72
73
74
75
76
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 72
def accept_verbatim(am, fragment)
@res << annotate("<pre>") + "\n"
@res << CGI.escapeHTML(fragment.txt)
@res << annotate("</pre>") << "\n"
end
|
#add_tag(name, start, stop) ⇒ Object
Add a new set of HTML tags for an attribute. We allow separate start and end tags for flexibility
40
41
42
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 40
def add_tag(name, start, stop)
@attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop)
end
|
#annotate(tag) ⇒ Object
Given an HTML tag, decorate it with class information and the like if required. This is a no-op in the base class, but is overridden in HTML output classes that implement style sheets
50
51
52
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 50
def annotate(tag)
tag
end
|
#end_accepting ⇒ Object
62
63
64
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 62
def end_accepting
@res
end
|
Set up the standard mapping of attributes to HTML tags
28
29
30
31
32
33
34
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 28
def init_tags
@attr_tags = [
InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
InlineTag.new(SM::Attribute.bitmap_for(:TT), "<tt>", "</tt>"),
InlineTag.new(SM::Attribute.bitmap_for(:EM), "<em>", "</em>"),
]
end
|
#start_accepting ⇒ Object
Here's the client side of the visitor pattern
57
58
59
60
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 57
def start_accepting
@res = ""
@in_list_entry = []
end
|
#wrap(txt, line_len = 76) ⇒ Object
This is a higher speed (if messier) version of wrap
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/rdoc/markup/simple_markup/to_html.rb', line 115
def wrap(txt, line_len = 76)
res = ""
sp = 0
ep = txt.length
while sp < ep
p = sp + line_len - 1
if p >= ep
p = ep
else
while p > sp and txt[p] != ?\s
p -= 1
end
if p <= sp
p = sp + line_len
while p < ep and txt[p] != ?\s
p += 1
end
end
end
res << txt[sp...p] << "\n"
sp = p
sp += 1 while sp < ep and txt[sp] == ?\s
end
res
end
|