org-ruby 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/History.txt +45 -40
  2. data/{README.txt → README.rdoc} +66 -66
  3. data/Rakefile +28 -27
  4. data/bin/org-ruby +40 -40
  5. data/lib/org-ruby.rb +50 -50
  6. data/lib/org-ruby/headline.rb +80 -80
  7. data/lib/org-ruby/html_output_buffer.rb +117 -105
  8. data/lib/org-ruby/line.rb +178 -173
  9. data/lib/org-ruby/output_buffer.rb +172 -172
  10. data/lib/org-ruby/parser.rb +80 -80
  11. data/lib/org-ruby/regexp_helper.rb +156 -156
  12. data/lib/org-ruby/textile_output_buffer.rb +67 -67
  13. data/spec/data/freeform.org +111 -111
  14. data/spec/data/hyp-planning.org +335 -335
  15. data/spec/data/remember.org +53 -53
  16. data/spec/headline_spec.rb +55 -55
  17. data/spec/html_examples/advanced-lists.html +31 -31
  18. data/spec/html_examples/advanced-lists.org +31 -31
  19. data/spec/html_examples/block_code.html +30 -30
  20. data/spec/html_examples/block_code.org +35 -35
  21. data/spec/html_examples/blockquote.html +7 -7
  22. data/spec/html_examples/blockquote.org +13 -13
  23. data/spec/html_examples/code-comment.html +19 -0
  24. data/spec/html_examples/code-comment.org +22 -0
  25. data/spec/html_examples/escape-pre.html +7 -7
  26. data/spec/html_examples/escape-pre.org +6 -6
  27. data/spec/html_examples/html-literal.html +2 -0
  28. data/spec/html_examples/html-literal.org +6 -0
  29. data/spec/html_examples/inline-formatting.html +10 -10
  30. data/spec/html_examples/inline-formatting.org +17 -17
  31. data/spec/html_examples/lists.html +19 -19
  32. data/spec/html_examples/lists.org +36 -36
  33. data/spec/html_examples/metadata-comment.org-fail +30 -0
  34. data/spec/html_examples/only-list.html +5 -5
  35. data/spec/html_examples/only-list.org +3 -3
  36. data/spec/html_examples/only-table.html +6 -6
  37. data/spec/html_examples/only-table.org +5 -5
  38. data/spec/html_examples/tables.html +20 -20
  39. data/spec/html_examples/tables.org +26 -26
  40. data/spec/html_examples/text.html +2 -2
  41. data/spec/html_examples/text.org +16 -16
  42. data/spec/line_spec.rb +89 -89
  43. data/spec/parser_spec.rb +86 -86
  44. data/spec/regexp_helper_spec.rb +57 -57
  45. data/spec/spec_helper.rb +20 -20
  46. data/spec/textile_examples/block_code.org +35 -35
  47. data/spec/textile_examples/block_code.textile +29 -29
  48. data/spec/textile_examples/blockquote.org +13 -13
  49. data/spec/textile_examples/blockquote.textile +11 -11
  50. data/spec/textile_examples/keywords.org +13 -13
  51. data/spec/textile_examples/keywords.textile +11 -11
  52. data/spec/textile_examples/links.org +11 -11
  53. data/spec/textile_examples/links.textile +10 -10
  54. data/spec/textile_examples/lists.org +36 -36
  55. data/spec/textile_examples/lists.textile +20 -20
  56. data/spec/textile_examples/single-space-plain-list.org +13 -13
  57. data/spec/textile_examples/single-space-plain-list.textile +10 -10
  58. data/spec/textile_examples/tables.org +26 -26
  59. data/spec/textile_examples/tables.textile +23 -23
  60. data/spec/textile_output_buffer_spec.rb +21 -21
  61. data/tasks/test_case.rake +49 -49
  62. metadata +10 -6
  63. data/.bnsignore +0 -18
@@ -1,172 +1,172 @@
1
- require 'logger'
2
-
3
- module Orgmode
4
-
5
- # The OutputBuffer is used to accumulate multiple lines of orgmode
6
- # text, and then emit them to the output all in one go. The class
7
- # will do the final textile substitution for inline formatting and
8
- # add a newline character prior emitting the output.
9
- class OutputBuffer
10
-
11
- # This is the temporary buffer that we accumulate into.
12
- attr_reader :buffer
13
-
14
- # This is the overall output buffer
15
- attr_reader :output
16
-
17
- # This is the current type of output being accumulated.
18
- attr_accessor :output_type
19
-
20
- # Creates a new OutputBuffer object that is bound to an output object.
21
- # The output will get flushed to =output=.
22
- def initialize(output)
23
- @output = output
24
- @buffer = ""
25
- @output_type = :start
26
- @list_indent_stack = []
27
- @paragraph_modifier = nil
28
- @cancel_modifier = false
29
- @mode_stack = []
30
- push_mode(:normal)
31
-
32
- @logger = Logger.new(STDERR)
33
- @logger.level = Logger::WARN
34
-
35
- @re_help = RegexpHelper.new
36
- end
37
-
38
- Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :code, :table]
39
-
40
- def current_mode
41
- @mode_stack.last
42
- end
43
-
44
- def current_mode_list?
45
- (current_mode == :ordered_list) or (current_mode == :unordered_list)
46
- end
47
-
48
- def push_mode(mode)
49
- raise "Not a recognized mode: #{mode}" unless Modes.include?(mode)
50
- @mode_stack.push(mode)
51
- end
52
-
53
- def pop_mode(mode = nil)
54
- m = @mode_stack.pop
55
- @logger.warn "Modes don't match. Expected to pop #{mode}, but popped #{m}" if mode && mode != m
56
- m
57
- end
58
-
59
- # Prepares the output buffer to receive content from a line.
60
- # As a side effect, this may flush the current accumulated text.
61
- def prepare(line)
62
- @logger.debug "Looking at #{line.paragraph_type}: #{line.to_s}"
63
- if not should_accumulate_output?(line) then
64
- flush!
65
- maintain_list_indent_stack(line)
66
- @output_type = line.paragraph_type
67
- end
68
- push_mode(:table) if enter_table?
69
- pop_mode(:table) if exit_table?
70
- end
71
-
72
- # Tests if we are entering a table mode.
73
- def enter_table?
74
- ((@output_type == :table_row) || (@output_type == :table_separator)) &&
75
- (current_mode != :table)
76
- end
77
-
78
- # Tests if we are existing a table mode.
79
- def exit_table?
80
- ((@output_type != :table_row) && (@output_type != :table_separator)) &&
81
- (current_mode == :table)
82
- end
83
-
84
- # Accumulate the string @str@.
85
- def << (str)
86
- @buffer << str
87
- end
88
-
89
- # Gets the current list indent level.
90
- def list_indent_level
91
- @list_indent_stack.length
92
- end
93
-
94
- # Test if we're in an output mode in which whitespace is significant.
95
- def preserve_whitespace?
96
- return current_mode == :code
97
- end
98
-
99
- ######################################################################
100
- private
101
-
102
- # call-seq:
103
- # continue_current_list? => boolean
104
- #
105
- # Tests if the line should continue the current list.
106
- def continue_current_list?(line)
107
- end
108
-
109
- def maintain_list_indent_stack(line)
110
- if (line.plain_list?) then
111
- while (not @list_indent_stack.empty? \
112
- and (@list_indent_stack.last > line.indent))
113
- @list_indent_stack.pop
114
- pop_mode
115
- end
116
- if (@list_indent_stack.empty? \
117
- or @list_indent_stack.last < line.indent)
118
- @list_indent_stack.push(line.indent)
119
- push_mode line.paragraph_type
120
- end
121
- elsif line.blank? then
122
-
123
- # Nothing
124
-
125
- elsif ((line.paragraph_type == :paragraph) and
126
- (not @list_indent_stack.empty? and
127
- line.indent > @list_indent_stack.last))
128
-
129
- # Nothing -- output this paragraph inside
130
- # the list block (ul/ol)
131
-
132
- else
133
- @list_indent_stack = []
134
- while ((current_mode == :ordered_list) or
135
- (current_mode == :unordered_list))
136
- pop_mode
137
- end
138
- end
139
- end
140
-
141
- # Tests if the current line should be accumulated in the current
142
- # output buffer. (Extraneous line breaks in the orgmode buffer
143
- # are removed by accumulating lines in the output buffer without
144
- # line breaks.)
145
- def should_accumulate_output?(line)
146
-
147
- # Special case: Preserve line breaks in block code mode.
148
- return false if preserve_whitespace?
149
-
150
- # Special case: Multiple blank lines get accumulated.
151
- return true if line.paragraph_type == :blank and @output_type == :blank
152
-
153
- # Currently only "paragraphs" get accumulated with previous output.
154
- return false unless line.paragraph_type == :paragraph
155
- if ((@output_type == :ordered_list) or
156
- (@output_type == :unordered_list)) then
157
-
158
- # If the previous output type was a list item, then we only put a paragraph in it
159
- # if its indent level is greater than the list indent level.
160
-
161
- return false unless line.indent > @list_indent_stack.last
162
- end
163
-
164
- # Only accumulate paragraphs with lists & paragraphs.
165
- return false unless
166
- ((@output_type == :paragraph) or
167
- (@output_type == :ordered_list) or
168
- (@output_type == :unordered_list))
169
- true
170
- end
171
- end # class OutputBuffer
172
- end # module Orgmode
1
+ require 'logger'
2
+
3
+ module Orgmode
4
+
5
+ # The OutputBuffer is used to accumulate multiple lines of orgmode
6
+ # text, and then emit them to the output all in one go. The class
7
+ # will do the final textile substitution for inline formatting and
8
+ # add a newline character prior emitting the output.
9
+ class OutputBuffer
10
+
11
+ # This is the temporary buffer that we accumulate into.
12
+ attr_reader :buffer
13
+
14
+ # This is the overall output buffer
15
+ attr_reader :output
16
+
17
+ # This is the current type of output being accumulated.
18
+ attr_accessor :output_type
19
+
20
+ # Creates a new OutputBuffer object that is bound to an output object.
21
+ # The output will get flushed to =output=.
22
+ def initialize(output)
23
+ @output = output
24
+ @buffer = ""
25
+ @output_type = :start
26
+ @list_indent_stack = []
27
+ @paragraph_modifier = nil
28
+ @cancel_modifier = false
29
+ @mode_stack = []
30
+ push_mode(:normal)
31
+
32
+ @logger = Logger.new(STDERR)
33
+ @logger.level = Logger::WARN
34
+
35
+ @re_help = RegexpHelper.new
36
+ end
37
+
38
+ Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :code, :table]
39
+
40
+ def current_mode
41
+ @mode_stack.last
42
+ end
43
+
44
+ def current_mode_list?
45
+ (current_mode == :ordered_list) or (current_mode == :unordered_list)
46
+ end
47
+
48
+ def push_mode(mode)
49
+ raise "Not a recognized mode: #{mode}" unless Modes.include?(mode)
50
+ @mode_stack.push(mode)
51
+ end
52
+
53
+ def pop_mode(mode = nil)
54
+ m = @mode_stack.pop
55
+ @logger.warn "Modes don't match. Expected to pop #{mode}, but popped #{m}" if mode && mode != m
56
+ m
57
+ end
58
+
59
+ # Prepares the output buffer to receive content from a line.
60
+ # As a side effect, this may flush the current accumulated text.
61
+ def prepare(line)
62
+ @logger.debug "Looking at #{line.paragraph_type}: #{line.to_s}"
63
+ if not should_accumulate_output?(line) then
64
+ flush!
65
+ maintain_list_indent_stack(line)
66
+ @output_type = line.paragraph_type
67
+ end
68
+ push_mode(:table) if enter_table?
69
+ pop_mode(:table) if exit_table?
70
+ end
71
+
72
+ # Tests if we are entering a table mode.
73
+ def enter_table?
74
+ ((@output_type == :table_row) || (@output_type == :table_separator)) &&
75
+ (current_mode != :table)
76
+ end
77
+
78
+ # Tests if we are existing a table mode.
79
+ def exit_table?
80
+ ((@output_type != :table_row) && (@output_type != :table_separator)) &&
81
+ (current_mode == :table)
82
+ end
83
+
84
+ # Accumulate the string @str@.
85
+ def << (str)
86
+ @buffer << str
87
+ end
88
+
89
+ # Gets the current list indent level.
90
+ def list_indent_level
91
+ @list_indent_stack.length
92
+ end
93
+
94
+ # Test if we're in an output mode in which whitespace is significant.
95
+ def preserve_whitespace?
96
+ return current_mode == :code
97
+ end
98
+
99
+ ######################################################################
100
+ private
101
+
102
+ # call-seq:
103
+ # continue_current_list? => boolean
104
+ #
105
+ # Tests if the line should continue the current list.
106
+ def continue_current_list?(line)
107
+ end
108
+
109
+ def maintain_list_indent_stack(line)
110
+ if (line.plain_list?) then
111
+ while (not @list_indent_stack.empty? \
112
+ and (@list_indent_stack.last > line.indent))
113
+ @list_indent_stack.pop
114
+ pop_mode
115
+ end
116
+ if (@list_indent_stack.empty? \
117
+ or @list_indent_stack.last < line.indent)
118
+ @list_indent_stack.push(line.indent)
119
+ push_mode line.paragraph_type
120
+ end
121
+ elsif line.blank? then
122
+
123
+ # Nothing
124
+
125
+ elsif ((line.paragraph_type == :paragraph) and
126
+ (not @list_indent_stack.empty? and
127
+ line.indent > @list_indent_stack.last))
128
+
129
+ # Nothing -- output this paragraph inside
130
+ # the list block (ul/ol)
131
+
132
+ else
133
+ @list_indent_stack = []
134
+ while ((current_mode == :ordered_list) or
135
+ (current_mode == :unordered_list))
136
+ pop_mode
137
+ end
138
+ end
139
+ end
140
+
141
+ # Tests if the current line should be accumulated in the current
142
+ # output buffer. (Extraneous line breaks in the orgmode buffer
143
+ # are removed by accumulating lines in the output buffer without
144
+ # line breaks.)
145
+ def should_accumulate_output?(line)
146
+
147
+ # Special case: Preserve line breaks in block code mode.
148
+ return false if preserve_whitespace?
149
+
150
+ # Special case: Multiple blank lines get accumulated.
151
+ return true if line.paragraph_type == :blank and @output_type == :blank
152
+
153
+ # Currently only "paragraphs" get accumulated with previous output.
154
+ return false unless line.paragraph_type == :paragraph
155
+ if ((@output_type == :ordered_list) or
156
+ (@output_type == :unordered_list)) then
157
+
158
+ # If the previous output type was a list item, then we only put a paragraph in it
159
+ # if its indent level is greater than the list indent level.
160
+
161
+ return false unless line.indent > @list_indent_stack.last
162
+ end
163
+
164
+ # Only accumulate paragraphs with lists & paragraphs.
165
+ return false unless
166
+ ((@output_type == :paragraph) or
167
+ (@output_type == :ordered_list) or
168
+ (@output_type == :unordered_list))
169
+ true
170
+ end
171
+ end # class OutputBuffer
172
+ end # module Orgmode
@@ -1,80 +1,80 @@
1
- require 'rubygems'
2
- require 'rubypants'
3
-
4
- module Orgmode
5
-
6
- ##
7
- ## Simple routines for loading / saving an ORG file.
8
- ##
9
-
10
- class Parser
11
-
12
- # All of the lines of the orgmode file
13
- attr_reader :lines
14
-
15
- # All of the headlines in the org file
16
- attr_reader :headlines
17
-
18
- # These are any lines before the first headline
19
- attr_reader :header_lines
20
-
21
- # I can construct a parser object either with an array of lines
22
- # or with a single string that I will split along \n boundaries.
23
- def initialize(lines)
24
- if lines.is_a? Array then
25
- @lines = lines
26
- elsif lines.is_a? String then
27
- @lines = lines.split("\n")
28
- else
29
- raise "Unsupported type for +lines+: #{lines.class}"
30
- end
31
-
32
- @headlines = Array.new
33
- @current_headline = nil
34
- @header_lines = []
35
- @lines.each do |line|
36
- if (Headline.headline? line) then
37
- @current_headline = Headline.new line
38
- @headlines << @current_headline
39
- else
40
- line = Line.new line
41
- if (@current_headline) then
42
- @current_headline.body_lines << line
43
- else
44
- @header_lines << line
45
- end
46
- end
47
- end
48
- end # initialize
49
-
50
- # Creates a new parser from the data in a given file
51
- def self.load(fname)
52
- lines = IO.readlines(fname)
53
- return self.new(lines)
54
- end
55
-
56
- # Saves the loaded orgmode file as a textile file.
57
- def to_textile
58
- output = ""
59
- output << Line.to_textile(@header_lines)
60
- @headlines.each do |headline|
61
- output << headline.to_textile
62
- end
63
- output
64
- end
65
-
66
- # Converts the loaded org-mode file to HTML.
67
- def to_html
68
- output = ""
69
- decorate = true
70
- output << Line.to_html(@header_lines, :decorate_title => decorate)
71
- decorate = (output.length == 0)
72
- @headlines.each do |headline|
73
- output << headline.to_html(:decorate_title => decorate)
74
- decorate = (output.length == 0)
75
- end
76
- rp = RubyPants.new(output)
77
- rp.to_html
78
- end
79
- end # class Parser
80
- end # module Orgmode
1
+ require 'rubygems'
2
+ require 'rubypants'
3
+
4
+ module Orgmode
5
+
6
+ ##
7
+ ## Simple routines for loading / saving an ORG file.
8
+ ##
9
+
10
+ class Parser
11
+
12
+ # All of the lines of the orgmode file
13
+ attr_reader :lines
14
+
15
+ # All of the headlines in the org file
16
+ attr_reader :headlines
17
+
18
+ # These are any lines before the first headline
19
+ attr_reader :header_lines
20
+
21
+ # I can construct a parser object either with an array of lines
22
+ # or with a single string that I will split along \n boundaries.
23
+ def initialize(lines)
24
+ if lines.is_a? Array then
25
+ @lines = lines
26
+ elsif lines.is_a? String then
27
+ @lines = lines.split("\n")
28
+ else
29
+ raise "Unsupported type for +lines+: #{lines.class}"
30
+ end
31
+
32
+ @headlines = Array.new
33
+ @current_headline = nil
34
+ @header_lines = []
35
+ @lines.each do |line|
36
+ if (Headline.headline? line) then
37
+ @current_headline = Headline.new line
38
+ @headlines << @current_headline
39
+ else
40
+ line = Line.new line
41
+ if (@current_headline) then
42
+ @current_headline.body_lines << line
43
+ else
44
+ @header_lines << line
45
+ end
46
+ end
47
+ end
48
+ end # initialize
49
+
50
+ # Creates a new parser from the data in a given file
51
+ def self.load(fname)
52
+ lines = IO.readlines(fname)
53
+ return self.new(lines)
54
+ end
55
+
56
+ # Saves the loaded orgmode file as a textile file.
57
+ def to_textile
58
+ output = ""
59
+ output << Line.to_textile(@header_lines)
60
+ @headlines.each do |headline|
61
+ output << headline.to_textile
62
+ end
63
+ output
64
+ end
65
+
66
+ # Converts the loaded org-mode file to HTML.
67
+ def to_html
68
+ output = ""
69
+ decorate = true
70
+ output << Line.to_html(@header_lines, :decorate_title => decorate)
71
+ decorate = (output.length == 0)
72
+ @headlines.each do |headline|
73
+ output << headline.to_html(:decorate_title => decorate)
74
+ decorate = (output.length == 0)
75
+ end
76
+ rp = RubyPants.new(output)
77
+ rp.to_html
78
+ end
79
+ end # class Parser
80
+ end # module Orgmode