org-ruby 0.7.1 → 0.7.2

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/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.7.2 / 2012-10-07
2
+
3
+ * Many fixes to the regular expressions used for emphasis, contributed by [[http://github.com/vonavi][vonavi]]
4
+ * Bug fix for when a table starts with a headline, thanks to [[http://github/til][til]]
5
+ * Asterisk can be used for definition lists too
6
+ * Use text lexer as default option for Pygments and Coderay when no language is specified
7
+
1
8
  == 0.7.1 / 2012-08-04
2
9
 
3
10
  * Make source code blocks from lisp dialects use Pygments scheme lexer
data/lib/org-ruby.rb CHANGED
@@ -21,7 +21,7 @@ require 'org-ruby/tilt'
21
21
  module OrgRuby
22
22
 
23
23
  # :stopdoc:
24
- VERSION = '0.7.1'
24
+ VERSION = '0.7.2'
25
25
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
26
26
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
27
27
  # :startdoc:
@@ -85,13 +85,6 @@ module Orgmode
85
85
  :"heading#{@level}"
86
86
  end
87
87
 
88
- # Converts this headline and its body to textile.
89
- def to_textile
90
- output = "h#{@level}. #{@headline_text}\n"
91
- output << Line.to_textile(@body_lines[1..-1])
92
- output
93
- end
94
-
95
88
  ######################################################################
96
89
  private
97
90
 
@@ -109,14 +109,14 @@ module Orgmode
109
109
 
110
110
  # Only try to colorize #+BEGIN_SRC blocks with a specified language,
111
111
  # but we still have to catch the cases when a lexer for the language was not available
112
- if not @block_lang.empty? and (defined? Pygments or defined? CodeRay)
112
+ if defined? Pygments or defined? CodeRay
113
113
  lang = normalize_lang(@block_lang)
114
114
 
115
115
  # NOTE: CodeRay and Pygments already escape the html once, so no need to escape_buffer!
116
116
  if defined? Pygments
117
117
  begin
118
118
  @buffer = Pygments.highlight(@buffer, :lexer => lang)
119
- rescue ::RubyPython::PythonError
119
+ rescue
120
120
  # Not supported lexer from Pygments, we fallback on using the text lexer
121
121
  @buffer = Pygments.highlight(@buffer, :lexer => 'text')
122
122
  end
@@ -347,6 +347,8 @@ module Orgmode
347
347
  case lang
348
348
  when 'emacs-lisp', 'common-lisp', 'lisp'
349
349
  'scheme'
350
+ when ''
351
+ 'text'
350
352
  else
351
353
  lang
352
354
  end
data/lib/org-ruby/line.rb CHANGED
@@ -78,7 +78,7 @@ module Orgmode
78
78
  ordered_list? or unordered_list? or definition_list?
79
79
  end
80
80
 
81
- UnorderedListRegexp = /^\s*(-|\+)\s+/
81
+ UnorderedListRegexp = /^\s*(-|\+|\s+[*])\s+/
82
82
 
83
83
  def unordered_list?
84
84
  check_assignment_or_regexp(:unordered_list, UnorderedListRegexp)
@@ -88,7 +88,7 @@ module Orgmode
88
88
  @line.sub(UnorderedListRegexp, "")
89
89
  end
90
90
 
91
- DefinitionListRegexp = /^\s*(-|\+)\s*(.*?)::/
91
+ DefinitionListRegexp = /^\s*(-|\+|\s+[*])\s*(.*?)::/
92
92
 
93
93
  def definition_list?
94
94
  check_assignment_or_regexp(:definition_list, DefinitionListRegexp)
@@ -223,12 +223,6 @@ module Orgmode
223
223
  return :paragraph
224
224
  end
225
225
 
226
- def self.to_textile(lines)
227
- output = ""
228
- output_buffer = TextileOutputBuffer.new(output)
229
- Parser.translate(lines, output_buffer)
230
- end
231
-
232
226
  ######################################################################
233
227
  private
234
228
 
@@ -99,15 +99,16 @@ module Orgmode
99
99
  mode = :normal
100
100
  previous_line = nil
101
101
  table_header_set = false
102
- @lines.each do |line|
102
+ @lines.each do |text|
103
+ line = Line.new text, self
104
+
103
105
  case mode
104
106
  when :normal
105
107
 
106
- if (Headline.headline? line) then
107
- @current_headline = Headline.new line, self, offset
108
+ if (Headline.headline? line.line) then
109
+ @current_headline = Headline.new line.line, self, offset
108
110
  @headlines << @current_headline
109
111
  else
110
- line = Line.new line, self
111
112
  # If there is a setting on this line, remember it.
112
113
  line.in_buffer_setting? do |key, value|
113
114
  store_in_buffer_setting key, value
@@ -131,7 +132,7 @@ module Orgmode
131
132
  end
132
133
 
133
134
  when :block_comment
134
- line = Line.new line, self
135
+
135
136
  if line.end_block? and line.block_type == "COMMENT"
136
137
  mode = :normal
137
138
  else
@@ -142,7 +143,6 @@ module Orgmode
142
143
 
143
144
  # As long as we stay in code mode, force lines to be either blank or paragraphs.
144
145
  # Don't try to interpret structural items, like headings and tables.
145
- line = Line.new line, self
146
146
  if line.end_block? and line.code_block?
147
147
  mode = :normal
148
148
  else
@@ -156,9 +156,8 @@ module Orgmode
156
156
 
157
157
  when :src_code
158
158
 
159
- line = Line.new line, self
160
159
  if line.end_block? and line.code_block?
161
- mode = :normal
160
+ mode = :normal
162
161
  else
163
162
  line.assigned_paragraph_type = :src
164
163
  end
@@ -170,7 +169,6 @@ module Orgmode
170
169
 
171
170
  when :property_drawer
172
171
 
173
- line = Line.new line, self
174
172
  if line.property_drawer_end_block?
175
173
  mode = :normal
176
174
  else
@@ -182,6 +180,7 @@ module Orgmode
182
180
  @header_lines << line
183
181
  end
184
182
  end # case
183
+
185
184
  previous_line = line
186
185
  end # @lines.each
187
186
  end # initialize
@@ -195,9 +194,11 @@ module Orgmode
195
194
  # Saves the loaded orgmode file as a textile file.
196
195
  def to_textile
197
196
  output = ""
198
- output << Line.to_textile(@header_lines)
197
+ output_buffer = TextileOutputBuffer.new(output)
198
+
199
+ Parser.translate(@header_lines, output_buffer)
199
200
  @headlines.each do |headline|
200
- output << headline.to_textile
201
+ Parser.translate(headline.body_lines, output_buffer)
201
202
  end
202
203
  output
203
204
  end
@@ -248,6 +249,7 @@ module Orgmode
248
249
  # Converts an array of lines to the appropriate format.
249
250
  # Writes the output to +output_buffer+.
250
251
  def self.translate(lines, output_buffer)
252
+ output_buffer.output_type = :start
251
253
  lines.each do |line|
252
254
 
253
255
  # See if we're carrying paragraph payload, and output
@@ -52,11 +52,11 @@ module Orgmode
52
52
 
53
53
  def initialize
54
54
  # Set up the emphasis regular expression.
55
- @pre_emphasis = " \t\\('\""
56
- @post_emphasis = "- \t.,:!?;'\"\\)"
55
+ @pre_emphasis = " \t\\('\"\\{"
56
+ @post_emphasis = "- \t\\.,:!\\?;'\"\\)\\}\\\\"
57
57
  @border_forbidden = " \t\r\n,\"'"
58
58
  @body_regexp = ".*?"
59
- @markers = "*/_=~+"
59
+ @markers = "\\*\\/_=~\\+"
60
60
  @logger = Logger.new(STDERR)
61
61
  @logger.level = Logger::WARN
62
62
  build_org_emphasis_regexp
@@ -97,7 +97,7 @@ module Orgmode
97
97
  def rewrite_emphasis(str)
98
98
  str.gsub(@org_emphasis_regexp) do |match|
99
99
  inner = yield $2, $3
100
- "#{$1}#{inner}#{$4}"
100
+ "#{$1}#{inner}"
101
101
  end
102
102
  end
103
103
 
@@ -161,11 +161,11 @@ module Orgmode
161
161
 
162
162
  def build_org_emphasis_regexp
163
163
  @org_emphasis_regexp = Regexp.new("([#{@pre_emphasis}]|^)\n" +
164
- "( [#{@markers}] )\n" +
165
- "( [^#{@border_forbidden}] | " +
166
- " [^#{@border_forbidden}]#{@body_regexp}[^#{@border_forbidden}] )\n" +
164
+ "( [#{@markers}] ) (?!\\2)\n" +
165
+ "( [^#{@border_forbidden}] | " +
166
+ "[^#{@border_forbidden}]#{@body_regexp}[^#{@border_forbidden}] )\n" +
167
167
  "\\2\n" +
168
- "([#{@post_emphasis}]|$)\n", Regexp::EXTENDED)
168
+ "(?=[#{@post_emphasis}]|$)\n", Regexp::EXTENDED)
169
169
  @logger.debug "Just created regexp: #{@org_emphasis_regexp}"
170
170
  end
171
171
 
@@ -92,7 +92,13 @@ module Orgmode
92
92
  (@output_type == :definition_list and not @support_definition_list) then
93
93
  @output << "*" * @list_indent_stack.length << " "
94
94
  end
95
- @output << inline_formatting(@buffer) << "\n"
95
+ if (@buffered_lines[0].kind_of?(Headline)) then
96
+ headline = @buffered_lines[0]
97
+ raise "Cannot be more than one headline!" if @buffered_lines.length > 1
98
+ @output << "h#{headline.level}. #{headline.headline_text}\n"
99
+ else
100
+ @output << inline_formatting(@buffer) << "\n"
101
+ end
96
102
  end
97
103
  clear_accumulation_buffer!
98
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: org-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-08 00:00:00.000000000Z
12
+ date: 2012-10-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubypants
16
- requirement: &70185642496880 !ruby/object:Gem::Requirement
16
+ requirement: &70185810847640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70185642496880
24
+ version_requirements: *70185810847640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bones
27
- requirement: &70185642496060 !ruby/object:Gem::Requirement
27
+ requirement: &70185810846040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 3.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70185642496060
35
+ version_requirements: *70185810846040
36
36
  description: ! 'This gem contains Ruby routines for parsing org-mode files.The most
37
37
 
38
38
  significant thing this library does today is convert org-mode files to