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
data/.document
ADDED
data/.gitignore
ADDED
data/ChangeLog
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 kensei nakamura
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
= org-parse
|
2
|
+
|
3
|
+
A library of Ruby which converts a document of Org-Mode into other formats.
|
4
|
+
http://orgmode.org/
|
5
|
+
|
6
|
+
I refer to cords of org-ruby.
|
7
|
+
http://orgmode.org/worg/org-tutorials/org-ruby.php
|
8
|
+
|
9
|
+
== using gems
|
10
|
+
ultraviolet (for syntax highlight)
|
11
|
+
shoulda (for test)
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
=== command line tool
|
16
|
+
|
17
|
+
Usage: org-parse [options] <file>
|
18
|
+
-h, --help Show this message
|
19
|
+
-f, --format FORMAT Translate the ORG file to the specified format. html(default) or textile
|
20
|
+
-t, --template TEMPLATE Erb template to build the html output.
|
21
|
+
|
22
|
+
format
|
23
|
+
html (default)
|
24
|
+
textile
|
25
|
+
|
26
|
+
template
|
27
|
+
Erb script.
|
28
|
+
default: lib/org-parse/templates/single.html.erb
|
29
|
+
|
30
|
+
variables
|
31
|
+
* title -- document title
|
32
|
+
* language -- document language
|
33
|
+
* charset
|
34
|
+
* add_to_head -- additional lines for <head> ... </head>
|
35
|
+
* before_text -- Texts before first section( #+TEXT ...)
|
36
|
+
* body -- body contents
|
37
|
+
* footnotes -- footnote definitions
|
38
|
+
* @options[] -- options
|
39
|
+
|
40
|
+
function
|
41
|
+
* table_of_contents
|
42
|
+
|
43
|
+
=== as libraly
|
44
|
+
see bin/org-parse
|
45
|
+
|
46
|
+
Get a parser
|
47
|
+
parser = OrgParse::StructParser.new(data, title)
|
48
|
+
data: Org-Mode document (String)
|
49
|
+
title: Document title (Optional)
|
50
|
+
Do parse
|
51
|
+
root = parser.parse
|
52
|
+
Get a visitor
|
53
|
+
visitor = OrgParse::HtmlVisitor.new(root, template)
|
54
|
+
or
|
55
|
+
visitor = OrgParse::TextileVisitor.new(root)
|
56
|
+
|
57
|
+
template is optional. default is lib/org-parse/templates/single.html.erb
|
58
|
+
Build output
|
59
|
+
visitor.build
|
60
|
+
|
61
|
+
=== todo
|
62
|
+
* write documents
|
63
|
+
* make tests
|
64
|
+
* impilment meny functions...
|
65
|
+
|
66
|
+
== Copyright
|
67
|
+
|
68
|
+
Copyright (c) 2010 knb. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "org-parse"
|
8
|
+
gem.summary = "parse and convert Org-Mode file"
|
9
|
+
gem.description = %Q|This gem contains libraries for parsing org-mode files and build html or textile format file|
|
10
|
+
gem.email = "knb@artif.org"
|
11
|
+
gem.homepage = "http://github.com/knb/org-parse"
|
12
|
+
gem.authors = ["knb"]
|
13
|
+
gem.add_development_dependency "ultraviolet", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "org-parse #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
rdoc.options = ["--charset", "utf-8"]
|
54
|
+
end
|
data/VERSION.yml
ADDED
data/bin/org-parse
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# require File.expand_path(
|
4
|
+
# File.join(File.dirname(__FILE__), %w[.. lib org-parse]))
|
5
|
+
require 'rubygems'
|
6
|
+
require 'org-parse'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
options_parser = OptionParser.new do |opts|
|
11
|
+
options[:help] = false
|
12
|
+
options[:format] = :html
|
13
|
+
options[:template] = nil
|
14
|
+
|
15
|
+
opts.banner = "Usage: org-parse [options] <file>"
|
16
|
+
|
17
|
+
opts.on("-h", "--help", "Show this message") do |v|
|
18
|
+
options[:help] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-f", "--format FORMAT", [:html, :textile],
|
22
|
+
"Translate the ORG file to the specified format. html(default) or textile") do |v|
|
23
|
+
options[:format] = v
|
24
|
+
end
|
25
|
+
opts.on("-t", "--template TEMPLATE",
|
26
|
+
"Erb template to build the html output.") do |v|
|
27
|
+
options[:template] = v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
options_parser.parse!
|
33
|
+
if (ARGV.length == 0) then
|
34
|
+
puts options_parser
|
35
|
+
else
|
36
|
+
data = IO.read(ARGV[0])
|
37
|
+
|
38
|
+
parser = OrgParse::StructParser.new(data, File.basename(ARGV[0], '.*'))
|
39
|
+
root = parser.parse
|
40
|
+
if options[:format] == :html
|
41
|
+
visitor = OrgParse::HtmlVisitor.new(root, options[:template])
|
42
|
+
elsif
|
43
|
+
visitor = OrgParse::TextileVisitor.new(root)
|
44
|
+
else
|
45
|
+
raise OptionParser::ParseError.new('format error')
|
46
|
+
end
|
47
|
+
puts visitor.build
|
48
|
+
end
|
49
|
+
rescue OptionParser::ParseError
|
50
|
+
puts options_parser
|
51
|
+
end
|
data/bin/org-test
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. lib org-parse]))
|
5
|
+
#require 'rubygems'
|
6
|
+
#require 'org-parse'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
options_parser = OptionParser.new do |opts|
|
11
|
+
options[:help] = false
|
12
|
+
options[:format] = :html
|
13
|
+
options[:template] = nil
|
14
|
+
|
15
|
+
opts.banner = "Usage: org-parse [options] <file>"
|
16
|
+
|
17
|
+
opts.on("-h", "--help", "Show this message") do |v|
|
18
|
+
options[:help] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-f", "--format FORMAT", [:html, :textile],
|
22
|
+
"Translate the ORG file to the specified format.(not yet)") do |v|
|
23
|
+
options[:format] = v
|
24
|
+
end
|
25
|
+
opts.on("-t", "--template TEMPLATE",
|
26
|
+
"Erb template for build the output.") do |v|
|
27
|
+
options[:template] = v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_test(node, opt = {})
|
32
|
+
cnt = 1;
|
33
|
+
|
34
|
+
section_no = node.section_no if node.kind == :SECTION
|
35
|
+
node.children.each do |n|
|
36
|
+
n.parent = node
|
37
|
+
if n.kind == :SECTION
|
38
|
+
if node.kind == :ROOT
|
39
|
+
n.section_no = cnt.to_s
|
40
|
+
else
|
41
|
+
n.section_no = section_no + "." + cnt.to_s
|
42
|
+
end
|
43
|
+
cnt += 1
|
44
|
+
end
|
45
|
+
update_test n, opt
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def disp_toc(node)
|
50
|
+
node.children.each do |n|
|
51
|
+
if n.kind == :SECTION
|
52
|
+
puts n.section_no
|
53
|
+
disp_toc(n)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
begin
|
59
|
+
options_parser.parse!
|
60
|
+
if (ARGV.length == 0) then
|
61
|
+
puts options_parser
|
62
|
+
else
|
63
|
+
data = IO.read(ARGV[0])
|
64
|
+
|
65
|
+
parser = OrgParse::StructParser.new(data, File.basename(ARGV[0], '.*'))
|
66
|
+
root = parser.parse
|
67
|
+
update_test(root)
|
68
|
+
disp_toc(root)
|
69
|
+
# visitor = OrgParse::HtmlVisitor.new(root, options[:template])
|
70
|
+
# puts visitor.build
|
71
|
+
end
|
72
|
+
rescue OptionParser::ParseError
|
73
|
+
puts options_parser
|
74
|
+
end
|
data/doc/org-parse.html
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml"
|
5
|
+
lang="en" xml:lang="en">
|
6
|
+
<head>
|
7
|
+
<title>OrgParse</title>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
9
|
+
<meta name="generator" content="Org-mode"/>
|
10
|
+
<meta name="generated" content="2010-03-10 11:09:20 JST"/>
|
11
|
+
<meta name="author" content="Kensei Nakamura"/>
|
12
|
+
<meta name="description" content=""/>
|
13
|
+
<meta name="keywords" content=""/>
|
14
|
+
<style type="text/css">
|
15
|
+
<!--/*--><![CDATA[/*><!--*/
|
16
|
+
html { font-family: Times, serif; font-size: 12pt; }
|
17
|
+
.title { text-align: center; }
|
18
|
+
.todo { color: red; }
|
19
|
+
.done { color: green; }
|
20
|
+
.tag { background-color: #add8e6; font-weight:normal }
|
21
|
+
.target { }
|
22
|
+
.timestamp { color: #bebebe; }
|
23
|
+
.timestamp-kwd { color: #5f9ea0; }
|
24
|
+
p.verse { margin-left: 3% }
|
25
|
+
pre {
|
26
|
+
border: 1pt solid #AEBDCC;
|
27
|
+
background-color: #F3F5F7;
|
28
|
+
padding: 5pt;
|
29
|
+
font-family: courier, monospace;
|
30
|
+
font-size: 90%;
|
31
|
+
overflow:auto;
|
32
|
+
}
|
33
|
+
table { border-collapse: collapse; }
|
34
|
+
td, th { vertical-align: top; }
|
35
|
+
dt { font-weight: bold; }
|
36
|
+
div.figure { padding: 0.5em; }
|
37
|
+
div.figure p { text-align: center; }
|
38
|
+
.linenr { font-size:smaller }
|
39
|
+
.code-highlighted {background-color:#ffff00;}
|
40
|
+
.org-info-js_info-navigation { border-style:none; }
|
41
|
+
#org-info-js_console-label { font-size:10px; font-weight:bold;
|
42
|
+
white-space:nowrap; }
|
43
|
+
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
|
44
|
+
font-weight:bold; }
|
45
|
+
/*]]>*/-->
|
46
|
+
</style>
|
47
|
+
<script type="text/javascript">
|
48
|
+
<!--/*--><![CDATA[/*><!--*/
|
49
|
+
function CodeHighlightOn(elem, id)
|
50
|
+
{
|
51
|
+
var target = document.getElementById(id);
|
52
|
+
if(null != target) {
|
53
|
+
elem.cacheClassElem = elem.className;
|
54
|
+
elem.cacheClassTarget = target.className;
|
55
|
+
target.className = "code-highlighted";
|
56
|
+
elem.className = "code-highlighted";
|
57
|
+
}
|
58
|
+
}
|
59
|
+
function CodeHighlightOff(elem, id)
|
60
|
+
{
|
61
|
+
var target = document.getElementById(id);
|
62
|
+
if(elem.cacheClassElem)
|
63
|
+
elem.className = elem.cacheClassElem;
|
64
|
+
if(elem.cacheClassTarget)
|
65
|
+
target.className = elem.cacheClassTarget;
|
66
|
+
}
|
67
|
+
/*]]>*///-->
|
68
|
+
</script>
|
69
|
+
</head>
|
70
|
+
<body>
|
71
|
+
<div id="content">
|
72
|
+
|
73
|
+
<h1 class="title">OrgParse</h1>
|
74
|
+
|
75
|
+
|
76
|
+
<div id="table-of-contents">
|
77
|
+
<h2>Table of Contents</h2>
|
78
|
+
<div id="text-table-of-contents">
|
79
|
+
<ul>
|
80
|
+
<li><a href="#sec-1">1 これは何か? </a></li>
|
81
|
+
<li><a href="#sec-2">2 何故作ったか。 </a></li>
|
82
|
+
<li><a href="#sec-3">3 構成 </a>
|
83
|
+
<ul>
|
84
|
+
<li><a href="#sec-3.1">3.1 概要 </a></li>
|
85
|
+
</ul>
|
86
|
+
</li>
|
87
|
+
<li><a href="#sec-4">4 使い方 </a>
|
88
|
+
<ul>
|
89
|
+
<li><a href="#sec-4.1">4.1 org-parse コマンド </a></li>
|
90
|
+
<li><a href="#sec-4.2">4.2 org-parse ライブラリ </a></li>
|
91
|
+
</ul>
|
92
|
+
</li>
|
93
|
+
</ul>
|
94
|
+
</div>
|
95
|
+
</div>
|
96
|
+
|
97
|
+
<div id="outline-container-1" class="outline-2">
|
98
|
+
<h2 id="sec-1"><span class="section-number-2">1</span> これは何か? </h2>
|
99
|
+
<div class="outline-text-2" id="text-1">
|
100
|
+
|
101
|
+
<p><a href="http://orgmode.org">Org-Mode</a> で書かれた文書を他のフォーマットに変換するためのライブラリである。
|
102
|
+
</p></div>
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<div id="outline-container-2" class="outline-2">
|
107
|
+
<h2 id="sec-2"><span class="section-number-2">2</span> 何故作ったか。 </h2>
|
108
|
+
<div class="outline-text-2" id="text-2">
|
109
|
+
|
110
|
+
<p>直接の動機は、Redmine の文書やWikiに、Org-Modeで書いた文書を入れたかったから。
|
111
|
+
長文になると、textileで書くのは骨が折れる。Org-Mode のアウトライン操作は快適である。
|
112
|
+
</p>
|
113
|
+
<p>
|
114
|
+
この用途には<a href="http://orgmode.org/worg/org-tutorials/org-ruby.php">Org-ruby</a> が使えそうだけど、日本語の textile 文書との相性が悪かった。
|
115
|
+
Org-rubyに手を入れるか自分用を作るか迷ったのだが、Racc の勉強を兼ねて一から作ることにした。
|
116
|
+
</p></div>
|
117
|
+
|
118
|
+
</div>
|
119
|
+
|
120
|
+
<div id="outline-container-3" class="outline-2">
|
121
|
+
<h2 id="sec-3"><span class="section-number-2">3</span> 構成 </h2>
|
122
|
+
<div class="outline-text-2" id="text-3">
|
123
|
+
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
<div id="outline-container-3.1" class="outline-3">
|
128
|
+
<h3 id="sec-3.1"><span class="section-number-3">3.1</span> 概要 </h3>
|
129
|
+
<div class="outline-text-3" id="text-3.1">
|
130
|
+
|
131
|
+
<p>org-file を、スキャナー、パーサーを通して、構文木を作成する。
|
132
|
+
出来上がった構文木から、HTMLや、textile 等のフォーマットの文書を構築する。
|
133
|
+
</p>
|
134
|
+
<p>
|
135
|
+
<img src="images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png" alt="images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png" />
|
136
|
+
</p>
|
137
|
+
<p>
|
138
|
+
RDtool の構成と同じ様な形式である。
|
139
|
+
visitor の部分を置き換えることで、様々なフォーマットへの対応を行う予定である。
|
140
|
+
</p></div>
|
141
|
+
</div>
|
142
|
+
|
143
|
+
</div>
|
144
|
+
|
145
|
+
<div id="outline-container-4" class="outline-2">
|
146
|
+
<h2 id="sec-4"><span class="section-number-2">4</span> 使い方 </h2>
|
147
|
+
<div class="outline-text-2" id="text-4">
|
148
|
+
|
149
|
+
|
150
|
+
</div>
|
151
|
+
|
152
|
+
<div id="outline-container-4.1" class="outline-3">
|
153
|
+
<h3 id="sec-4.1"><span class="section-number-3">4.1</span> org-parse コマンド </h3>
|
154
|
+
<div class="outline-text-3" id="text-4.1">
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
<pre class="example">Usage: org-parse [options] <file>
|
160
|
+
-h, --help Show this message
|
161
|
+
-f, --format FORMAT Translate the ORG file to the specified format.(not yet)
|
162
|
+
-t, --template TEMPLATE Erb template for build the output.
|
163
|
+
</pre>
|
164
|
+
|
165
|
+
|
166
|
+
</div>
|
167
|
+
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div id="outline-container-4.2" class="outline-3">
|
171
|
+
<h3 id="sec-4.2"><span class="section-number-3">4.2</span> org-parse ライブラリ </h3>
|
172
|
+
<div class="outline-text-3" id="text-4.2">
|
173
|
+
|
174
|
+
<p>以下の様な感じ。
|
175
|
+
</p>
|
176
|
+
|
177
|
+
|
178
|
+
<pre class="example">data = IO.read(ARGV[0])
|
179
|
+
|
180
|
+
# ソース文字列と、タイトルに使われるファイルのベース名を与える
|
181
|
+
parser = OrgParse::StructParser.new(data, File.basename(ARGV[0], '.*'))
|
182
|
+
# 構文解析を実行して、構文木を取得する
|
183
|
+
root = parser.parse
|
184
|
+
# ビジターに構文木を渡す。
|
185
|
+
visitor = OrgParse::HtmlVisitor.new(root, options[:template])
|
186
|
+
# 結果を得る
|
187
|
+
puts visitor.build
|
188
|
+
</pre>
|
189
|
+
|
190
|
+
|
191
|
+
</div>
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
<div id="postamble">
|
195
|
+
<p class="author"> Author: Kensei Nakamura
|
196
|
+
<a href="mailto:kensei@dalmore.artifarm.com"><kensei@dalmore.artifarm.com></a>
|
197
|
+
</p>
|
198
|
+
<p class="date"> Date: 2010-03-10 11:09:20 JST</p>
|
199
|
+
<p class="creator">HTML generated by org-mode 6.34c in emacs 23</p>
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
</body>
|
203
|
+
</html>
|
data/doc/org-parse.org
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
OrgParse
|
2
|
+
* これは何か?
|
3
|
+
[[http://orgmode.org][Org-Mode]] で書かれた文書を他のフォーマットに変換するためのライブラリである。
|
4
|
+
** 何故作ったか。
|
5
|
+
直接の動機は、Redmine の文書やWikiに、Org-Modeで書いた文書を入れたかったから。
|
6
|
+
長文になると、textileで書くのは骨が折れる。Org-Mode のアウトライン操作は快適である。
|
7
|
+
|
8
|
+
この用途には[[http://orgmode.org/worg/org-tutorials/org-ruby.php][Org-ruby]] が使えそうだけど、日本語の textile 文書との相性が悪かった。
|
9
|
+
Org-rubyに手を入れるか自分用を作るか迷ったのだが、Racc の勉強を兼ねて一から作ることにした。
|
10
|
+
|
11
|
+
が、構文エラーを出さない方針にしてみると、Racc 等の構文解析ライブラリは使いにくかった。
|
12
|
+
プログラミング言語じゃないから、あまりガチガチにすると使いにくいし、悩ましい所である。
|
13
|
+
* 構成
|
14
|
+
** 概要
|
15
|
+
org-file を、スキャナー、パーサーを通して、構文木を作成する。
|
16
|
+
出来上がった構文木から、HTMLや、textile 等のフォーマットの文書を構築する。
|
17
|
+
#+BEGIN_DOT images/org-parse-struct.png -Tpng
|
18
|
+
digraph structure {
|
19
|
+
graph [rankdir = LR];
|
20
|
+
"org-file" [shape = box];
|
21
|
+
output [shape = box];
|
22
|
+
tree [shape = box];
|
23
|
+
"org-file" -> parser;
|
24
|
+
parser -> tree;
|
25
|
+
tree -> visitor;
|
26
|
+
visitor -> output;
|
27
|
+
}
|
28
|
+
#+END_DOT
|
29
|
+
RDtool の構成と同じ様な形式である。
|
30
|
+
visitor の部分を置き換えることで、様々なフォーマットへ変換出来るようになる(予定)。
|
31
|
+
* 使い方
|
32
|
+
** org-parse コマンド
|
33
|
+
#+begin_example
|
34
|
+
Usage: org-parse [options] <file>
|
35
|
+
-h, --help Show this message
|
36
|
+
-f, --format FORMAT Translate the ORG file to the specified format.(not yet)
|
37
|
+
-t, --template TEMPLATE Erb template for build the output.
|
38
|
+
#+end_example
|
39
|
+
** org-parse ライブラリ
|
40
|
+
以下の様な感じ。
|
41
|
+
#+begin_example
|
42
|
+
data = IO.read(ARGV[0])
|
43
|
+
|
44
|
+
# ソース文字列と、タイトルに使われるファイルのベース名を与える
|
45
|
+
parser = OrgParse::StructParser.new(data, File.basename(ARGV[0], '.*'))
|
46
|
+
# 構文解析を実行して、構文木を取得する
|
47
|
+
root = parser.parse
|
48
|
+
# ビジターに構文木を渡す。
|
49
|
+
visitor = OrgParse::HtmlVisitor.new(root, options[:template])
|
50
|
+
# 結果を得る
|
51
|
+
puts visitor.build
|
52
|
+
#+end_example
|
53
|
+
* MEMO
|
54
|
+
以下は、これからの修正のための覚書
|
55
|
+
** オプション類の扱い
|
56
|
+
*** プログラム内でのオプションの記憶場所
|
57
|
+
オプションや、セクション番号等の情報は、各Nodeに持たせる。
|
58
|
+
つまり、ビジターで、コンテキストやオプション類の判定を行わないで済む様にする。
|
59
|
+
- セクション番号を、Section Node に持たせる
|
60
|
+
- Verse、Example 等は、各 BlockNode 配下のnode 自体が知っている
|
61
|
+
*** オプションの指定方法
|
62
|
+
コマンドラインで指定。
|
63
|
+
コンフィグファイルを作る?(~/.org-parse-rc)
|
64
|
+
文書内での指定を最優先する方が正しいか?
|
65
|
+
[[../examples/dot.org-parse-rc]]
|
66
|
+
*** オプションの優先順位
|
67
|
+
- デフォルト設定
|
68
|
+
- .opt-parse
|
69
|
+
- コマンドラインオプション
|
70
|
+
- ソースファイル内の指定
|
71
|
+
|
data/doc/struct.dot
ADDED
data/doc/struct.png
ADDED
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @body %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# org-parse options
|
2
|
+
|
3
|
+
---
|
4
|
+
:author: knb
|
5
|
+
:email: knb@artif.org
|
6
|
+
:language: ja
|
7
|
+
:charset: utf-8
|
8
|
+
:skip: false
|
9
|
+
:url: http://www.artif.org/
|
10
|
+
:default_title: (no title)
|
11
|
+
:H: 3
|
12
|
+
:toc: true
|
13
|
+
:timestamp: true
|
14
|
+
:uv: true
|
15
|
+
:num: true
|
16
|
+
# :style: <link rel="stylesheet" type="text/css" href="css/eiffel.css" />
|
17
|
+
# :creator: OrgParse 0.0.2 Powered by Ruby 1.8.7
|
18
|
+
# :title:
|
19
|
+
:text:
|
20
|
+
- Texts before 1st section.
|
21
|
+
- This must be array.
|