org-parse 0.1.1
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.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/ChangeLog +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +68 -0
- data/Rakefile +54 -0
- data/VERSION.yml +5 -0
- data/bin/org-parse +51 -0
- data/bin/org-test +74 -0
- data/doc/images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png +0 -0
- data/doc/org-parse.html +203 -0
- data/doc/org-parse.org +71 -0
- data/doc/struct.dot +10 -0
- data/doc/struct.png +0 -0
- data/examples/body-only.html.erb +1 -0
- data/examples/dot.org-parse-rc +21 -0
- data/lib/org-parse/inline-parser.output +945 -0
- data/lib/org-parse/inline-parser.rb +219 -0
- data/lib/org-parse/inline-parser.ry +77 -0
- data/lib/org-parse/inline-parser.tab.rb +411 -0
- data/lib/org-parse/node.rb +329 -0
- data/lib/org-parse/struct-parser.output +1019 -0
- data/lib/org-parse/struct-parser.rb +78 -0
- data/lib/org-parse/struct-parser.ry +125 -0
- data/lib/org-parse/struct-parser.tab.rb +608 -0
- data/lib/org-parse/struct-scanner.rb +272 -0
- data/lib/org-parse/templates/single.html.erb +118 -0
- data/lib/org-parse/textile-visitor.rb +296 -0
- data/lib/org-parse/utils.rb +15 -0
- data/lib/org-parse/visitor.rb +542 -0
- data/lib/org-parse.rb +46 -0
- data/org-parse.gemspec +113 -0
- data/rakelib/racc.rake +16 -0
- data/test/data/blocks.org +67 -0
- data/test/data/emphasis.org +7 -0
- data/test/data/footnote.html +136 -0
- data/test/data/footnote.org +8 -0
- data/test/data/html-export.html +1062 -0
- data/test/data/html-export.org +342 -0
- data/test/data/images.html +179 -0
- data/test/data/images.org +30 -0
- data/test/data/index.org +242 -0
- data/test/data/lily20100228.jpg +0 -0
- data/test/data/lily20100228t.jpg +0 -0
- data/test/data/link.org +7 -0
- data/test/data/list_before_1st_headline.html +119 -0
- data/test/data/list_before_1st_headline.org +7 -0
- data/test/data/lists.html +284 -0
- data/test/data/lists.org +78 -0
- data/test/data/no-headline.org +6 -0
- data/test/data/one-headline.org +2 -0
- data/test/data/paragraph.org +13 -0
- data/test/data/quote.org +15 -0
- data/test/data/sections.html +173 -0
- data/test/data/sections.org +9 -0
- data/test/data/simple-list.org +6 -0
- data/test/data/skip_t.org +3 -0
- data/test/data/structure.org +53 -0
- data/test/data/table.org +14 -0
- data/test/data/test-list.org +12 -0
- data/test/data/text-bef-hl.org +5 -0
- data/test/data/text.org +6 -0
- data/test/data/title.html +88 -0
- data/test/data/title.org +6 -0
- data/test/data/verse.org +48 -0
- data/test/helper.rb +31 -0
- data/test/test_org-parse.rb +148 -0
- metadata +134 -0
@@ -0,0 +1,542 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'erb'
|
4
|
+
require 'uv'
|
5
|
+
|
6
|
+
module OrgParse
|
7
|
+
|
8
|
+
module VisitorUtils
|
9
|
+
|
10
|
+
|
11
|
+
def execute(node)
|
12
|
+
puts "not implimented => #{node.inspect}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def exec_list(nodes)
|
16
|
+
ret = ''
|
17
|
+
nodes.each{|n| ret += execute(n) }
|
18
|
+
ret
|
19
|
+
end
|
20
|
+
|
21
|
+
def exec_children(node)
|
22
|
+
exec_list node.children
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class OrgVisitor
|
27
|
+
@@image_exts = ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'tiff', 'srg']
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
make_image_regs @@image_exts
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_image_regs(exts)
|
34
|
+
@image_file_reg = /\.(#{exts.join('|')})$/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# todo:
|
39
|
+
# \\- ­ \\-
|
40
|
+
# -- – --
|
41
|
+
# --- — ---
|
42
|
+
# ... … \ldots
|
43
|
+
|
44
|
+
# output HTML format
|
45
|
+
class HtmlVisitor < OrgVisitor
|
46
|
+
include VisitorUtils
|
47
|
+
TEMPLATE = ::File.join(OrgParse::LIBPATH , 'org-parse', 'templates', 'single.html.erb')
|
48
|
+
attr_reader :body
|
49
|
+
|
50
|
+
def initialize(root, template = nil, cm_opt = {})
|
51
|
+
@body = @title = @add_to_head = ''
|
52
|
+
@root = root
|
53
|
+
@ul_stack = []
|
54
|
+
super()
|
55
|
+
template = TEMPLATE unless template
|
56
|
+
@erb = ERB.new(::File.read(template))
|
57
|
+
@p_tag_flag = true
|
58
|
+
@list_level = 0
|
59
|
+
@indent_stack = [0]
|
60
|
+
@body = ''
|
61
|
+
@curr_level = 0
|
62
|
+
@para_level = 0
|
63
|
+
@options = cm_opt
|
64
|
+
end
|
65
|
+
|
66
|
+
def make_image_regs(exts)
|
67
|
+
@image_file_reg = /\.(#{exts.join('|')})$/
|
68
|
+
end
|
69
|
+
|
70
|
+
# remove HTML tags
|
71
|
+
def rm_html_tag(str)
|
72
|
+
str.sub!(/<[^<>]*>/,"") while /<[^<>]*>/ =~ str
|
73
|
+
str
|
74
|
+
end
|
75
|
+
|
76
|
+
# build the HTML string
|
77
|
+
def build
|
78
|
+
@options = @root.options
|
79
|
+
@title = exec_list @root.options[:title]
|
80
|
+
@language = @root.options[:language]
|
81
|
+
@charset = @root.options[:charset]
|
82
|
+
@body = ''
|
83
|
+
@footnotes = []
|
84
|
+
@footnote_idxs = []
|
85
|
+
@before_text = ''
|
86
|
+
@before_text = exec_list @options[:text] # .each {|n| @before_text += execute(n)}
|
87
|
+
@add_to_head = @options[:style]
|
88
|
+
start_flag = true
|
89
|
+
@root.children.each do |node|
|
90
|
+
if start_flag and node.kind != :SECTION
|
91
|
+
@before_text += execute(node)
|
92
|
+
else
|
93
|
+
start_flag = false
|
94
|
+
@body += execute(node)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
@language = @root.options[:language]
|
98
|
+
@erb.result(binding)
|
99
|
+
end
|
100
|
+
|
101
|
+
def section_indent(level = nil)
|
102
|
+
level = @curr_level if level.nil?
|
103
|
+
' ' * level
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_indent
|
107
|
+
base = section_indent
|
108
|
+
base += (' ' * @list_level)
|
109
|
+
base += (' ' * @para_level)
|
110
|
+
end
|
111
|
+
|
112
|
+
def close_ul_sec(level)
|
113
|
+
str = ''
|
114
|
+
while @ul_stack.last and @ul_stack.last > level
|
115
|
+
indent = section_indent(@ul_stack.last - 1)
|
116
|
+
@ul_stack.pop
|
117
|
+
str += "#{indent}</ul>\n"
|
118
|
+
end
|
119
|
+
str
|
120
|
+
end
|
121
|
+
|
122
|
+
def table_of_contents
|
123
|
+
toc = "<ul>\n"
|
124
|
+
@root.children.each {|node|
|
125
|
+
if node.kind == :SECTION
|
126
|
+
toc += toc_out node
|
127
|
+
end
|
128
|
+
}
|
129
|
+
toc += "</ul>\n"
|
130
|
+
return '' if toc == "<ul>\n</ul>\n"
|
131
|
+
ret =<<"EOS"
|
132
|
+
<div id="table-of-contents">
|
133
|
+
<h2>Table of Contents</h2>
|
134
|
+
<div id="text-table-of-contents">
|
135
|
+
#{toc}
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
EOS
|
139
|
+
end
|
140
|
+
|
141
|
+
def toc_out(node)
|
142
|
+
curr_level = node.headline.level
|
143
|
+
idx_no = node.section_no
|
144
|
+
str = toc_headline node.headline
|
145
|
+
ret = %Q|<li><a href="#sec-#{idx_no}">#{idx_no} #{str}</a>|
|
146
|
+
has_child = false
|
147
|
+
node.children.each {|node|
|
148
|
+
if node.kind == :SECTION
|
149
|
+
ret += "\n<ul>\n" unless has_child
|
150
|
+
has_child = true
|
151
|
+
ret += toc_out node
|
152
|
+
end
|
153
|
+
}
|
154
|
+
if has_child
|
155
|
+
ret += "</ul>\n"
|
156
|
+
ret += "</li>\n"
|
157
|
+
end
|
158
|
+
ret
|
159
|
+
end
|
160
|
+
|
161
|
+
def toc_headline(node)
|
162
|
+
str = ''
|
163
|
+
node.children.each do |item|
|
164
|
+
unless item.kind == :FN_LINK
|
165
|
+
str += execute item
|
166
|
+
end
|
167
|
+
end
|
168
|
+
str
|
169
|
+
end
|
170
|
+
|
171
|
+
def section(node)
|
172
|
+
curr_level = node.headline.level
|
173
|
+
|
174
|
+
@curr_level = curr_level
|
175
|
+
indent = section_indent(curr_level - 1)
|
176
|
+
idx_no = node.section_no
|
177
|
+
if curr_level > @options[:H]
|
178
|
+
str = close_ul_sec(curr_level)
|
179
|
+
if @ul_stack.last and @ul_stack.last == curr_level
|
180
|
+
str += %Q|#{indent} <li id="sec-#{idx_no}">#{exec_children node}</li>\n|
|
181
|
+
else
|
182
|
+
str += "#{indent}<ul>\n"
|
183
|
+
@ul_stack << curr_level
|
184
|
+
str += %Q|#{indent} <li id="sec-#{idx_no}">#{exec_children node}</li>\n|
|
185
|
+
end
|
186
|
+
str
|
187
|
+
else
|
188
|
+
%Q|#{close_ul_sec(curr_level).chomp}
|
189
|
+
#{indent}<div id="outline-container-#{idx_no}" class="outline-#{curr_level+1}">
|
190
|
+
#{indent} #{headline node.headline}
|
191
|
+
#{indent} <div class="outline-text-#{@curr_level+1}" id="text-#{idx_no}">
|
192
|
+
#{exec_children node}
|
193
|
+
#{close_ul_sec(curr_level).chomp}
|
194
|
+
#{indent} </div>
|
195
|
+
#{indent}</div>
|
196
|
+
|
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def headline(node)
|
201
|
+
level = node.level+1
|
202
|
+
index_str = node.parent.section_no
|
203
|
+
%Q|<h#{level} id="sec-#{index_str}"><span class="section-number-#{level}">#{index_str}</span> #{exec_children(node).chomp} </h#{level}>|
|
204
|
+
end
|
205
|
+
|
206
|
+
# paragraph
|
207
|
+
# if @p_tag_flag == false then we do'nt output <p></p> tags.
|
208
|
+
def textblock(node)
|
209
|
+
if node.verse? or node.example? or node.html? or node.src?
|
210
|
+
exec_children node
|
211
|
+
elsif @p_tag_flag
|
212
|
+
indent = get_indent
|
213
|
+
@para_level += 1
|
214
|
+
str = "#{indent}<p>\n#{exec_children(node).chomp}\n#{indent}</p>\n"
|
215
|
+
@para_level -= 1
|
216
|
+
str
|
217
|
+
else
|
218
|
+
str = exec_children node
|
219
|
+
@p_tag_flag = true # next paragraph has <p>
|
220
|
+
str
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def textline(node)
|
225
|
+
if node.example? or (node.src? and !@options[:uv])
|
226
|
+
indent = ' ' * @indent_stack.last
|
227
|
+
return h node.value.sub(/^#{indent}/,'')
|
228
|
+
elsif node.src? and @options[:uv]
|
229
|
+
return node.value
|
230
|
+
elsif node.html?
|
231
|
+
return node.value
|
232
|
+
else
|
233
|
+
indent = get_indent
|
234
|
+
str = exec_children(node).sub(/^\s*/, '')
|
235
|
+
if node.verse?
|
236
|
+
n = node.indent - @indent_stack.last
|
237
|
+
n = 0 if n < 0
|
238
|
+
indent = ' ' * n
|
239
|
+
indent + str.gsub(/\n/, "<br/>\n")
|
240
|
+
else
|
241
|
+
indent + str
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def verse(node)
|
247
|
+
pre = get_indent + %Q|<p class="verse">\n|
|
248
|
+
post = get_indent + "</p>\n"
|
249
|
+
@indent_stack << node.indent
|
250
|
+
body = exec_children node
|
251
|
+
@indent_stack.pop
|
252
|
+
pre + body.chomp + "\n" + post
|
253
|
+
end
|
254
|
+
|
255
|
+
def example(node)
|
256
|
+
indent = get_indent
|
257
|
+
this_indent = 0
|
258
|
+
this_indent = node.children[0].children[0].indent
|
259
|
+
@indent_stack << this_indent
|
260
|
+
body = exec_children(node)
|
261
|
+
@indent_stack.pop
|
262
|
+
%Q|<pre class="example">\n#{ body.chomp }\n</pre>\n|
|
263
|
+
end
|
264
|
+
|
265
|
+
def src(node)
|
266
|
+
if @options[:uv]
|
267
|
+
text = exec_children(node)
|
268
|
+
syntax = node.syntax
|
269
|
+
syntax = 'lisp' if syntax == 'emacs-lisp'
|
270
|
+
theme = node.syntax_theme
|
271
|
+
theme = 'amy' if theme.empty?
|
272
|
+
begin
|
273
|
+
Uv.parse( text, "xhtml", syntax, true, theme)
|
274
|
+
rescue
|
275
|
+
"uv can't parse #{syntax}/#{theme} <br>\n" + example(node)
|
276
|
+
end
|
277
|
+
else
|
278
|
+
example node
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def html_quote(node)
|
283
|
+
indent = get_indent
|
284
|
+
@indent_stack << node.children[0].children[0].indent
|
285
|
+
body = exec_children(node)
|
286
|
+
@indent_stack.pop
|
287
|
+
body
|
288
|
+
end
|
289
|
+
|
290
|
+
def blockquote(node)
|
291
|
+
indent = get_indent
|
292
|
+
# @p_tag_flag = false
|
293
|
+
@para_level += 1
|
294
|
+
body = exec_children(node)
|
295
|
+
@para_level -= 1
|
296
|
+
%Q|#{indent}<blockquote>\n#{body.chomp}\n#{indent}</blockquote>\n|
|
297
|
+
end
|
298
|
+
|
299
|
+
def blocks(node)
|
300
|
+
case node.block_name
|
301
|
+
when 'VERSE'
|
302
|
+
verse node
|
303
|
+
when 'EXAMPLE'
|
304
|
+
example node
|
305
|
+
when 'QUOTE'
|
306
|
+
blockquote node
|
307
|
+
when 'HTML'
|
308
|
+
html_quote node
|
309
|
+
when 'COMMENT'
|
310
|
+
''
|
311
|
+
when 'SRC'
|
312
|
+
src node
|
313
|
+
else
|
314
|
+
puts "not implimented block=>[#{node.block_name}](#{node.inspect})"
|
315
|
+
exec_children(node)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
def image_tag(uri, attr = '')
|
320
|
+
%Q|<img src="#{uri.sub(/^file:/,'')}"#{attr}/>|
|
321
|
+
end
|
322
|
+
|
323
|
+
def link(node)
|
324
|
+
if node.caption.nil?
|
325
|
+
mk_link(node)
|
326
|
+
else
|
327
|
+
%Q|<div class="figure">
|
328
|
+
<p>#{mk_link(node)}</p>
|
329
|
+
<p>#{node.caption}</p>
|
330
|
+
</div>
|
331
|
+
|
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def mk_link(node)
|
336
|
+
a_attrs = ['href', 'name', 'target', 'charset', 'hreflang', 'type', 'rel', 'rev',
|
337
|
+
'tabindex', 'accesskey', 'shape', 'coords']
|
338
|
+
a_attr = ''
|
339
|
+
img_attr = ''
|
340
|
+
node.html_options.each do |k, v|
|
341
|
+
if a_attrs.include? k
|
342
|
+
a_attr = ' ' if a_attr.empty?
|
343
|
+
a_attr += "#{k}=#{v}"
|
344
|
+
else
|
345
|
+
img_attr = ' ' if img_attr.empty?
|
346
|
+
img_attr += "#{k}=#{v} "
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
desc = exec_children node
|
351
|
+
|
352
|
+
if desc.empty?
|
353
|
+
if node.uri =~ @image_file_reg
|
354
|
+
image_tag(node.uri, a_attr+img_attr)
|
355
|
+
else
|
356
|
+
%Q|<a href="#{node.uri.sub(/^file:/,'')}"#{a_attr+img_attr}>node.uri</a>|
|
357
|
+
end
|
358
|
+
else
|
359
|
+
if desc =~ @image_file_reg
|
360
|
+
desc = image_tag desc, img_attr
|
361
|
+
else
|
362
|
+
a_attr += img_attr
|
363
|
+
end
|
364
|
+
%Q|<a href="#{node.uri.sub(/^file:/,'')}"#{a_attr+img_attr}>#{desc}</a>|
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def table(node)
|
369
|
+
indent = get_indent
|
370
|
+
ret = indent + %Q|<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">\n|
|
371
|
+
ret += indent + ' ' + %Q|<caption></caption>\n|
|
372
|
+
#ret += indent + ' ' + %Q|<colgroup><col align="left" /><col align="left" /><col align="left" /></colgroup>\n|
|
373
|
+
ret += indent + ' ' + "<tbody>\n"
|
374
|
+
ret += exec_list node.hrows
|
375
|
+
ret += exec_children node
|
376
|
+
ret += indent + ' ' + "</tbody>\n"
|
377
|
+
ret += indent + "</table>"
|
378
|
+
end
|
379
|
+
|
380
|
+
def table_row(node)
|
381
|
+
indent = get_indent + " "
|
382
|
+
ret = ""
|
383
|
+
s = node.is_head? ? '<th>' : '<td>'
|
384
|
+
e = node.is_head? ? '</th>' : '</td>'
|
385
|
+
node.children.each {|col|
|
386
|
+
ret += s + exec_list(col) + e
|
387
|
+
}
|
388
|
+
indent + "<tr>\n " + indent + ret + "\n" + indent + "</tr>\n"
|
389
|
+
end
|
390
|
+
|
391
|
+
def variable(node)
|
392
|
+
fvs = ['CAPTION', 'ATTR_HTML', 'TEXT']
|
393
|
+
if fvs.include? node.name
|
394
|
+
@flash_vars[node.name] = node.value
|
395
|
+
else
|
396
|
+
@options[node.name] = node.value
|
397
|
+
end
|
398
|
+
''
|
399
|
+
end
|
400
|
+
|
401
|
+
def clear_vars
|
402
|
+
@flash_vars.clear
|
403
|
+
end
|
404
|
+
|
405
|
+
def lists(node)
|
406
|
+
tags = { :UNORDERED_LIST => ['<ul>', '</ul>'],
|
407
|
+
:ORDERED_LIST => ['<ol>', '</ol>'],
|
408
|
+
:DEFINITION_LIST => ['<dl>', '</dl>'],
|
409
|
+
}
|
410
|
+
indent = get_indent
|
411
|
+
@list_level += 1
|
412
|
+
body = exec_children node
|
413
|
+
@list_level -= 1
|
414
|
+
"#{indent}#{tags[node.kind][0]}\n#{body.chomp}\n#{indent}#{tags[node.kind][1]}\n"
|
415
|
+
end
|
416
|
+
|
417
|
+
# list_item
|
418
|
+
def list_item(node)
|
419
|
+
indent = get_indent
|
420
|
+
if node.children.empty?
|
421
|
+
if node.type == :DL_START
|
422
|
+
"#{indent}<dt>#{exec_list(node.dt)}</dt>\n#{indent}<dd>#{exec_list(node.value).chomp}</dd>\n"
|
423
|
+
else
|
424
|
+
"#{indent}<li>#{exec_list(node.value).chomp}</li>\n"
|
425
|
+
end
|
426
|
+
else
|
427
|
+
@list_level += 1
|
428
|
+
@p_tag_flag = false
|
429
|
+
str = get_indent + exec_list(node.value)
|
430
|
+
str += exec_children node
|
431
|
+
if node.type == :DL_START
|
432
|
+
str = "#{indent}<dt>#{exec_list(node.dt)}</dt>\n#{indent}<dd>\n#{str.chomp}\n#{indent}</dd>\n"
|
433
|
+
else
|
434
|
+
str = "#{indent}<li>\n#{str.chomp}\n#{indent}</li>\n"
|
435
|
+
end
|
436
|
+
@p_tag_flag = true
|
437
|
+
@list_level -= 1
|
438
|
+
str
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
def footnote_link(node)
|
443
|
+
idx = @footnote_idxs.index node.value
|
444
|
+
unless idx
|
445
|
+
idx = @footnote_idxs.size
|
446
|
+
@footnote_idxs << node.value
|
447
|
+
end
|
448
|
+
idx += 1
|
449
|
+
%Q|<sup><a class="footref" name="fnr.#{idx}" href="#fn.#{idx}">#{idx}</a></sup> |
|
450
|
+
end
|
451
|
+
|
452
|
+
def footnote_define(node)
|
453
|
+
idx = @footnote_idxs.index node.value
|
454
|
+
unless idx
|
455
|
+
idx = @footnote_idxs.size
|
456
|
+
@footnotes_idxs << node.value
|
457
|
+
end
|
458
|
+
@footnotes[idx] = exec_children(node)
|
459
|
+
''
|
460
|
+
end
|
461
|
+
|
462
|
+
def footnotes
|
463
|
+
ret = ''
|
464
|
+
@footnotes.each_index{|idx|
|
465
|
+
n = idx+1
|
466
|
+
val = @footnotes[idx]
|
467
|
+
ret += %Q|<p class="footnote"><sup><a class="footnum" name="fn.#{n}" href="#fnr.#{n}">#{n}</a></sup> #{val}</p>\n|
|
468
|
+
}
|
469
|
+
ret
|
470
|
+
end
|
471
|
+
|
472
|
+
def execute(node)
|
473
|
+
# puts "node:#{node.kind} [#{node.value}]\n"
|
474
|
+
# STDERR.puts node.inspect
|
475
|
+
return '' if node.done?
|
476
|
+
case node.kind
|
477
|
+
when :SECTION
|
478
|
+
section node
|
479
|
+
when :HEADLINE
|
480
|
+
headline node
|
481
|
+
when :TEXTBLOCK
|
482
|
+
textblock node
|
483
|
+
when :WHITELINE, :WHITELINES
|
484
|
+
@p_tag_flag = true
|
485
|
+
if node.verse?
|
486
|
+
"<br>\n" * node.value
|
487
|
+
else
|
488
|
+
"\n" * node.value
|
489
|
+
end
|
490
|
+
when :STRING
|
491
|
+
h node.value
|
492
|
+
when :QUOTE
|
493
|
+
if node.value == "\n"
|
494
|
+
'<br/>'
|
495
|
+
else
|
496
|
+
node.value
|
497
|
+
end
|
498
|
+
when :TEXTLINE
|
499
|
+
textline node
|
500
|
+
when :EMPHASIS
|
501
|
+
"<b>#{ exec_children node }</b>"
|
502
|
+
when :ITALIC
|
503
|
+
"<i>#{ exec_children node }</i>"
|
504
|
+
when :UNDER_LINE
|
505
|
+
%Q|<span style="text-decoration: underline;">#{exec_children node}</span>|
|
506
|
+
when :STRIKE_THROUGH
|
507
|
+
"<del>#{ exec_children node}</del>"
|
508
|
+
when :CODE, :VERBATIM
|
509
|
+
"<code>#{ exec_children node }</code>"
|
510
|
+
when :VARIABLE
|
511
|
+
variable node
|
512
|
+
when :UNORDERED_LIST, :ORDERED_LIST, :DEFINITION_LIST
|
513
|
+
lists node
|
514
|
+
when :LIST_ITEM
|
515
|
+
list_item node
|
516
|
+
when :LINK
|
517
|
+
link node
|
518
|
+
when :BLOCK
|
519
|
+
blocks node
|
520
|
+
when :TABLE
|
521
|
+
table node
|
522
|
+
when :TABLE_ROW
|
523
|
+
table_row node
|
524
|
+
when :FN_LINK
|
525
|
+
footnote_link node
|
526
|
+
when :FN_DEFINE
|
527
|
+
footnote_define node
|
528
|
+
else
|
529
|
+
puts "not implimented=>[#{node.kind}](#{node.inspect})"
|
530
|
+
''
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
# HTML escape
|
535
|
+
def html_escape(s)
|
536
|
+
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
537
|
+
end
|
538
|
+
alias h html_escape
|
539
|
+
|
540
|
+
end
|
541
|
+
|
542
|
+
end
|
data/lib/org-parse.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module OrgParse
|
3
|
+
|
4
|
+
# :stopdoc:
|
5
|
+
VERSION = '0.0.2'
|
6
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
|
+
# :startdoc:
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# Returns the version string for the library.
|
13
|
+
#
|
14
|
+
def self.version
|
15
|
+
VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the library path for the module. If any arguments are given,
|
19
|
+
# they will be joined to the end of the libray path using
|
20
|
+
# <tt>File.join</tt>.
|
21
|
+
#
|
22
|
+
def self.libpath( *args )
|
23
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the lpath for the module. If any arguments are given,
|
27
|
+
# they will be joined to the end of the path using
|
28
|
+
# <tt>File.join</tt>.
|
29
|
+
#
|
30
|
+
def self.path( *args )
|
31
|
+
args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.to_html(fname)
|
35
|
+
parser = StructParser.new(fname)
|
36
|
+
end
|
37
|
+
|
38
|
+
end # module OrgParse
|
39
|
+
|
40
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'utils.rb')
|
41
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'node.rb')
|
42
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'struct-scanner.rb')
|
43
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'struct-parser.rb')
|
44
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'visitor.rb')
|
45
|
+
require ::File.join(OrgParse::LIBPATH , 'org-parse', 'textile-visitor.rb')
|
46
|
+
|
data/org-parse.gemspec
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{org-parse}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["knb"]
|
12
|
+
s.date = %q{2010-03-23}
|
13
|
+
s.description = %q{This gem contains libraries for parsing org-mode files and build html or textile format file}
|
14
|
+
s.email = %q{knb@artif.org}
|
15
|
+
s.executables = ["org-parse", "org-test"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"ChangeLog",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"ChangeLog",
|
25
|
+
"LICENSE",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION.yml",
|
29
|
+
"bin/org-parse",
|
30
|
+
"bin/org-test",
|
31
|
+
"doc/images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png",
|
32
|
+
"doc/org-parse.html",
|
33
|
+
"doc/org-parse.org",
|
34
|
+
"doc/struct.dot",
|
35
|
+
"doc/struct.png",
|
36
|
+
"examples/body-only.html.erb",
|
37
|
+
"examples/dot.org-parse-rc",
|
38
|
+
"lib/org-parse.rb",
|
39
|
+
"lib/org-parse/inline-parser.output",
|
40
|
+
"lib/org-parse/inline-parser.rb",
|
41
|
+
"lib/org-parse/inline-parser.ry",
|
42
|
+
"lib/org-parse/inline-parser.tab.rb",
|
43
|
+
"lib/org-parse/node.rb",
|
44
|
+
"lib/org-parse/struct-parser.output",
|
45
|
+
"lib/org-parse/struct-parser.rb",
|
46
|
+
"lib/org-parse/struct-parser.ry",
|
47
|
+
"lib/org-parse/struct-parser.tab.rb",
|
48
|
+
"lib/org-parse/struct-scanner.rb",
|
49
|
+
"lib/org-parse/templates/single.html.erb",
|
50
|
+
"lib/org-parse/textile-visitor.rb",
|
51
|
+
"lib/org-parse/utils.rb",
|
52
|
+
"lib/org-parse/visitor.rb",
|
53
|
+
"org-parse.gemspec",
|
54
|
+
"rakelib/racc.rake",
|
55
|
+
"test/data/blocks.org",
|
56
|
+
"test/data/emphasis.org",
|
57
|
+
"test/data/footnote.html",
|
58
|
+
"test/data/footnote.org",
|
59
|
+
"test/data/html-export.html",
|
60
|
+
"test/data/html-export.org",
|
61
|
+
"test/data/images.html",
|
62
|
+
"test/data/images.org",
|
63
|
+
"test/data/index.org",
|
64
|
+
"test/data/lily20100228.jpg",
|
65
|
+
"test/data/lily20100228t.jpg",
|
66
|
+
"test/data/link.org",
|
67
|
+
"test/data/list_before_1st_headline.html",
|
68
|
+
"test/data/list_before_1st_headline.org",
|
69
|
+
"test/data/lists.html",
|
70
|
+
"test/data/lists.org",
|
71
|
+
"test/data/no-headline.org",
|
72
|
+
"test/data/one-headline.org",
|
73
|
+
"test/data/paragraph.org",
|
74
|
+
"test/data/quote.org",
|
75
|
+
"test/data/sections.html",
|
76
|
+
"test/data/sections.org",
|
77
|
+
"test/data/simple-list.org",
|
78
|
+
"test/data/skip_t.org",
|
79
|
+
"test/data/structure.org",
|
80
|
+
"test/data/table.org",
|
81
|
+
"test/data/test-list.org",
|
82
|
+
"test/data/text-bef-hl.org",
|
83
|
+
"test/data/text.org",
|
84
|
+
"test/data/title.html",
|
85
|
+
"test/data/title.org",
|
86
|
+
"test/data/verse.org",
|
87
|
+
"test/helper.rb",
|
88
|
+
"test/test_org-parse.rb"
|
89
|
+
]
|
90
|
+
s.homepage = %q{http://github.com/knb/org-parse}
|
91
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
92
|
+
s.require_paths = ["lib"]
|
93
|
+
s.rubygems_version = %q{1.3.5}
|
94
|
+
s.summary = %q{parse and convert Org-Mode file}
|
95
|
+
s.test_files = [
|
96
|
+
"test/test_org-parse.rb",
|
97
|
+
"test/helper.rb"
|
98
|
+
]
|
99
|
+
|
100
|
+
if s.respond_to? :specification_version then
|
101
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
102
|
+
s.specification_version = 3
|
103
|
+
|
104
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
105
|
+
s.add_development_dependency(%q<ultraviolet>, [">= 0"])
|
106
|
+
else
|
107
|
+
s.add_dependency(%q<ultraviolet>, [">= 0"])
|
108
|
+
end
|
109
|
+
else
|
110
|
+
s.add_dependency(%q<ultraviolet>, [">= 0"])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|