org-ruby 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bnsignore +18 -0
- data/History.txt +24 -0
- data/README.txt +66 -0
- data/Rakefile +22 -0
- data/TAGS +128 -0
- data/bin/org-ruby +40 -0
- data/lib/org-ruby.rb +48 -0
- data/lib/org-ruby/headline.rb +75 -0
- data/lib/org-ruby/html_output_buffer.rb +80 -0
- data/lib/org-ruby/line.rb +172 -0
- data/lib/org-ruby/output_buffer.rb +154 -0
- data/lib/org-ruby/parser.rb +72 -0
- data/lib/org-ruby/regexp_helper.rb +156 -0
- data/lib/org-ruby/textile_output_buffer.rb +67 -0
- data/spec/data/freeform.org +111 -0
- data/spec/data/hyp-planning.org +335 -0
- data/spec/data/remember.org +53 -0
- data/spec/headline_spec.rb +55 -0
- data/spec/html_examples/block_code.html +29 -0
- data/spec/html_examples/block_code.org +35 -0
- data/spec/html_examples/blockquote.html +7 -0
- data/spec/html_examples/blockquote.org +13 -0
- data/spec/html_examples/inline-formatting.html +10 -0
- data/spec/html_examples/inline-formatting.org +17 -0
- data/spec/html_examples/lists.html +19 -0
- data/spec/html_examples/lists.org +36 -0
- data/spec/html_examples/tables.html +20 -0
- data/spec/html_examples/tables.org +26 -0
- data/spec/html_examples/text.html +2 -0
- data/spec/html_examples/text.org +16 -0
- data/spec/line_spec.rb +89 -0
- data/spec/parser_spec.rb +86 -0
- data/spec/regexp_helper_spec.rb +57 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/textile_examples/block_code.org +35 -0
- data/spec/textile_examples/block_code.textile +29 -0
- data/spec/textile_examples/blockquote.org +13 -0
- data/spec/textile_examples/blockquote.textile +11 -0
- data/spec/textile_examples/keywords.org +13 -0
- data/spec/textile_examples/keywords.textile +11 -0
- data/spec/textile_examples/links.org +11 -0
- data/spec/textile_examples/links.textile +10 -0
- data/spec/textile_examples/lists.org +36 -0
- data/spec/textile_examples/lists.textile +20 -0
- data/spec/textile_examples/single-space-plain-list.org +13 -0
- data/spec/textile_examples/single-space-plain-list.textile +10 -0
- data/spec/textile_examples/tables.org +26 -0
- data/spec/textile_examples/tables.textile +23 -0
- data/spec/textile_output_buffer_spec.rb +21 -0
- data/test/test_orgmode_parser.rb +0 -0
- metadata +120 -0
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe Orgmode::Parser do
|
5
|
+
it "should open ORG files" do
|
6
|
+
parser = Orgmode::Parser.load(RememberFile)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fail on non-existant files" do
|
10
|
+
lambda { parser = Orgmode::Parser.load("does-not-exist.org") }.should raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should load all of the lines" do
|
14
|
+
parser = Orgmode::Parser.load(RememberFile)
|
15
|
+
parser.lines.length.should eql(53)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find all headlines" do
|
19
|
+
parser = Orgmode::Parser.load(RememberFile)
|
20
|
+
parser.should have(12).headlines
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can find a headline by index" do
|
24
|
+
parser = Orgmode::Parser.load(RememberFile)
|
25
|
+
parser.headlines[1].line.should eql("** YAML header in Webby\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should determine headline levels" do
|
29
|
+
parser = Orgmode::Parser.load(RememberFile)
|
30
|
+
parser.headlines[0].level.should eql(1)
|
31
|
+
parser.headlines[1].level.should eql(2)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should put body lines in headlines" do
|
35
|
+
parser = Orgmode::Parser.load(RememberFile)
|
36
|
+
parser.headlines[0].should have(0).body_lines
|
37
|
+
parser.headlines[1].should have(6).body_lines
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should understand lines before the first headline" do
|
41
|
+
parser = Orgmode::Parser.load(FreeformFile)
|
42
|
+
parser.should have(19).header_lines
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a textile string" do
|
46
|
+
parser = Orgmode::Parser.load(FreeformFile)
|
47
|
+
parser.to_textile.should be_kind_of(String)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can translate textile files" do
|
51
|
+
data_directory = File.join(File.dirname(__FILE__), "textile_examples")
|
52
|
+
org_files = File.expand_path(File.join(data_directory, "*.org" ))
|
53
|
+
files = Dir.glob(org_files)
|
54
|
+
files.each do |file|
|
55
|
+
basename = File.basename(file, ".org")
|
56
|
+
textile_name = File.join(data_directory, basename + ".textile")
|
57
|
+
textile_name = File.expand_path(textile_name)
|
58
|
+
|
59
|
+
expected = IO.read(textile_name)
|
60
|
+
expected.should be_kind_of(String)
|
61
|
+
parser = Orgmode::Parser.new(IO.read(file))
|
62
|
+
actual = parser.to_textile
|
63
|
+
actual.should be_kind_of(String)
|
64
|
+
actual.should == expected
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can translate to html" do
|
69
|
+
data_directory = File.join(File.dirname(__FILE__), "html_examples")
|
70
|
+
org_files = File.expand_path(File.join(data_directory, "*.org" ))
|
71
|
+
files = Dir.glob(org_files)
|
72
|
+
files.each do |file|
|
73
|
+
basename = File.basename(file, ".org")
|
74
|
+
textile_name = File.join(data_directory, basename + ".html")
|
75
|
+
textile_name = File.expand_path(textile_name)
|
76
|
+
|
77
|
+
expected = IO.read(textile_name)
|
78
|
+
expected.should be_kind_of(String)
|
79
|
+
parser = Orgmode::Parser.new(IO.read(file))
|
80
|
+
actual = parser.to_html
|
81
|
+
actual.should be_kind_of(String)
|
82
|
+
actual.should == expected
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
|
+
|
3
|
+
describe Orgmode::RegexpHelper do
|
4
|
+
it "should recognize simple markup" do
|
5
|
+
e = Orgmode::RegexpHelper.new
|
6
|
+
total = 0
|
7
|
+
e.match_all("/italic/") do |border, string|
|
8
|
+
border.should eql("/")
|
9
|
+
string.should eql("italic")
|
10
|
+
total += 1
|
11
|
+
end
|
12
|
+
total.should eql(1)
|
13
|
+
|
14
|
+
total = 0
|
15
|
+
borders = %w[* / ~]
|
16
|
+
strings = %w[bold italic verbatim]
|
17
|
+
e.match_all("This string contains *bold*, /italic/, and ~verbatim~ text.")\
|
18
|
+
do |border, str|
|
19
|
+
border.should eql(borders[total])
|
20
|
+
str.should eql(strings[total])
|
21
|
+
total += 1
|
22
|
+
end
|
23
|
+
total.should eql(3)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not get confused by links" do
|
27
|
+
e = Orgmode::RegexpHelper.new
|
28
|
+
total = 0
|
29
|
+
# Make sure the slashes in these links aren't treated as italics
|
30
|
+
e.match_all("[[http://www.bing.com/twitter]]") do |border, str|
|
31
|
+
total += 1
|
32
|
+
end
|
33
|
+
total.should eql(0)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should correctly perform substitutions" do
|
37
|
+
e = Orgmode::RegexpHelper.new
|
38
|
+
map = {
|
39
|
+
"*" => "strong",
|
40
|
+
"/" => "i",
|
41
|
+
"~" => "pre"
|
42
|
+
}
|
43
|
+
n = e.rewrite_emphasis("This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str|
|
44
|
+
"<#{map[border]}>#{str}</#{map[border]}>"
|
45
|
+
end
|
46
|
+
n.should eql("This string contains <strong>bold</strong>, <i>italic</i>, and <pre>verbatim</pre> text.")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should allow link rewriting" do
|
50
|
+
e = Orgmode::RegexpHelper.new
|
51
|
+
str = e.rewrite_links("[[http://www.bing.com]]") do |link,text|
|
52
|
+
text ||= link
|
53
|
+
"\"#{text}\":#{link}"
|
54
|
+
end
|
55
|
+
str.should eql("\"http://www.bing.com\":http://www.bing.com")
|
56
|
+
end
|
57
|
+
end # describe Orgmode::RegexpHelper
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. lib org-ruby]))
|
4
|
+
|
5
|
+
|
6
|
+
RememberFile = File.join(File.dirname(__FILE__), %w[data remember.org])
|
7
|
+
FreeformFile = File.join(File.dirname(__FILE__), %w[data freeform.org])
|
8
|
+
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
# == Mock Framework
|
12
|
+
#
|
13
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
14
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
15
|
+
#
|
16
|
+
# config.mock_with :mocha
|
17
|
+
# config.mock_with :flexmock
|
18
|
+
# config.mock_with :rr
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
* Block Code
|
2
|
+
|
3
|
+
I need to get block code examples working. In =orgmode=, they look
|
4
|
+
like this:
|
5
|
+
|
6
|
+
#+BEGIN_EXAMPLE
|
7
|
+
|
8
|
+
def initialize(output)
|
9
|
+
@output = output
|
10
|
+
@buffer = ""
|
11
|
+
@output_type = :start
|
12
|
+
@list_indent_stack = []
|
13
|
+
@paragraph_modifier = nil
|
14
|
+
|
15
|
+
@logger = Logger.new(STDERR)
|
16
|
+
@logger.level = Logger::WARN
|
17
|
+
end
|
18
|
+
|
19
|
+
#+END_EXAMPLE
|
20
|
+
|
21
|
+
And now I should be back to normal text.
|
22
|
+
|
23
|
+
Putting in another paragraph for good measure.
|
24
|
+
|
25
|
+
|
26
|
+
Code should also get cancelled by a list, thus:
|
27
|
+
|
28
|
+
#+BEGIN_EXAMPLE
|
29
|
+
This is my code!
|
30
|
+
|
31
|
+
Another line!
|
32
|
+
#+END_EXAMPLE
|
33
|
+
|
34
|
+
- My list should cancel this.
|
35
|
+
- Another list line.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
h1. Block Code
|
2
|
+
|
3
|
+
I need to get block code examples working. In @orgmode@, they look like this:
|
4
|
+
|
5
|
+
bc..
|
6
|
+
def initialize(output)
|
7
|
+
@output = output
|
8
|
+
@buffer = ""
|
9
|
+
@output_type = :start
|
10
|
+
@list_indent_stack = []
|
11
|
+
@paragraph_modifier = nil
|
12
|
+
|
13
|
+
@logger = Logger.new(STDERR)
|
14
|
+
@logger.level = Logger::WARN
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
p. And now I should be back to normal text.
|
19
|
+
|
20
|
+
Putting in another paragraph for good measure.
|
21
|
+
|
22
|
+
Code should also get cancelled by a list, thus:
|
23
|
+
|
24
|
+
bc.. This is my code!
|
25
|
+
|
26
|
+
Another line!
|
27
|
+
|
28
|
+
* My list should cancel this.
|
29
|
+
* Another list line.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
KEYWORDS
|
2
|
+
|
3
|
+
By default, I don't want keywords exported to textile.
|
4
|
+
|
5
|
+
* DONE Recognize standard keywords
|
6
|
+
CLOSED: [2009-12-21 Mon 15:23]
|
7
|
+
|
8
|
+
The standard =orgmode= keywords are TODO and DONE. Recognize those.
|
9
|
+
|
10
|
+
* TODO Recongize buffer-specific keywords
|
11
|
+
|
12
|
+
There's a way to define a custom keyword list in a buffer. Research
|
13
|
+
that and handle it.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
KEYWORDS
|
2
|
+
|
3
|
+
By default, I don't want keywords exported to textile.
|
4
|
+
|
5
|
+
h1. Recognize standard keywords
|
6
|
+
|
7
|
+
The standard @orgmode@ keywords are TODO and DONE. Recognize those.
|
8
|
+
|
9
|
+
h1. Recongize buffer-specific keywords
|
10
|
+
|
11
|
+
There's a way to define a custom keyword list in a buffer. Research that and handle it.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
LINKS
|
2
|
+
|
3
|
+
"http://www.bing.com":http://www.bing.com
|
4
|
+
|
5
|
+
h1. Supported Link Styles
|
6
|
+
|
7
|
+
* "http://www.hotmail.com":http://www.hotmail.com => Simple
|
8
|
+
* "Hotmail":http://www.hotmail.com => With link text
|
9
|
+
* "with spaces":http://url/with%20spaces
|
10
|
+
* "http://url/with spaces":http://url/with%20spaces
|
@@ -0,0 +1,36 @@
|
|
1
|
+
* Lists
|
2
|
+
|
3
|
+
I want to make sure I have great support for lists.
|
4
|
+
|
5
|
+
- This is an unordered list
|
6
|
+
- This continues the unordered list
|
7
|
+
|
8
|
+
And this is a paragraph *after* the list.
|
9
|
+
|
10
|
+
** Wrapping within the list
|
11
|
+
|
12
|
+
- This is a single-line list item in the org file.
|
13
|
+
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
|
14
|
+
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
|
15
|
+
erat, sed diam voluptua. At vero eos et accusam et justo duo
|
16
|
+
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
|
17
|
+
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
|
18
|
+
amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
|
19
|
+
invidunt ut labore et dolore magna aliquyam erat, sed diam
|
20
|
+
voluptua. At vero eos et accusam et justo duo dolores et ea
|
21
|
+
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
|
22
|
+
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet,
|
23
|
+
consetetur sadipscing elitr, sed diam nonumy eirmod tempor
|
24
|
+
invidunt ut labore et dolore magna aliquyam erat, sed diam
|
25
|
+
voluptua. At vero eos et accusam et justo duo dolores et ea
|
26
|
+
rebum. Stet clita kasd gubergren, no sea takimata sanctus est
|
27
|
+
Lorem ipsum dolor sit amet.
|
28
|
+
- And this is the next item. The previous item needs to be on one
|
29
|
+
line to keep =textile= happy.
|
30
|
+
- Ditto the previous line, actually.
|
31
|
+
|
32
|
+
** Edge cases
|
33
|
+
|
34
|
+
- This is a single-line list.
|
35
|
+
And this is a *separate paragraph.* Note the indentation in the org
|
36
|
+
file.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
h1. Lists
|
2
|
+
|
3
|
+
I want to make sure I have great support for lists.
|
4
|
+
|
5
|
+
* This is an unordered list
|
6
|
+
* This continues the unordered list
|
7
|
+
|
8
|
+
And this is a paragraph *after* the list.
|
9
|
+
|
10
|
+
h2. Wrapping within the list
|
11
|
+
|
12
|
+
* This is a single-line list item in the org file.
|
13
|
+
* Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
14
|
+
* And this is the next item. The previous item needs to be on one line to keep @textile@ happy.
|
15
|
+
* Ditto the previous line, actually.
|
16
|
+
|
17
|
+
h2. Edge cases
|
18
|
+
|
19
|
+
* This is a single-line list.
|
20
|
+
And this is a *separate paragraph.* Note the indentation in the org file.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
** Anatomy of a BVP
|
2
|
+
|
3
|
+
Each BVP followed a simple, one-page template with the following
|
4
|
+
parts:
|
5
|
+
|
6
|
+
- Customer Summary
|
7
|
+
- Storyboard
|
8
|
+
- Requirements
|
9
|
+
- Partner teams
|
10
|
+
|
11
|
+
The following sections walk through each section and give an
|
12
|
+
example from one of our BVPs, [[http://windows/hyper-v/initiatives/Value Propositions/DynamicDatacenter-ValueProp.docx][Resource-Smart Virtualization
|
13
|
+
Infrastructure]] (also called /Dynamic Datacenter/).
|
@@ -0,0 +1,10 @@
|
|
1
|
+
h2. Anatomy of a BVP
|
2
|
+
|
3
|
+
Each BVP followed a simple, one-page template with the following parts:
|
4
|
+
|
5
|
+
* Customer Summary
|
6
|
+
* Storyboard
|
7
|
+
* Requirements
|
8
|
+
* Partner teams
|
9
|
+
|
10
|
+
The following sections walk through each section and give an example from one of our BVPs, "Resource-Smart Virtualization Infrastructure":http://windows/hyper-v/initiatives/Value%20Propositions/DynamicDatacenter-ValueProp.docx (also called _Dynamic Datacenter_).
|
@@ -0,0 +1,26 @@
|
|
1
|
+
TABLES
|
2
|
+
|
3
|
+
Different types of ORG tables.
|
4
|
+
|
5
|
+
* Simple table, no header.
|
6
|
+
|
7
|
+
| Cell one | Cell two |
|
8
|
+
| Cell three | Cell four |
|
9
|
+
|
10
|
+
|
11
|
+
* Indented table
|
12
|
+
|
13
|
+
| Cell one |
|
14
|
+
| Cell two |
|
15
|
+
|
16
|
+
And here's some paragraph content. The line breaks will need to get
|
17
|
+
removed here, but not for the tables.
|
18
|
+
|
19
|
+
* Table with header
|
20
|
+
|
21
|
+
| One | Two | Three |
|
22
|
+
|-------+-------+-------|
|
23
|
+
| Four | Five | Six |
|
24
|
+
| Seven | Eight | Nine |
|
25
|
+
|
26
|
+
The separator row should not get printed out.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
TABLES
|
2
|
+
|
3
|
+
Different types of ORG tables.
|
4
|
+
|
5
|
+
h1. Simple table, no header.
|
6
|
+
|
7
|
+
| Cell one | Cell two |
|
8
|
+
| Cell three | Cell four |
|
9
|
+
|
10
|
+
h1. Indented table
|
11
|
+
|
12
|
+
| Cell one |
|
13
|
+
| Cell two |
|
14
|
+
|
15
|
+
And here's some paragraph content. The line breaks will need to get removed here, but not for the tables.
|
16
|
+
|
17
|
+
h1. Table with header
|
18
|
+
|
19
|
+
| One | Two | Three |
|
20
|
+
| Four | Five | Six |
|
21
|
+
| Seven | Eight | Nine |
|
22
|
+
|
23
|
+
The separator row should not get printed out.
|