raf 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,198 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Copyright (C) garin <garin54@gmail.com> 2011
3
- # See the included file COPYING for details.
4
- require "rafblockparser.tab"
5
- module Raf
6
-
7
- class Element
8
- def newline_to_br(str)
9
- str.gsub("\n", "<br />\n")
10
- end
11
-
12
- # @inline_parser.parse の配列を文字列に変換する
13
- def inline_parse_to_str(array)
14
- str = ""
15
- array.each do |obj|
16
- str += obj.apply
17
- end
18
- str
19
- end
20
- end
21
-
22
- # ----- Blocks
23
- class WhiteLine < Element
24
- def apply
25
- "\n"
26
- end
27
- end
28
-
29
- class PlainTextBlock < Element
30
- def apply
31
- @contents.map {|c| c.apply }
32
- end
33
- end
34
-
35
- class HeadLine < Element
36
- # @contents = [level, title, id, index]
37
- def apply
38
- return "" if @contents[0] == 1
39
- str = ""
40
- str += "<h#{@contents[0]} id='raf-head#{@contents[0]}-#{@contents[2]}'>"
41
- str += "<a id='#{@contents[1].to_code}'></a>"
42
- str += " #{@contents[3]}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
43
- str += "#{@contents[1]}</h#{@contents[0]}>\n"
44
- str
45
- end
46
- end
47
-
48
- class Paragraph < Element
49
- def apply
50
- "<p>#{@contents.map{|c| c.apply}}</p>\n"
51
- end
52
- end
53
-
54
- class Quote < Element
55
- def apply
56
- "<pre>#{@contents}</pre>\n"
57
- end
58
- end
59
-
60
- class ItemList < Element
61
- def apply
62
- return "" if @contents.empty?
63
- type = :dummy
64
- str = "<ul>\n"
65
- @contents.each do |item|
66
- type_pre = type
67
- case item
68
- when :INDENT
69
- type = :indent
70
- str += "\n<ul>\n"
71
- when :DEDENT
72
- type = :dedent
73
- str += "</li>\n" if type_pre == :item
74
- str += "</ul>\n</li>\n"
75
- else
76
- type = :item
77
- str += "</li>\n" if type_pre == :item
78
- str += "<li>#{item.apply}"
79
- end
80
- end
81
- str += "\n</li>" if type == :item
82
- str += "\n</ul>\n"
83
- str
84
- end
85
- end
86
-
87
- class NumList < Element
88
- def apply
89
- str = "<ol>\n"
90
- @contents.map do |item|
91
- if item == :INDENT
92
- str += "<ol>\n"
93
- elsif item == :DEDENT
94
- str += "</ol>\n"
95
- else
96
- str += "<li>#{item.apply}</li>\n"
97
- end
98
- end
99
- str += "</ol>\n"
100
- str
101
- end
102
- end
103
-
104
- class Desc < Element
105
- # @contents = [title, lines]
106
- def apply
107
- str = "<dl id='#{@contents[0].to_code}'>\n<dt>#{@contents[0]}</dt>\n"
108
- str += "<dd>#{inline_parse_to_str(@contents[1])}</dd>\n" unless inline_parse_to_str(@contents[1]).empty?
109
- str += "</dl>"
110
- str
111
- end
112
- end
113
-
114
- class Table < Element
115
- def apply
116
- str = "<table>"
117
- @contents.each do |line|
118
- str += "\n<tr>"
119
- line.each do |item|
120
- if item =~ /^\s*\*/
121
- str += "<th>#{item.sub(/^\s*\*/, "").sub(/\*\s*$/,"")}</th>"
122
- else
123
- str += "<td>#{item}</td>"
124
- end
125
- end
126
- str += "\n</tr>"
127
- end
128
- str += "\n</table>"
129
- str
130
- end
131
- end
132
- # --- Blocks end
133
-
134
- # --- Inlines
135
- class Label < Element
136
- # @contents = [label, title]
137
- def apply
138
- "<a href='##{@contents[0]}' id='#{@contents[0]}'>#{@contents[1]}</a>"
139
- end
140
- end
141
-
142
- class Reference < Element
143
- def apply
144
- "<a href='#{@contents[1]}' title='#{@contents[1]}'>#{@contents[0]}</a>"
145
- end
146
- end
147
-
148
- class Plain < Element
149
- def apply
150
- "#{newline_to_br(CGI.escapeHTML(@contents.join))}"
151
- end
152
- end
153
-
154
- class Emphasis < Element
155
- def apply
156
- "<em>#{@contents.map{|c| c.apply}}</em>"
157
- end
158
- end
159
- class Italic < Element
160
- def apply
161
- "<i>#{@contents.map{|c| c.apply}}</i>"
162
- end
163
- end
164
- class Strike < Element
165
- def apply
166
- "<s>#{@contents.map{|c| c.apply}}</s>"
167
- end
168
- end
169
-
170
- class Verb < Element
171
- def apply
172
- "#{@contents}"
173
- end
174
- end
175
-
176
- class Manuedo < Element
177
- def apply
178
- "<span class='manuedo'>/#{@contents.map{|c| c.apply}}/</span>"
179
- end
180
- end
181
- class Ruby < Element
182
- def apply
183
- "<ruby><rb>#{@contents[0]}</rb><rp>(</rp><rt>#{@contents[1]}</rt><rp>)</rp></ruby>"
184
- end
185
- end
186
-
187
- class Footnote < Element
188
- def apply
189
- "<a href='#raf-footnote-#{@contents[1]}' name='raf-footnote-#{@contents[1]}-reverse' title='#{@contents[0].map {|c| c.apply}}' class='footnote-reverse'><sup><small>*#{@contents[1]}</small></sup></a>"
190
- end
191
- end
192
-
193
- class Image < Element
194
- def apply
195
- "<img src='#{@contents}' />"
196
- end
197
- end
198
- end