org-ruby 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.9.0 / 2014-02-08
2
+
3
+ * Add explicit enable or disable of include file feature
4
+ * Add lang attribute to src code block to support syntax highlight in Github
5
+
1
6
  == 0.8.3 / 2014-02-02
2
7
 
3
8
  * Bugfix: Two backslashes \\ at the end of the line make a line break without breaking paragraph.
data/README.rdoc CHANGED
@@ -25,6 +25,10 @@ From Ruby code:
25
25
  Orgmode::Parser.new("* Hello world!).to_textile
26
26
  # => "h1. Hello world!\n"
27
27
 
28
+ # Renders Markdown
29
+ Orgmode::Parser.new("* Hello world!).to_markdown
30
+ # => "# Hello world!\n"
31
+
28
32
  It can also be used from the command line:
29
33
 
30
34
  org-ruby sample.org --translate html
@@ -35,6 +39,10 @@ It can also be used from the command line:
35
39
 
36
40
  ...will output a textile version of sample.org.
37
41
 
42
+ org-ruby --translate markdown sample.org
43
+
44
+ ...will output a markdown version of sample.org.
45
+
38
46
  == Features
39
47
 
40
48
  * Converts org-mode files to HTML or Textile
data/lib/org-ruby.rb CHANGED
@@ -24,7 +24,7 @@ require 'org-ruby/tilt'
24
24
  module OrgRuby
25
25
 
26
26
  # :stopdoc:
27
- VERSION = '0.8.3'
27
+ VERSION = '0.9.0'
28
28
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
29
29
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
30
30
  # :startdoc:
@@ -67,7 +67,7 @@ module Orgmode
67
67
  when (mode == :src and @block_lang.empty?)
68
68
  " class=\"src\""
69
69
  when (mode == :src and not @block_lang.empty?)
70
- " class=\"src src-#{@block_lang}\""
70
+ " class=\"src\" lang=\"#{@block_lang}\""
71
71
  when (mode == :example || mode == :inline_example)
72
72
  " class=\"example\""
73
73
  when mode == :center
@@ -81,7 +81,7 @@ module Orgmode
81
81
 
82
82
  # I can construct a parser object either with an array of lines
83
83
  # or with a single string that I will split along \n boundaries.
84
- def initialize(lines, offset=0)
84
+ def initialize(lines, parser_options={ })
85
85
  if lines.is_a? Array then
86
86
  @lines = lines
87
87
  elsif lines.is_a? String then
@@ -97,8 +97,34 @@ module Orgmode
97
97
  @in_buffer_settings = { }
98
98
  @options = { }
99
99
  @link_abbrevs = { }
100
+ @parser_options = parser_options
101
+
102
+ #
103
+ # Include file feature disabled by default since
104
+ # it would be dangerous in some environments
105
+ #
106
+ # http://orgmode.org/manual/Include-files.html
107
+ #
108
+ # It will be activated by one of the following:
109
+ #
110
+ # - setting an ORG_RUBY_ENABLE_INCLUDE_FILES env variable to 'true'
111
+ # - setting an ORG_RUBY_INCLUDE_ROOT env variable with the root path
112
+ # - explicitly enabling it by passing it as an option:
113
+ # e.g. Orgmode::Parser.new(org_text, { :allow_include_files => true })
114
+ #
115
+ # IMPORTANT: To avoid the feature altogether, it can be _explicitly disabled_ as follows:
116
+ # e.g. Orgmode::Parser.new(org_text, { :allow_include_files => false })
117
+ #
118
+ if @parser_options[:allow_include_files].nil?
119
+ if ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] == 'true' \
120
+ or not ENV['ORG_RUBY_INCLUDE_ROOT'].nil?
121
+ @parser_options[:allow_include_files] = true
122
+ end
123
+ end
100
124
 
101
- parse_lines @lines, offset
125
+ @parser_options[:offset] ||= 0
126
+
127
+ parse_lines @lines
102
128
  end
103
129
 
104
130
  # Check include file availability and permissions
@@ -119,24 +145,19 @@ module Orgmode
119
145
  can_be_included
120
146
  end
121
147
 
122
- # Parse lines
123
- def parse_lines(lines, offset)
148
+ def parse_lines(lines)
124
149
  mode = :normal
125
150
  previous_line = nil
126
151
  table_header_set = false
127
152
  lines.each do |text|
128
153
  line = Line.new text, self
129
154
 
130
- # Disable file include feature by default since it would be dangerous in some environments
131
- # It can be activated either by setting a ORG_RUBY_ENABLE_INCLUDE_FILES environment variable
132
- # or by setting a root path for included file via the ORG_RUBY_INCLUDE_ROOT environment variable
133
- if ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] == 'true' \
134
- or not ENV['ORG_RUBY_INCLUDE_ROOT'].nil?
155
+ if @parser_options[:allow_include_files]
135
156
  if line.include_file? and not line.include_file_path.nil?
136
157
  next if not check_include_file line.include_file_path
137
158
  include_data = get_include_data line
138
- include_lines = Orgmode::Parser.new(include_data).lines
139
- parse_lines include_lines, offset
159
+ include_lines = Orgmode::Parser.new(include_data, @parser_options).lines
160
+ parse_lines include_lines
140
161
  end
141
162
  end
142
163
 
@@ -152,7 +173,7 @@ module Orgmode
152
173
  case mode
153
174
  when :normal, :quote, :center
154
175
  if Headline.headline? line.to_s
155
- line = Headline.new line.to_s, self, offset
176
+ line = Headline.new line.to_s, self, @parser_options[:offset]
156
177
  elsif line.table_separator?
157
178
  if previous_line and previous_line.paragraph_type == :table_row and !table_header_set
158
179
  previous_line.assigned_paragraph_type = :table_header
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.8.3
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-02 00:00:00.000000000 Z
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubypants
@@ -84,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project: org-ruby
87
- rubygems_version: 1.8.21
87
+ rubygems_version: 1.8.24
88
88
  signing_key:
89
89
  specification_version: 3
90
90
  summary: This gem contains Ruby routines for parsing org-mode files.
91
91
  test_files: []
92
- has_rdoc: