Class SM::ToHtml
In: markup/simple_markup/to_html.rb
Parent: Object

Methods

Constants

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>" ], }
InlineTag = Struct.new(:bit, :on, :off)

Public Class methods

[Source]

    # File markup/simple_markup/to_html.rb, line 21
21:     def initialize
22:       init_tags
23:     end

Public Instance methods

[Source]

     # File markup/simple_markup/to_html.rb, line 105
105:     def accept_blank_line(am, fragment)
106:       # @res << annotate("<p />") << "\n"
107:     end

[Source]

     # File markup/simple_markup/to_html.rb, line 109
109:     def accept_heading(am, fragment)
110:       @res << convert_heading(fragment.head_level, am.flow(fragment.txt))
111:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 89
89:     def accept_list_end(am, fragment)
90:       if tag = @in_list_entry.pop
91:         @res << annotate(tag) << "\n"
92:       end
93:       @res << html_list_name(fragment.type, false) <<"\n"
94:     end

[Source]

     # File markup/simple_markup/to_html.rb, line 96
 96:     def accept_list_item(am, fragment)
 97:       if tag = @in_list_entry.last
 98:         @res << annotate(tag) << "\n"
 99:       end
100:       @res << list_item_start(am, fragment)
101:       @res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
102:       @in_list_entry[-1] = list_end_for(fragment.type)
103:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 84
84:     def accept_list_start(am, fragment)
85:       @res << html_list_name(fragment.type, true) <<"\n"
86:       @in_list_entry.push false
87:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 66
66:     def accept_paragraph(am, fragment)
67:       @res << annotate("<p>") + "\n"
68:       @res << wrap(convert_flow(am.flow(fragment.txt)))
69:       @res << annotate("</p>") + "\n"
70:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 78
78:     def accept_rule(am, fragment)
79:       size = fragment.param
80:       size = 10 if size > 10
81:       @res << "<hr size=\"#{size}\"></hr>"
82:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 72
72:     def accept_verbatim(am, fragment)
73:       @res << annotate("<pre>") + "\n"
74:       @res << CGI.escapeHTML(fragment.txt)
75:       @res << annotate("</pre>") << "\n"
76:     end

Add a new set of HTML tags for an attribute. We allow separate start and end tags for flexibility

[Source]

    # File markup/simple_markup/to_html.rb, line 40
40:     def add_tag(name, start, stop)
41:       @attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop)
42:     end

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

[Source]

    # File markup/simple_markup/to_html.rb, line 50
50:     def annotate(tag)
51:       tag
52:     end

[Source]

    # File markup/simple_markup/to_html.rb, line 62
62:     def end_accepting
63:       @res
64:     end

Set up the standard mapping of attributes to HTML tags

[Source]

    # File markup/simple_markup/to_html.rb, line 28
28:     def init_tags
29:       @attr_tags = [
30:         InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"),
31:         InlineTag.new(SM::Attribute.bitmap_for(:TT),   "<tt>", "</tt>"),
32:         InlineTag.new(SM::Attribute.bitmap_for(:EM),   "<em>", "</em>"),
33:       ]
34:     end

Here‘s the client side of the visitor pattern

[Source]

    # File markup/simple_markup/to_html.rb, line 57
57:     def start_accepting
58:       @res = ""
59:       @in_list_entry = []
60:     end

This is a higher speed (if messier) version of wrap

[Source]

     # File markup/simple_markup/to_html.rb, line 115
115:     def wrap(txt, line_len = 76)
116:       res = ""
117:       sp = 0
118:       ep = txt.length
119:       while sp < ep
120:         # scan back for a space
121:         p = sp + line_len - 1
122:         if p >= ep
123:           p = ep
124:         else
125:           while p > sp and txt[p] != ?\s
126:             p -= 1
127:           end
128:           if p <= sp
129:             p = sp + line_len
130:             while p < ep and txt[p] != ?\s
131:               p += 1
132:             end
133:           end
134:         end
135:         res << txt[sp...p] << "\n"
136:         sp = p
137:         sp += 1 while sp < ep and txt[sp] == ?\s
138:       end
139:       res
140:     end

[Validate]