org-ruby 0.8.2 → 0.8.3

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,9 @@
1
+ == 0.8.3 / 2014-02-02
2
+
3
+ * Bugfix: Two backslashes \\ at the end of the line make a line break without breaking paragraph.
4
+ * Bugfix: Fix inline formatting not working for definition lists
5
+ * Add basic markdown exporter
6
+
1
7
  == 0.8.2 / 2013-11-09
2
8
 
3
9
  * Manage the #+INCLUDE tag in org files (contribution by pierre-lecocq)
data/bin/org-ruby CHANGED
@@ -17,7 +17,7 @@ options_parser = OptionParser.new do |opts|
17
17
  options[:debug] = true
18
18
  end
19
19
 
20
- opts.on("-t", "--translate FORMAT", [:html, :textile],
20
+ opts.on("-t", "--translate FORMAT", [:html, :textile, :markdown],
21
21
  "Translate the ORG file to the specified format.") do |v|
22
22
  options[:format] = v
23
23
  end
@@ -43,9 +43,8 @@ begin
43
43
  $DEBUG = true if options[:debug]
44
44
  puts p.to_html if options[:format] == :html
45
45
  puts p.to_textile if options[:format] == :textile
46
+ puts p.to_markdown if options[:format] == :markdown
46
47
  end
47
48
  rescue OptionParser::ParseError
48
49
  puts options_parser
49
50
  end
50
-
51
-
data/lib/org-ruby.rb CHANGED
@@ -15,13 +15,16 @@ require 'org-ruby/html_symbol_replace'
15
15
  require 'org-ruby/textile_output_buffer'
16
16
  require 'org-ruby/textile_symbol_replace'
17
17
 
18
+ # Markdown exporter
19
+ require 'org-ruby/markdown_output_buffer'
20
+
18
21
  # Tilt support
19
22
  require 'org-ruby/tilt'
20
23
 
21
24
  module OrgRuby
22
25
 
23
26
  # :stopdoc:
24
- VERSION = '0.8.2'
27
+ VERSION = '0.8.3'
25
28
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
26
29
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
27
30
  # :startdoc:
@@ -172,6 +172,8 @@ module Orgmode
172
172
  push_mode(:definition_descr, indent)
173
173
  @output << inline_formatting(d[2].strip + d[3])
174
174
  @new_paragraph = nil
175
+ # FIXME: Need to restore tags once again (this should be done in escape_buffer!)
176
+ @output.gsub!(/@(<[^<>\n]*>)/, "\\1")
175
177
 
176
178
  when :horizontal_rule
177
179
  add_paragraph unless @new_paragraph == :start
@@ -328,6 +330,10 @@ module Orgmode
328
330
  "@<sup>@<a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">#{name}@</a>@</sup>"
329
331
  end
330
332
  end
333
+ # Two backslashes \\ at the end of the line make a line break without breaking paragraph.
334
+ if @output_type != :table_row and @output_type != :table_header then
335
+ str.sub!(/\\\\$/, "@<br />")
336
+ end
331
337
  escape_buffer!
332
338
  Orgmode.special_symbols_to_html str
333
339
  str = @re_help.restore_code_snippets str
@@ -0,0 +1,109 @@
1
+ require 'stringio'
2
+
3
+ module Orgmode
4
+
5
+ class MarkdownOutputBuffer < OutputBuffer
6
+
7
+ def initialize(output)
8
+ super(output)
9
+ end
10
+
11
+ def push_mode(mode, indent)
12
+ super(mode, indent)
13
+ end
14
+
15
+ def pop_mode(mode = nil)
16
+ m = super(mode)
17
+ @list_indent_stack.pop
18
+ m
19
+ end
20
+
21
+ # Maps org markup to markdown markup.
22
+ MarkdownMap = {
23
+ "*" => "**",
24
+ "/" => "*",
25
+ "_" => "*",
26
+ "=" => "`",
27
+ "~" => "`",
28
+ "+" => "~~"
29
+ }
30
+
31
+ # Handles inline formatting for markdown.
32
+ def inline_formatting(input)
33
+ @re_help.rewrite_emphasis input do |marker, body|
34
+ m = MarkdownMap[marker]
35
+ "#{m}#{body}#{m}"
36
+ end
37
+ @re_help.rewrite_subp input do |type, text|
38
+ if type == "_" then
39
+ "<sub>#{text}</sub>"
40
+ elsif type == "^" then
41
+ "<sup>#{text}</sup>"
42
+ end
43
+ end
44
+ @re_help.rewrite_links input do |link, defi|
45
+ # We don't add a description for images in links, because its
46
+ # empty value forces the image to be inlined.
47
+ defi ||= link unless link =~ @re_help.org_image_file_regexp
48
+ link = link.gsub(/ /, "%%20")
49
+
50
+ if defi =~ @re_help.org_image_file_regexp
51
+ "![#{defi}](#{defi})"
52
+ elsif defi
53
+ "[#{defi}](#{link})"
54
+ else
55
+ "[#{link}](#{link})"
56
+ end
57
+ end
58
+
59
+ # Just reuse Textile special symbols for now?
60
+ Orgmode.special_symbols_to_textile(input)
61
+ input = @re_help.restore_code_snippets input
62
+ input
63
+ end
64
+
65
+ # TODO: Implement this
66
+ def output_footnotes!
67
+ return false
68
+ end
69
+
70
+ # Flushes the current buffer
71
+ def flush!
72
+ return false if @buffer.empty? and @output_type != :blank
73
+ @logger.debug "FLUSH ==========> #{@output_type}"
74
+ @buffer.gsub!(/\A\n*/, "")
75
+
76
+ case
77
+ when mode_is_code?(current_mode)
78
+ @output << "```#{@block_lang}\n"
79
+ @output << @buffer << "\n"
80
+ @output << "```\n"
81
+ when preserve_whitespace?
82
+ @output << @buffer << "\n"
83
+
84
+ when @output_type == :blank
85
+ @output << "\n"
86
+
87
+ else
88
+ case current_mode
89
+ when :paragraph
90
+ @output << "> " if @mode_stack[0] == :quote
91
+
92
+ when :list_item
93
+ @output << " " * @mode_stack.count(:list_item) << "* "
94
+
95
+ when :horizontal_rule
96
+ @output << "---"
97
+
98
+ end
99
+ @output << inline_formatting(@buffer) << "\n"
100
+ end
101
+ @buffer = ""
102
+ end
103
+
104
+ def add_line_attributes headline
105
+ @output << "#" * headline.level
106
+ @output << " "
107
+ end
108
+ end # class MarkdownOutputBuffer
109
+ end # module Orgmode
@@ -255,6 +255,27 @@ module Orgmode
255
255
  output
256
256
  end
257
257
 
258
+ # Exports the Org mode content into Markdown format
259
+ def to_markdown
260
+ mark_trees_for_export
261
+ output = ""
262
+ output_buffer = MarkdownOutputBuffer.new(output)
263
+
264
+ translate(@header_lines, output_buffer)
265
+ @headlines.each do |headline|
266
+ next if headline.export_state == :exclude
267
+ case headline.export_state
268
+ when :exclude
269
+ # NOTHING
270
+ when :headline_only
271
+ translate(headline.body_lines[0, 1], output_buffer)
272
+ when :all
273
+ translate(headline.body_lines, output_buffer)
274
+ end
275
+ end
276
+ output
277
+ end
278
+
258
279
  # Converts the loaded org-mode file to HTML.
259
280
  def to_html
260
281
  mark_trees_for_export
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.2
4
+ version: 0.8.3
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: 2013-11-23 00:00:00.000000000Z
12
+ date: 2014-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubypants
16
- requirement: &70289581896800 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 0.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70289581896800
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.0
25
30
  description: ! 'An org-mode parser written in Ruby. This gem contains Ruby routines
26
31
  for parsing org-mode files.The most
27
32
 
@@ -52,10 +57,11 @@ files:
52
57
  - lib/org-ruby/output_buffer.rb
53
58
  - lib/org-ruby/parser.rb
54
59
  - lib/org-ruby/regexp_helper.rb
60
+ - lib/org-ruby/markdown_output_buffer.rb
55
61
  - lib/org-ruby/textile_output_buffer.rb
56
62
  - lib/org-ruby/textile_symbol_replace.rb
57
63
  - lib/org-ruby/tilt.rb
58
- homepage: http://github.com/bdewey/org-ruby
64
+ homepage: https://github.com/bdewey/org-ruby
59
65
  licenses:
60
66
  - MIT
61
67
  post_install_message:
@@ -78,8 +84,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
84
  version: '0'
79
85
  requirements: []
80
86
  rubyforge_project: org-ruby
81
- rubygems_version: 1.8.10
87
+ rubygems_version: 1.8.21
82
88
  signing_key:
83
89
  specification_version: 3
84
90
  summary: This gem contains Ruby routines for parsing org-mode files.
85
91
  test_files: []
92
+ has_rdoc: