Class | SM::ToHtml |
In: |
markup/simple_markup/to_html.rb
|
Parent: | Object |
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) |
# File markup/simple_markup/to_html.rb, line 105 105: def accept_blank_line(am, fragment) 106: # @res << annotate("<p />") << "\n" 107: end
# 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
# 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
# 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
# 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
# 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
# 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
# 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
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
# File markup/simple_markup/to_html.rb, line 50 50: def annotate(tag) 51: tag 52: end
Set up the standard mapping of attributes to HTML tags
# 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
# 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
# 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