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.
Files changed (68) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/ChangeLog +4 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +68 -0
  6. data/Rakefile +54 -0
  7. data/VERSION.yml +5 -0
  8. data/bin/org-parse +51 -0
  9. data/bin/org-test +74 -0
  10. data/doc/images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png +0 -0
  11. data/doc/org-parse.html +203 -0
  12. data/doc/org-parse.org +71 -0
  13. data/doc/struct.dot +10 -0
  14. data/doc/struct.png +0 -0
  15. data/examples/body-only.html.erb +1 -0
  16. data/examples/dot.org-parse-rc +21 -0
  17. data/lib/org-parse/inline-parser.output +945 -0
  18. data/lib/org-parse/inline-parser.rb +219 -0
  19. data/lib/org-parse/inline-parser.ry +77 -0
  20. data/lib/org-parse/inline-parser.tab.rb +411 -0
  21. data/lib/org-parse/node.rb +329 -0
  22. data/lib/org-parse/struct-parser.output +1019 -0
  23. data/lib/org-parse/struct-parser.rb +78 -0
  24. data/lib/org-parse/struct-parser.ry +125 -0
  25. data/lib/org-parse/struct-parser.tab.rb +608 -0
  26. data/lib/org-parse/struct-scanner.rb +272 -0
  27. data/lib/org-parse/templates/single.html.erb +118 -0
  28. data/lib/org-parse/textile-visitor.rb +296 -0
  29. data/lib/org-parse/utils.rb +15 -0
  30. data/lib/org-parse/visitor.rb +542 -0
  31. data/lib/org-parse.rb +46 -0
  32. data/org-parse.gemspec +113 -0
  33. data/rakelib/racc.rake +16 -0
  34. data/test/data/blocks.org +67 -0
  35. data/test/data/emphasis.org +7 -0
  36. data/test/data/footnote.html +136 -0
  37. data/test/data/footnote.org +8 -0
  38. data/test/data/html-export.html +1062 -0
  39. data/test/data/html-export.org +342 -0
  40. data/test/data/images.html +179 -0
  41. data/test/data/images.org +30 -0
  42. data/test/data/index.org +242 -0
  43. data/test/data/lily20100228.jpg +0 -0
  44. data/test/data/lily20100228t.jpg +0 -0
  45. data/test/data/link.org +7 -0
  46. data/test/data/list_before_1st_headline.html +119 -0
  47. data/test/data/list_before_1st_headline.org +7 -0
  48. data/test/data/lists.html +284 -0
  49. data/test/data/lists.org +78 -0
  50. data/test/data/no-headline.org +6 -0
  51. data/test/data/one-headline.org +2 -0
  52. data/test/data/paragraph.org +13 -0
  53. data/test/data/quote.org +15 -0
  54. data/test/data/sections.html +173 -0
  55. data/test/data/sections.org +9 -0
  56. data/test/data/simple-list.org +6 -0
  57. data/test/data/skip_t.org +3 -0
  58. data/test/data/structure.org +53 -0
  59. data/test/data/table.org +14 -0
  60. data/test/data/test-list.org +12 -0
  61. data/test/data/text-bef-hl.org +5 -0
  62. data/test/data/text.org +6 -0
  63. data/test/data/title.html +88 -0
  64. data/test/data/title.org +6 -0
  65. data/test/data/verse.org +48 -0
  66. data/test/helper.rb +31 -0
  67. data/test/test_org-parse.rb +148 -0
  68. metadata +134 -0
@@ -0,0 +1,148 @@
1
+ require 'helper'
2
+ require 'nokogiri'
3
+
4
+ class TestOrgParse < Test::Unit::TestCase
5
+
6
+ context "titles" do
7
+
8
+ should "inline parsed" do
9
+ src = "title *bold*\nmay be <b>tag\n"
10
+ ret = to_html(src, 'yyy')
11
+ doc = Nokogiri(ret)
12
+ assert_equal 'title <b>bold</b>', doc.search('h1').inner_html
13
+ end
14
+
15
+ context "no texts before 1st headline" do
16
+ setup do
17
+ @src = "* title\n"
18
+ "there is no lines before 1st headline\n"
19
+ end
20
+
21
+ should "title is filename(default)" do
22
+ src = @src
23
+ ret = to_html(src, 'yyy')
24
+ doc = Nokogiri(ret)
25
+ assert_equal '<h1 class="title">yyy</h1>', doc.search('h1').to_s
26
+ assert_equal '<span class="section-number-2">1</span> title ', doc.search('h2').inner_html
27
+ end
28
+
29
+ should "default title become title with opt skip" do
30
+ src = @src + "#+OPTIONS: skip:t\n"
31
+ ret = to_html(src, 'yyy')
32
+ doc = Nokogiri(ret)
33
+ assert_equal '<h1 class="title">yyy</h1>', doc.search('h1').to_s
34
+ assert_equal '<span class="section-number-2">1</span> title ', doc.search('h2').inner_html
35
+ end
36
+
37
+ should "TITLE set with opt title" do
38
+ src = @src + "#+TITLE: xxxx\n"
39
+ ret = to_html(src, 'yyy')
40
+ doc = Nokogiri(ret)
41
+ assert_equal '<h1 class="title">xxxx</h1>', doc.search('h1').to_s
42
+ assert_equal '<span class="section-number-2">1</span> title ', doc.search('h2').inner_html
43
+ end
44
+
45
+ should "TITLE set with opt title and skip" do
46
+ src = @src + "#+TITLE: xxxx\n" + "#+OPTIONS: skip:t\n"
47
+ ret = to_html(src, 'yyy')
48
+ doc = Nokogiri(ret)
49
+ assert_equal '<h1 class="title">xxxx</h1>', doc.search('h1').to_s
50
+ assert_equal '<span class="section-number-2">1</span> title ', doc.search('h2').inner_html
51
+ end
52
+
53
+ end
54
+
55
+ context "text before 1st headline" do
56
+ setup do
57
+ @src = "- list\n- item1\n* 1st head\n"
58
+ end
59
+
60
+ should "1st text become title" do
61
+ src = @src
62
+ str = to_html(src, 'yyy')
63
+ doc = Nokogiri(str)
64
+ assert_equal '<h1 class="title">- list</h1>', doc.search('h1').to_s
65
+ assert_equal '<li>item1</li>', doc.search('li').to_s
66
+ end
67
+
68
+ should "default title become title with opt skip" do
69
+ src = @src + "#+OPTIONS: skip:t\n"
70
+ ret = to_html(src, 'yyy')
71
+ doc = Nokogiri(ret)
72
+ assert_equal '<h1 class="title">yyy</h1>', doc.search('h1').to_s
73
+ assert_equal '<span class="section-number-2">1</span> 1st head ', doc.search('h2').inner_html
74
+ assert doc.search('li').empty?
75
+ end
76
+
77
+ should "TITLE set with opt title" do
78
+ src = @src + "#+TITLE: xxxx\n"
79
+ ret = to_html(src, 'yyy')
80
+ doc = Nokogiri(ret)
81
+ assert_equal '<h1 class="title">xxxx</h1>', doc.search('h1').to_s
82
+ assert_equal '<span class="section-number-2">1</span> 1st head ', doc.search('h2').inner_html
83
+ end
84
+
85
+ should "TITLE set with opt title and skip" do
86
+ src = @src + "#+TITLE: xxxx\n" + "#+OPTIONS: skip:t\n"
87
+ ret = to_html(src, 'yyy')
88
+ doc = Nokogiri(ret)
89
+ assert_equal '<h1 class="title">xxxx</h1>', doc.search('h1').to_s
90
+ assert_equal '<span class="section-number-2">1</span> 1st head ', doc.search('h2').inner_html
91
+ end
92
+ end
93
+ end
94
+
95
+ context "sections" do
96
+ setup do
97
+ src = load_data('sections.org')
98
+ ret = to_html(src, 'sections')
99
+ @doc = Nokogiri(ret)
100
+ end
101
+
102
+ should "has numbere label" do
103
+ assert_equal 'sections', @doc.search('h1').inner_html
104
+ labels = @doc.search('span')
105
+ assert_equal '<span class="section-number-2">1</span>', labels[0].to_s
106
+ assert_equal '1.1', labels[1].inner_text
107
+ assert_equal '1.1.1', labels[2].inner_text
108
+ assert_equal '1.1.2', labels[3].inner_text
109
+ assert_equal '1.2', labels[4].inner_text
110
+ assert_equal '2', labels[5].inner_text
111
+ assert_equal '2.1', labels[6].inner_text
112
+ assert labels[7].nil?
113
+ s1_1 = @doc.search("//div[@id='outline-container-1.1']")
114
+ assert_equal '1.1', s1_1.search('span')[0].inner_text
115
+ assert_equal 'sec-1.1', s1_1.children[1]['id']
116
+ s1_1_2 = s1_1.search("//div[@id='outline-container-1.1.2']")
117
+ assert_equal 'sec-1.1.2', s1_1_2.children[1]['id']
118
+ end
119
+
120
+ should "be <ul> outline-4" do
121
+ parent = @doc.search("//div[@id='text-2.1']")
122
+ ul = parent.children[1]
123
+ assert_equal 'ul', ul.name
124
+ assert_equal 'li', ul.children[0].name
125
+ assert_equal 'sec-2.1.2', ul.children[2]['id']
126
+ end
127
+ end
128
+
129
+ context "lists" do
130
+ setup do
131
+ src = load_data('lists.org')
132
+ @html = to_html(src, 'lists')
133
+ @doc = Nokogiri(@html)
134
+ end
135
+
136
+ should "have unordered list" do
137
+ # puts @html
138
+ ulli1 = @doc.xpath('//div[@id="text-1"]/ul')[0].xpath('li')
139
+ assert_equal 2, ulli1.size
140
+ assert_equal 'This is an unordered list', ulli1[0].inner_text
141
+ assert_equal 'This continues the unordered list', ulli1[1].inner_text.strip
142
+ p1 = @doc.xpath('//div[@id="text-1"]/ul')[0].next
143
+ assert_equal 'And this is a paragraph after the list.', p1.text.strip
144
+ assert_equal 'p', p1.name
145
+ # puts @doc.to_html
146
+ end
147
+ end
148
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: org-parse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - knb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-23 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ultraviolet
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: This gem contains libraries for parsing org-mode files and build html or textile format file
26
+ email: knb@artif.org
27
+ executables:
28
+ - org-parse
29
+ - org-test
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - ChangeLog
34
+ - LICENSE
35
+ - README.rdoc
36
+ files:
37
+ - .document
38
+ - .gitignore
39
+ - ChangeLog
40
+ - LICENSE
41
+ - README.rdoc
42
+ - Rakefile
43
+ - VERSION.yml
44
+ - bin/org-parse
45
+ - bin/org-test
46
+ - doc/images/org-parse-struct_1ffae50f0c5eb867f9418df6800f40a5cc3d1751.png
47
+ - doc/org-parse.html
48
+ - doc/org-parse.org
49
+ - doc/struct.dot
50
+ - doc/struct.png
51
+ - examples/body-only.html.erb
52
+ - examples/dot.org-parse-rc
53
+ - lib/org-parse.rb
54
+ - lib/org-parse/inline-parser.output
55
+ - lib/org-parse/inline-parser.rb
56
+ - lib/org-parse/inline-parser.ry
57
+ - lib/org-parse/inline-parser.tab.rb
58
+ - lib/org-parse/node.rb
59
+ - lib/org-parse/struct-parser.output
60
+ - lib/org-parse/struct-parser.rb
61
+ - lib/org-parse/struct-parser.ry
62
+ - lib/org-parse/struct-parser.tab.rb
63
+ - lib/org-parse/struct-scanner.rb
64
+ - lib/org-parse/templates/single.html.erb
65
+ - lib/org-parse/textile-visitor.rb
66
+ - lib/org-parse/utils.rb
67
+ - lib/org-parse/visitor.rb
68
+ - org-parse.gemspec
69
+ - rakelib/racc.rake
70
+ - test/data/blocks.org
71
+ - test/data/emphasis.org
72
+ - test/data/footnote.html
73
+ - test/data/footnote.org
74
+ - test/data/html-export.html
75
+ - test/data/html-export.org
76
+ - test/data/images.html
77
+ - test/data/images.org
78
+ - test/data/index.org
79
+ - test/data/lily20100228.jpg
80
+ - test/data/lily20100228t.jpg
81
+ - test/data/link.org
82
+ - test/data/list_before_1st_headline.html
83
+ - test/data/list_before_1st_headline.org
84
+ - test/data/lists.html
85
+ - test/data/lists.org
86
+ - test/data/no-headline.org
87
+ - test/data/one-headline.org
88
+ - test/data/paragraph.org
89
+ - test/data/quote.org
90
+ - test/data/sections.html
91
+ - test/data/sections.org
92
+ - test/data/simple-list.org
93
+ - test/data/skip_t.org
94
+ - test/data/structure.org
95
+ - test/data/table.org
96
+ - test/data/test-list.org
97
+ - test/data/text-bef-hl.org
98
+ - test/data/text.org
99
+ - test/data/title.html
100
+ - test/data/title.org
101
+ - test/data/verse.org
102
+ - test/helper.rb
103
+ - test/test_org-parse.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/knb/org-parse
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options:
110
+ - --charset=UTF-8
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ version:
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.3.5
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: parse and convert Org-Mode file
132
+ test_files:
133
+ - test/test_org-parse.rb
134
+ - test/helper.rb