org-ruby 0.9.1 → 0.9.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 +11 -1
- data/README.rdoc +31 -24
- data/lib/org-ruby.rb +1 -1
- data/lib/org-ruby/html_output_buffer.rb +65 -62
- data/lib/org-ruby/line.rb +72 -6
- data/lib/org-ruby/output_buffer.rb +7 -2
- data/lib/org-ruby/parser.rb +34 -9
- data/lib/org-ruby/version.rb +3 -0
- metadata +11 -25
    
        data/History.txt
    CHANGED
    
    | @@ -1,4 +1,14 @@ | |
| 1 | 
            -
            == 0.9. | 
| 1 | 
            +
            == 0.9.2 / 2014-03-22
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Fix Org mode syntax for escaping html: Syntax actually now is @@html:<text>@@ 
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            * Fix '#+TITLE:' to render as a h1 headline
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Remove rewriting links to '.org' files as '.html'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            * Implement :exports options for code blocks
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            == 0.9.1 / 2014-02-13
         | 
| 2 12 |  | 
| 3 13 | 
             
            * Backport CGI::escapeHTML function from Ruby to have same output among different Ruby versions
         | 
| 4 14 |  | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -1,11 +1,9 @@ | |
| 1 | 
            -
            =  | 
| 2 | 
            -
            <em>Originally by Brian Dewey</em> (http://github.com/bdewey/org-ruby)
         | 
| 3 | 
            -
             | 
| 1 | 
            +
            = OrgRuby
         | 
| 4 2 | 
             
            {<img src="https://secure.travis-ci.org/wallyqs/org-ruby.png?branch=master" alt="Build Status" />}[http://travis-ci.org/wallyqs/org-ruby]
         | 
| 5 3 |  | 
| 6 | 
            -
            An { | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 4 | 
            +
            An {Org mode}[http://orgmode.org] parser written in Ruby.
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            <em>Originally by Brian Dewey</em>
         | 
| 9 7 |  | 
| 10 8 | 
             
            == Installation
         | 
| 11 9 |  | 
| @@ -13,47 +11,56 @@ Currently, you cannot do much to customize the conversion. The supplied textile | |
| 13 11 |  | 
| 14 12 | 
             
            == Usage
         | 
| 15 13 |  | 
| 16 | 
            -
            From Ruby | 
| 14 | 
            +
            From Ruby:
         | 
| 17 15 |  | 
| 18 16 | 
             
                 require 'org-ruby'
         | 
| 19 17 |  | 
| 20 18 | 
             
                 # Renders HTML
         | 
| 21 | 
            -
                 Orgmode::Parser.new("* Hello world!).to_html
         | 
| 19 | 
            +
                 Orgmode::Parser.new("* Hello world!").to_html
         | 
| 22 20 | 
             
                 # => "<h1>Hello world!</h1>\n"
         | 
| 23 21 |  | 
| 24 22 | 
             
                 # Renders Textile
         | 
| 25 | 
            -
                 Orgmode::Parser.new("* Hello world!).to_textile
         | 
| 23 | 
            +
                 Orgmode::Parser.new("* Hello world!").to_textile
         | 
| 26 24 | 
             
                 # => "h1. Hello world!\n" 
         | 
| 27 25 |  | 
| 28 26 | 
             
                 # Renders Markdown
         | 
| 29 | 
            -
                 Orgmode::Parser.new("* Hello world!).to_markdown
         | 
| 27 | 
            +
                 Orgmode::Parser.new("* Hello world!").to_markdown
         | 
| 30 28 | 
             
                 # => "# Hello world!\n" 
         | 
| 31 29 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
                 org-ruby sample.org --translate html
         | 
| 35 | 
            -
             | 
| 36 | 
            -
            ...will output a HTML version of sample.org.
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                 org-ruby --translate textile sample.org
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            ...will output a textile version of sample.org.
         | 
| 30 | 
            +
            The supported output exporters can be also called from the command line:
         | 
| 41 31 |  | 
| 32 | 
            +
                 org-ruby --translate html     sample.org
         | 
| 33 | 
            +
                 org-ruby --translate textile  sample.org
         | 
| 42 34 | 
             
                 org-ruby --translate markdown sample.org
         | 
| 43 35 |  | 
| 44 | 
            -
             | 
| 36 | 
            +
            == Current status
         | 
| 45 37 |  | 
| 46 | 
            -
             | 
| 38 | 
            +
            Not all of the {Org mode features}[http://orgmode.org/manual/] are implemented yet.
         | 
| 39 | 
            +
            Currently, the development of the gem is mostly oriented towards
         | 
| 40 | 
            +
            giving support for exporting Org mode into other formats.
         | 
| 47 41 |  | 
| 48 | 
            -
             | 
| 42 | 
            +
            Brief list of features supported:
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            * Converts Org mode files to HTML, Textile or Markdown.
         | 
| 49 45 | 
             
            * Supports tables, block quotes, code blocks, and html blocks
         | 
| 50 46 | 
             
            * Supports bold, italic, underline, strikethrough, and code inline formatting.
         | 
| 51 | 
            -
            * Supports hyperlinks | 
| 52 | 
            -
            * Supports  | 
| 47 | 
            +
            * Supports hyperlinks
         | 
| 48 | 
            +
            * Supports lists
         | 
| 53 49 | 
             
            * Supports footnotes
         | 
| 54 50 | 
             
            * Supports +.org+ views in Rails through Tilt.
         | 
| 55 51 | 
             
            * Code syntax highlight of code blocks using Pygments.rb or Coderay when available
         | 
| 56 52 |  | 
| 53 | 
            +
            == Contributing
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            * If you see a feature missing, please create an issue so that the maintainer considers its implementation
         | 
| 56 | 
            +
            * Also, PRs are always welcome! Before submitting make sure to check what breaks by running <code>rake spec</code>
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            == Projects using it
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            * Used at {github/markup}[https://github.com/github/markup] for rendering +.org+ files
         | 
| 61 | 
            +
            * The {Gollum}[https://github.com/gollum/gollum] project uses it too
         | 
| 62 | 
            +
            * Can be used with Jekyll for building a site: {example here}[https://github.com/wallyqs/yet-another-jekyll-org-template]
         | 
| 63 | 
            +
             | 
| 57 64 | 
             
            == License
         | 
| 58 65 |  | 
| 59 66 | 
             
             (The MIT License)
         | 
    
        data/lib/org-ruby.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
         | 
| 2 2 |  | 
| 3 3 | 
             
            # internal requires
         | 
| 4 | 
            +
            require 'org-ruby/version'
         | 
| 4 5 | 
             
            require 'org-ruby/parser'
         | 
| 5 6 | 
             
            require 'org-ruby/regexp_helper'
         | 
| 6 7 | 
             
            require 'org-ruby/line'
         | 
| @@ -24,7 +25,6 @@ require 'org-ruby/tilt' | |
| 24 25 | 
             
            module OrgRuby
         | 
| 25 26 |  | 
| 26 27 | 
             
              # :stopdoc:
         | 
| 27 | 
            -
              VERSION = '0.9.1'
         | 
| 28 28 | 
             
              LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
         | 
| 29 29 | 
             
              PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
         | 
| 30 30 | 
             
              # :startdoc:
         | 
| @@ -14,37 +14,33 @@ module Orgmode | |
| 14 14 | 
             
              class HtmlOutputBuffer < OutputBuffer
         | 
| 15 15 |  | 
| 16 16 | 
             
                HtmlBlockTag = {
         | 
| 17 | 
            -
                  :paragraph | 
| 18 | 
            -
                  :ordered_list | 
| 19 | 
            -
                  :unordered_list | 
| 20 | 
            -
                  :list_item | 
| 21 | 
            -
                  :definition_list | 
| 22 | 
            -
                  :definition_term | 
| 17 | 
            +
                  :paragraph        => "p",
         | 
| 18 | 
            +
                  :ordered_list     => "ol",
         | 
| 19 | 
            +
                  :unordered_list   => "ul",
         | 
| 20 | 
            +
                  :list_item        => "li",
         | 
| 21 | 
            +
                  :definition_list  => "dl",
         | 
| 22 | 
            +
                  :definition_term  => "dt",
         | 
| 23 23 | 
             
                  :definition_descr => "dd",
         | 
| 24 | 
            -
                  :table | 
| 25 | 
            -
                  :table_row | 
| 26 | 
            -
                  :quote | 
| 27 | 
            -
                  :example | 
| 28 | 
            -
                  :src | 
| 29 | 
            -
                  :inline_example | 
| 30 | 
            -
                  :center | 
| 31 | 
            -
                  :heading1 | 
| 32 | 
            -
                  :heading2 | 
| 33 | 
            -
                  :heading3 | 
| 34 | 
            -
                  :heading4 | 
| 35 | 
            -
                  :heading5 | 
| 36 | 
            -
                  :heading6 | 
| 24 | 
            +
                  :table            => "table",
         | 
| 25 | 
            +
                  :table_row        => "tr",
         | 
| 26 | 
            +
                  :quote            => "blockquote",
         | 
| 27 | 
            +
                  :example          => "pre",
         | 
| 28 | 
            +
                  :src              => "pre",
         | 
| 29 | 
            +
                  :inline_example   => "pre",
         | 
| 30 | 
            +
                  :center           => "div",
         | 
| 31 | 
            +
                  :heading1         => "h1",
         | 
| 32 | 
            +
                  :heading2         => "h2",
         | 
| 33 | 
            +
                  :heading3         => "h3",
         | 
| 34 | 
            +
                  :heading4         => "h4",
         | 
| 35 | 
            +
                  :heading5         => "h5",
         | 
| 36 | 
            +
                  :heading6         => "h6",
         | 
| 37 | 
            +
                  :title            => "h1"
         | 
| 37 38 | 
             
                }
         | 
| 38 39 |  | 
| 39 40 | 
             
                attr_reader :options
         | 
| 40 41 |  | 
| 41 42 | 
             
                def initialize(output, opts = {})
         | 
| 42 43 | 
             
                  super(output)
         | 
| 43 | 
            -
                  if opts[:decorate_title] then
         | 
| 44 | 
            -
                    @title_decoration = " class=\"title\""
         | 
| 45 | 
            -
                  else
         | 
| 46 | 
            -
                    @title_decoration = ""
         | 
| 47 | 
            -
                  end
         | 
| 48 44 | 
             
                  @buffer_tag = "HTML"
         | 
| 49 45 | 
             
                  @options = opts
         | 
| 50 46 | 
             
                  @new_paragraph = :start
         | 
| @@ -71,8 +67,8 @@ module Orgmode | |
| 71 67 | 
             
                                    " class=\"example\""
         | 
| 72 68 | 
             
                                  when mode == :center
         | 
| 73 69 | 
             
                                    " style=\"text-align: center\""
         | 
| 74 | 
            -
                                   | 
| 75 | 
            -
                                     | 
| 70 | 
            +
                                  when @options[:decorate_title]
         | 
| 71 | 
            +
                                    " class=\"title\""
         | 
| 76 72 | 
             
                                  end
         | 
| 77 73 |  | 
| 78 74 | 
             
                      add_paragraph unless @new_paragraph == :start
         | 
| @@ -81,7 +77,7 @@ module Orgmode | |
| 81 77 | 
             
                      @logger.debug "#{mode}: <#{HtmlBlockTag[mode]}#{css_class}>"
         | 
| 82 78 | 
             
                      @output << "<#{HtmlBlockTag[mode]}#{css_class}>"
         | 
| 83 79 | 
             
                      # Entering a new mode obliterates the title decoration
         | 
| 84 | 
            -
                      @ | 
| 80 | 
            +
                      @options[:decorate_title] = nil
         | 
| 85 81 | 
             
                    end
         | 
| 86 82 | 
             
                  end
         | 
| 87 83 | 
             
                end
         | 
| @@ -138,7 +134,7 @@ module Orgmode | |
| 138 134 | 
             
                      @buffer.gsub!(/\A\n/, "") if @new_paragraph == :start
         | 
| 139 135 | 
             
                      @new_paragraph = true
         | 
| 140 136 | 
             
                    else
         | 
| 141 | 
            -
                      # *NOTE* Don't use  | 
| 137 | 
            +
                      # *NOTE* Don't use escape_string! through its sensitivity to @@html:<text>@@ forms
         | 
| 142 138 | 
             
                      @buffer = escapeHTML @buffer
         | 
| 143 139 | 
             
                    end
         | 
| 144 140 |  | 
| @@ -171,8 +167,6 @@ module Orgmode | |
| 171 167 | 
             
                      push_mode(:definition_descr, indent)
         | 
| 172 168 | 
             
                      @output << inline_formatting(d[2].strip + d[3])
         | 
| 173 169 | 
             
                      @new_paragraph = nil
         | 
| 174 | 
            -
                      # FIXME: Need to restore tags once again (this should be done in escape_buffer!)
         | 
| 175 | 
            -
                      @output.gsub!(/@(<[^<>\n]*>)/, "\\1")
         | 
| 176 170 |  | 
| 177 171 | 
             
                    when :horizontal_rule
         | 
| 178 172 | 
             
                      add_paragraph unless @new_paragraph == :start
         | 
| @@ -232,22 +226,22 @@ module Orgmode | |
| 232 226 | 
             
                   mode == :table_separator or mode == :table_header)
         | 
| 233 227 | 
             
                end
         | 
| 234 228 |  | 
| 235 | 
            -
                # Escapes any HTML content in  | 
| 236 | 
            -
                def  | 
| 237 | 
            -
                   | 
| 229 | 
            +
                # Escapes any HTML content in string
         | 
| 230 | 
            +
                def escape_string! str
         | 
| 231 | 
            +
                  str.gsub!(/&/, "&")
         | 
| 238 232 | 
             
                  # Escapes the left and right angular brackets but construction
         | 
| 239 | 
            -
                  #  | 
| 240 | 
            -
                   | 
| 241 | 
            -
                     | 
| 242 | 
            -
                    else "<#{$1}"
         | 
| 243 | 
            -
                    end
         | 
| 233 | 
            +
                  # @@html:<text>@@ which is formatted to <text>
         | 
| 234 | 
            +
                  str.gsub! /<([^<>\n]*)/ do |match|
         | 
| 235 | 
            +
                    ($`[-7..-1] == "@@html:" and $'[0..2] == ">@@") ? $& : "<#{$1}"
         | 
| 244 236 | 
             
                  end
         | 
| 245 | 
            -
                   | 
| 246 | 
            -
                     | 
| 247 | 
            -
                    else "#{$1}>"
         | 
| 248 | 
            -
                    end
         | 
| 237 | 
            +
                  str.gsub! /([^<>\n]*)>/ do |match|
         | 
| 238 | 
            +
                    $`[-8..-1] == "@@html:<" ? $& : "#{$1}>"
         | 
| 249 239 | 
             
                  end
         | 
| 250 | 
            -
                   | 
| 240 | 
            +
                  str.gsub! /@@html:(<[^<>\n]*>)@@/, "\\1"
         | 
| 241 | 
            +
                end
         | 
| 242 | 
            +
             | 
| 243 | 
            +
                def quote_tags str
         | 
| 244 | 
            +
                  str.gsub /(<[^<>\n]*>)/, "@@html:\\1@@"
         | 
| 251 245 | 
             
                end
         | 
| 252 246 |  | 
| 253 247 | 
             
                def buffer_indentation
         | 
| @@ -277,23 +271,25 @@ module Orgmode | |
| 277 271 | 
             
                      s = escapeHTML s
         | 
| 278 272 | 
             
                      "<#{Tags[marker][:open]}>#{s}</#{Tags[marker][:close]}>"
         | 
| 279 273 | 
             
                    else
         | 
| 280 | 
            -
                      " | 
| 274 | 
            +
                      quote_tags("<#{Tags[marker][:open]}>") + s +
         | 
| 275 | 
            +
                        quote_tags("</#{Tags[marker][:close]}>")
         | 
| 281 276 | 
             
                    end
         | 
| 282 277 | 
             
                  end
         | 
| 278 | 
            +
             | 
| 283 279 | 
             
                  if @options[:use_sub_superscripts] then
         | 
| 284 280 | 
             
                    @re_help.rewrite_subp str do |type, text|
         | 
| 285 281 | 
             
                      if type == "_" then
         | 
| 286 | 
            -
                        " | 
| 282 | 
            +
                        quote_tags("<sub>") + text + quote_tags("</sub>")
         | 
| 287 283 | 
             
                      elsif type == "^" then
         | 
| 288 | 
            -
                        " | 
| 284 | 
            +
                        quote_tags("<sup>") + text + quote_tags("</sup>")
         | 
| 289 285 | 
             
                      end
         | 
| 290 286 | 
             
                    end
         | 
| 291 287 | 
             
                  end
         | 
| 288 | 
            +
             | 
| 292 289 | 
             
                  @re_help.rewrite_links str do |link, defi|
         | 
| 293 290 | 
             
                    [link, defi].compact.each do |text|
         | 
| 294 291 | 
             
                      # We don't support search links right now. Get rid of it.
         | 
| 295 292 | 
             
                      text.sub!(/\A(file:[^\s]+)::[^\s]*?\Z/, "\\1")
         | 
| 296 | 
            -
                      text.sub!(/\A(file:[^\s]+)\.org\Z/i, "\\1.html")
         | 
| 297 293 | 
             
                      text.sub!(/\Afile:(?=[^\s]+\Z)/, "")
         | 
| 298 294 | 
             
                    end
         | 
| 299 295 |  | 
| @@ -302,38 +298,44 @@ module Orgmode | |
| 302 298 | 
             
                    defi ||= link unless link =~ @re_help.org_image_file_regexp
         | 
| 303 299 |  | 
| 304 300 | 
             
                    if defi =~ @re_help.org_image_file_regexp
         | 
| 305 | 
            -
                      defi = " | 
| 301 | 
            +
                      defi = quote_tags "<img src=\"#{defi}\" alt=\"#{defi}\" />"
         | 
| 306 302 | 
             
                    end
         | 
| 307 303 |  | 
| 308 304 | 
             
                    if defi
         | 
| 309 305 | 
             
                      link = @options[:link_abbrevs][link] if @options[:link_abbrevs].has_key? link
         | 
| 310 | 
            -
                      " | 
| 306 | 
            +
                      quote_tags("<a href=\"#{link}\">") + defi + quote_tags("</a>")
         | 
| 311 307 | 
             
                    else
         | 
| 312 | 
            -
                      " | 
| 308 | 
            +
                      quote_tags "<img src=\"#{link}\" alt=\"#{link}\" />"
         | 
| 313 309 | 
             
                    end
         | 
| 314 310 | 
             
                  end
         | 
| 311 | 
            +
             | 
| 315 312 | 
             
                  if @output_type == :table_row
         | 
| 316 | 
            -
                    str.gsub! | 
| 317 | 
            -
                    str.gsub! | 
| 318 | 
            -
                    str.gsub! | 
| 313 | 
            +
                    str.gsub! /^\|\s*/, quote_tags("<td>")
         | 
| 314 | 
            +
                    str.gsub! /\s*\|$/, quote_tags("</td>")
         | 
| 315 | 
            +
                    str.gsub! /\s*\|\s*/, quote_tags("</td><td>")
         | 
| 319 316 | 
             
                  end
         | 
| 317 | 
            +
             | 
| 320 318 | 
             
                  if @output_type == :table_header
         | 
| 321 | 
            -
                    str.gsub! | 
| 322 | 
            -
                    str.gsub! | 
| 323 | 
            -
                    str.gsub! | 
| 319 | 
            +
                    str.gsub! /^\|\s*/, quote_tags("<th>")
         | 
| 320 | 
            +
                    str.gsub! /\s*\|$/, quote_tags("</th>")
         | 
| 321 | 
            +
                    str.gsub! /\s*\|\s*/, quote_tags("</th><th>")
         | 
| 324 322 | 
             
                  end
         | 
| 323 | 
            +
             | 
| 325 324 | 
             
                  if @options[:export_footnotes] then
         | 
| 326 325 | 
             
                    @re_help.rewrite_footnote str do |name, defi|
         | 
| 327 326 | 
             
                      # TODO escape name for url?
         | 
| 328 327 | 
             
                      @footnotes[name] = defi if defi
         | 
| 329 | 
            -
                      " | 
| 328 | 
            +
                      quote_tags("<sup><a class=\"footref\" name=\"fnr.#{name}\" href=\"#fn.#{name}\">") +
         | 
| 329 | 
            +
                        name + quote_tags("</a></sup>")
         | 
| 330 330 | 
             
                    end
         | 
| 331 331 | 
             
                  end
         | 
| 332 | 
            +
             | 
| 332 333 | 
             
                  # Two backslashes \\ at the end of the line make a line break without breaking paragraph.
         | 
| 333 334 | 
             
                  if @output_type != :table_row and @output_type != :table_header then
         | 
| 334 | 
            -
                    str.sub! | 
| 335 | 
            +
                    str.sub! /\\\\$/, quote_tags("<br />")
         | 
| 335 336 | 
             
                  end
         | 
| 336 | 
            -
             | 
| 337 | 
            +
             | 
| 338 | 
            +
                  escape_string! str
         | 
| 337 339 | 
             
                  Orgmode.special_symbols_to_html str
         | 
| 338 340 | 
             
                  str = @re_help.restore_code_snippets str
         | 
| 339 341 | 
             
                end
         | 
| @@ -360,9 +362,10 @@ module Orgmode | |
| 360 362 | 
             
                end
         | 
| 361 363 |  | 
| 362 364 | 
             
                def strip_code_block!
         | 
| 363 | 
            -
                  @code_block_indent  | 
| 364 | 
            -
             | 
| 365 | 
            -
             | 
| 365 | 
            +
                  if @code_block_indent and @code_block_indent > 0
         | 
| 366 | 
            +
                    strip_regexp = Regexp.new("^" + " " * @code_block_indent)
         | 
| 367 | 
            +
                    @buffer.gsub!(strip_regexp, "")
         | 
| 368 | 
            +
                  end
         | 
| 366 369 | 
             
                  @code_block_indent = nil
         | 
| 367 370 |  | 
| 368 371 | 
             
                  # Strip proctective commas generated by Org mode (C-c ')
         | 
    
        data/lib/org-ruby/line.rb
    CHANGED
    
    | @@ -24,14 +24,14 @@ module Orgmode | |
| 24 24 | 
             
                # type. This will then affect the value of +paragraph_type+.
         | 
| 25 25 | 
             
                attr_accessor :assigned_paragraph_type
         | 
| 26 26 |  | 
| 27 | 
            -
                def initialize(line, parser = | 
| 27 | 
            +
                def initialize(line, parser=nil, assigned_paragraph_type=nil)
         | 
| 28 28 | 
             
                  @parser = parser
         | 
| 29 29 | 
             
                  @line = line
         | 
| 30 30 | 
             
                  @indent = 0
         | 
| 31 31 | 
             
                  @line =~ /\s*/
         | 
| 32 | 
            +
                  @assigned_paragraph_type = assigned_paragraph_type
         | 
| 32 33 | 
             
                  determine_paragraph_type
         | 
| 33 34 | 
             
                  determine_major_mode
         | 
| 34 | 
            -
                  @assigned_paragraph_type = nil
         | 
| 35 35 | 
             
                  @indent = $&.length unless blank?
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| @@ -158,7 +158,13 @@ module Orgmode | |
| 158 158 | 
             
                  table_row? or table_separator? or table_header?
         | 
| 159 159 | 
             
                end
         | 
| 160 160 |  | 
| 161 | 
            -
                 | 
| 161 | 
            +
                #
         | 
| 162 | 
            +
                # 1) block delimiters
         | 
| 163 | 
            +
                # 2) block type (src, example, html...) 
         | 
| 164 | 
            +
                # 3) switches (e.g. -n -r -l "asdf")
         | 
| 165 | 
            +
                # 4) header arguments (:hello world)
         | 
| 166 | 
            +
                #
         | 
| 167 | 
            +
                BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)\s*([0-9A-Za-z_\-]*)?\s*([^\":\n]*\"[^\"\n*]*\"[^\":\n]*|[^\":\n]*)?\s*([^\n]*)?/i
         | 
| 162 168 |  | 
| 163 169 | 
             
                def begin_block?
         | 
| 164 170 | 
             
                  @line =~ BlockRegexp && $1 =~ /BEGIN/i
         | 
| @@ -180,6 +186,48 @@ module Orgmode | |
| 180 186 | 
             
                  block_type =~ /^(EXAMPLE|SRC)$/i
         | 
| 181 187 | 
             
                end
         | 
| 182 188 |  | 
| 189 | 
            +
                def block_switches
         | 
| 190 | 
            +
                  $4 if @line =~ BlockRegexp
         | 
| 191 | 
            +
                end
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                def block_header_arguments
         | 
| 194 | 
            +
                  header_arguments = { }
         | 
| 195 | 
            +
             | 
| 196 | 
            +
                  if @line =~ BlockRegexp
         | 
| 197 | 
            +
                    header_arguments_string = $5
         | 
| 198 | 
            +
                    harray = header_arguments_string.split(' ')
         | 
| 199 | 
            +
                    harray.each_with_index do |arg, i|
         | 
| 200 | 
            +
                      next_argument = harray[i + 1]
         | 
| 201 | 
            +
                      if arg =~ /^:/ and not (next_argument.nil? or next_argument =~ /^:/)
         | 
| 202 | 
            +
                        header_arguments[arg] = next_argument
         | 
| 203 | 
            +
                      end
         | 
| 204 | 
            +
                    end
         | 
| 205 | 
            +
                  end
         | 
| 206 | 
            +
             | 
| 207 | 
            +
                  header_arguments
         | 
| 208 | 
            +
                end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                # TODO: COMMENT block should be considered here
         | 
| 211 | 
            +
                def block_should_be_exported?
         | 
| 212 | 
            +
                  export_state = block_header_arguments[':exports']
         | 
| 213 | 
            +
                  case
         | 
| 214 | 
            +
                  when ['both', 'code', nil, ''].include?(export_state)
         | 
| 215 | 
            +
                    true
         | 
| 216 | 
            +
                  when ['none', 'results'].include?(export_state)
         | 
| 217 | 
            +
                    false
         | 
| 218 | 
            +
                  end
         | 
| 219 | 
            +
                end
         | 
| 220 | 
            +
             | 
| 221 | 
            +
                def results_block_should_be_exported?
         | 
| 222 | 
            +
                  export_state = block_header_arguments[':exports']
         | 
| 223 | 
            +
                  case
         | 
| 224 | 
            +
                  when ['results', 'both'].include?(export_state)
         | 
| 225 | 
            +
                    true
         | 
| 226 | 
            +
                  when ['code', 'none', nil, ''].include?(export_state)
         | 
| 227 | 
            +
                    false
         | 
| 228 | 
            +
                  end
         | 
| 229 | 
            +
                end
         | 
| 230 | 
            +
             | 
| 183 231 | 
             
                InlineExampleRegexp = /^\s*:\s/
         | 
| 184 232 |  | 
| 185 233 | 
             
                # Test if the line matches the "inline example" case:
         | 
| @@ -224,6 +272,18 @@ module Orgmode | |
| 224 272 | 
             
                  end
         | 
| 225 273 | 
             
                end
         | 
| 226 274 |  | 
| 275 | 
            +
                # #+TITLE: is special because even though that it can be
         | 
| 276 | 
            +
                # written many times in the document, its value will be that of the last one
         | 
| 277 | 
            +
                def title?
         | 
| 278 | 
            +
                  @assigned_paragraph_type == :title
         | 
| 279 | 
            +
                end
         | 
| 280 | 
            +
             | 
| 281 | 
            +
                ResultsBlockStartsRegexp = /^\s*#\+RESULTS:\s*$/i
         | 
| 282 | 
            +
             | 
| 283 | 
            +
                def start_of_results_code_block?
         | 
| 284 | 
            +
                  @line =~ ResultsBlockStartsRegexp
         | 
| 285 | 
            +
                end
         | 
| 286 | 
            +
             | 
| 227 287 | 
             
                LinkAbbrevRegexp = /^\s*#\+LINK:\s*(\w+)\s+(.+)$/i
         | 
| 228 288 |  | 
| 229 289 | 
             
                def link_abbrev?
         | 
| @@ -267,12 +327,18 @@ module Orgmode | |
| 267 327 | 
             
                  when metadata?
         | 
| 268 328 | 
             
                    :metadata
         | 
| 269 329 | 
             
                  when block_type
         | 
| 270 | 
            -
                     | 
| 271 | 
            -
             | 
| 272 | 
            -
                       | 
| 330 | 
            +
                    if block_should_be_exported?
         | 
| 331 | 
            +
                      case block_type.downcase.to_sym
         | 
| 332 | 
            +
                      when :center, :comment, :example, :html, :quote, :src
         | 
| 333 | 
            +
                        block_type.downcase.to_sym
         | 
| 334 | 
            +
                      else
         | 
| 335 | 
            +
                        :comment
         | 
| 336 | 
            +
                      end
         | 
| 273 337 | 
             
                    else
         | 
| 274 338 | 
             
                      :comment
         | 
| 275 339 | 
             
                    end
         | 
| 340 | 
            +
                  when title?
         | 
| 341 | 
            +
                    :title
         | 
| 276 342 | 
             
                  when raw_text? # order is important! Raw text can be also a comment
         | 
| 277 343 | 
             
                    :raw_text
         | 
| 278 344 | 
             
                  when comment?
         | 
| @@ -60,7 +60,8 @@ module Orgmode | |
| 60 60 | 
             
                def insert(line)
         | 
| 61 61 | 
             
                  # Prepares the output buffer to receive content from a line.
         | 
| 62 62 | 
             
                  # As a side effect, this may flush the current accumulated text.
         | 
| 63 | 
            -
                  @logger.debug "Looking at #{line.paragraph_type}(#{current_mode}) : #{line.to_s}"
         | 
| 63 | 
            +
                  @logger.debug "Looking at #{line.paragraph_type}|#{line.assigned_paragraph_type}(#{current_mode}) : #{line.to_s}"
         | 
| 64 | 
            +
             | 
| 64 65 | 
             
                  # We try to get the lang from #+BEGIN_SRC blocks
         | 
| 65 66 | 
             
                  @block_lang = line.block_lang if line.begin_block?
         | 
| 66 67 | 
             
                  unless should_accumulate_output?(line)
         | 
| @@ -70,6 +71,10 @@ module Orgmode | |
| 70 71 |  | 
| 71 72 | 
             
                  # Adds the current line to the output buffer
         | 
| 72 73 | 
             
                  case
         | 
| 74 | 
            +
                  when line.assigned_paragraph_type == :comment
         | 
| 75 | 
            +
                    # Don't add to buffer
         | 
| 76 | 
            +
                  when line.title?
         | 
| 77 | 
            +
                    @buffer << line.output_text
         | 
| 73 78 | 
             
                  when line.raw_text?
         | 
| 74 79 | 
             
                    @buffer << "\n" << line.output_text if line.raw_text_tag == @buffer_tag
         | 
| 75 80 | 
             
                  when preserve_whitespace?
         | 
| @@ -187,7 +192,7 @@ module Orgmode | |
| 187 192 | 
             
                  # Special case: Only end-block line closes block
         | 
| 188 193 | 
             
                  pop_mode if line.end_block? and line.paragraph_type == current_mode
         | 
| 189 194 |  | 
| 190 | 
            -
                  unless line.paragraph_type == :blank
         | 
| 195 | 
            +
                  unless line.paragraph_type == :blank or line.assigned_paragraph_type == :comment
         | 
| 191 196 | 
             
                    if (@list_indent_stack.empty? or
         | 
| 192 197 | 
             
                        @list_indent_stack.last <= line.indent or
         | 
| 193 198 | 
             
                        mode_is_block? current_mode)
         | 
    
        data/lib/org-ruby/parser.rb
    CHANGED
    
    | @@ -167,7 +167,7 @@ module Orgmode | |
| 167 167 | 
             
                      @link_abbrevs[link_abbrev_data[0]] = link_abbrev_data[1]
         | 
| 168 168 | 
             
                    end
         | 
| 169 169 |  | 
| 170 | 
            -
                    mode = :normal if line.end_block? and  | 
| 170 | 
            +
                    mode = :normal if line.end_block? and [line.paragraph_type, :comment].include?(mode)
         | 
| 171 171 | 
             
                    mode = :normal if line.property_drawer_end_block? and mode == :property_drawer
         | 
| 172 172 |  | 
| 173 173 | 
             
                    case mode
         | 
| @@ -183,6 +183,8 @@ module Orgmode | |
| 183 183 | 
             
                      table_header_set = false if !line.table?
         | 
| 184 184 |  | 
| 185 185 | 
             
                    when :example, :html, :src
         | 
| 186 | 
            +
                      set_mode_for_results_block_contents(previous_line, line) if previous_line
         | 
| 187 | 
            +
             | 
| 186 188 | 
             
                      # As long as we stay in code mode, force lines to be code.
         | 
| 187 189 | 
             
                      # Don't try to interpret structural items, like headings and tables.
         | 
| 188 190 | 
             
                      line.assigned_paragraph_type = :code
         | 
| @@ -196,7 +198,21 @@ module Orgmode | |
| 196 198 | 
             
                      end
         | 
| 197 199 |  | 
| 198 200 | 
             
                      mode = line.paragraph_type if line.begin_block?
         | 
| 199 | 
            -
             | 
| 201 | 
            +
             | 
| 202 | 
            +
                      if previous_line
         | 
| 203 | 
            +
                        set_mode_for_results_block_contents(previous_line, line)
         | 
| 204 | 
            +
             | 
| 205 | 
            +
                        mode = :property_drawer if previous_line.property_drawer_begin_block?
         | 
| 206 | 
            +
                      end
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                      # We treat the results code block differently since the exporting can be omitted
         | 
| 209 | 
            +
                      if line.begin_block?
         | 
| 210 | 
            +
                        if line.results_block_should_be_exported?
         | 
| 211 | 
            +
                          @next_results_block_should_be_exported = true
         | 
| 212 | 
            +
                        else
         | 
| 213 | 
            +
                          @next_results_block_should_be_exported = false
         | 
| 214 | 
            +
                        end
         | 
| 215 | 
            +
                      end
         | 
| 200 216 | 
             
                    end
         | 
| 201 217 |  | 
| 202 218 | 
             
                    if mode == :property_drawer and @current_headline
         | 
| @@ -258,6 +274,15 @@ module Orgmode | |
| 258 274 | 
             
                  include_data
         | 
| 259 275 | 
             
                end
         | 
| 260 276 |  | 
| 277 | 
            +
                def set_mode_for_results_block_contents(previous_line, line)
         | 
| 278 | 
            +
                  if previous_line.start_of_results_code_block? \
         | 
| 279 | 
            +
                    or previous_line.assigned_paragraph_type == :comment
         | 
| 280 | 
            +
                    unless @next_results_block_should_be_exported or line.paragraph_type == :blank
         | 
| 281 | 
            +
                      line.assigned_paragraph_type = :comment
         | 
| 282 | 
            +
                    end
         | 
| 283 | 
            +
                  end
         | 
| 284 | 
            +
                end
         | 
| 285 | 
            +
             | 
| 261 286 | 
             
                # Creates a new parser from the data in a given file
         | 
| 262 287 | 
             
                def self.load(fname)
         | 
| 263 288 | 
             
                  lines = IO.readlines(fname)
         | 
| @@ -301,22 +326,22 @@ module Orgmode | |
| 301 326 | 
             
                def to_html
         | 
| 302 327 | 
             
                  mark_trees_for_export
         | 
| 303 328 | 
             
                  export_options = {
         | 
| 304 | 
            -
                    :decorate_title | 
| 329 | 
            +
                    :decorate_title        => @in_buffer_settings["TITLE"],
         | 
| 305 330 | 
             
                    :export_heading_number => export_heading_number?,
         | 
| 306 | 
            -
                    :export_todo | 
| 307 | 
            -
                    :use_sub_superscripts  | 
| 308 | 
            -
                    :export_footnotes | 
| 309 | 
            -
                    :link_abbrevs | 
| 331 | 
            +
                    :export_todo           => export_todo?,
         | 
| 332 | 
            +
                    :use_sub_superscripts  => use_sub_superscripts?,
         | 
| 333 | 
            +
                    :export_footnotes      => export_footnotes?,
         | 
| 334 | 
            +
                    :link_abbrevs          => @link_abbrevs
         | 
| 310 335 | 
             
                  }
         | 
| 311 336 | 
             
                  export_options[:skip_tables] = true if not export_tables?
         | 
| 312 337 | 
             
                  output = ""
         | 
| 313 338 | 
             
                  output_buffer = HtmlOutputBuffer.new(output, export_options)
         | 
| 314 339 |  | 
| 315 | 
            -
                  if @in_buffer_settings["TITLE"] | 
| 340 | 
            +
                  if @in_buffer_settings["TITLE"]
         | 
| 316 341 |  | 
| 317 342 | 
             
                    # If we're given a new title, then just create a new line
         | 
| 318 343 | 
             
                    # for that title.
         | 
| 319 | 
            -
                    title = Line.new(@in_buffer_settings["TITLE"], self)
         | 
| 344 | 
            +
                    title = Line.new(@in_buffer_settings["TITLE"], self, :title)
         | 
| 320 345 | 
             
                    translate([title], output_buffer)
         | 
| 321 346 | 
             
                  end
         | 
| 322 347 | 
             
                  translate(@header_lines, output_buffer) unless skip_header_lines?
         | 
    
        metadata
    CHANGED
    
    | @@ -1,19 +1,20 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: org-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.9. | 
| 4 | 
            +
              version: 0.9.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Brian Dewey
         | 
| 9 | 
            +
            - Waldemar Quevedo
         | 
| 9 10 | 
             
            autorequire: 
         | 
| 10 11 | 
             
            bindir: bin
         | 
| 11 12 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2014- | 
| 13 | 
            +
            date: 2014-03-22 00:00:00.000000000 Z
         | 
| 13 14 | 
             
            dependencies:
         | 
| 14 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 16 | 
             
              name: rubypants
         | 
| 16 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
              requirement: &70189716079180 !ruby/object:Gem::Requirement
         | 
| 17 18 | 
             
                none: false
         | 
| 18 19 | 
             
                requirements:
         | 
| 19 20 | 
             
                - - ! '>='
         | 
| @@ -21,23 +22,9 @@ dependencies: | |
| 21 22 | 
             
                    version: 0.2.0
         | 
| 22 23 | 
             
              type: :runtime
         | 
| 23 24 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements:  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
                - - ! '>='
         | 
| 28 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            -
                    version: 0.2.0
         | 
| 30 | 
            -
            description: ! 'An org-mode parser written in Ruby. This gem contains Ruby routines
         | 
| 31 | 
            -
              for parsing org-mode files.The most
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              significant thing this library does today is convert org-mode files to
         | 
| 34 | 
            -
             | 
| 35 | 
            -
              HTML or textile. Currently, you cannot do much to customize the
         | 
| 36 | 
            -
             | 
| 37 | 
            -
              conversion. The supplied textile conversion is optimized for
         | 
| 38 | 
            -
             | 
| 39 | 
            -
              extracting "content" from the orgfile as opposed to "metadata." '
         | 
| 40 | 
            -
            email: bdewey@gmail.com
         | 
| 25 | 
            +
              version_requirements: *70189716079180
         | 
| 26 | 
            +
            description: An Org mode parser written in Ruby.
         | 
| 27 | 
            +
            email: waldemar.quevedo@gmail.com
         | 
| 41 28 | 
             
            executables:
         | 
| 42 29 | 
             
            - org-ruby
         | 
| 43 30 | 
             
            extensions: []
         | 
| @@ -61,13 +48,12 @@ files: | |
| 61 48 | 
             
            - lib/org-ruby/textile_output_buffer.rb
         | 
| 62 49 | 
             
            - lib/org-ruby/textile_symbol_replace.rb
         | 
| 63 50 | 
             
            - lib/org-ruby/tilt.rb
         | 
| 64 | 
            -
             | 
| 51 | 
            +
            - lib/org-ruby/version.rb
         | 
| 52 | 
            +
            homepage: https://github.com/wallyqs/org-ruby
         | 
| 65 53 | 
             
            licenses:
         | 
| 66 54 | 
             
            - MIT
         | 
| 67 55 | 
             
            post_install_message: 
         | 
| 68 | 
            -
            rdoc_options:
         | 
| 69 | 
            -
            - --main
         | 
| 70 | 
            -
            - README.rdoc
         | 
| 56 | 
            +
            rdoc_options: []
         | 
| 71 57 | 
             
            require_paths:
         | 
| 72 58 | 
             
            - lib
         | 
| 73 59 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| @@ -84,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 84 70 | 
             
                  version: '0'
         | 
| 85 71 | 
             
            requirements: []
         | 
| 86 72 | 
             
            rubyforge_project: org-ruby
         | 
| 87 | 
            -
            rubygems_version: 1.8. | 
| 73 | 
            +
            rubygems_version: 1.8.10
         | 
| 88 74 | 
             
            signing_key: 
         | 
| 89 75 | 
             
            specification_version: 3
         | 
| 90 76 | 
             
            summary: This gem contains Ruby routines for parsing org-mode files.
         |