From fdabd21d024ca0985578aace8fe78c29d29dc735 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Mon, 21 Nov 2022 17:16:40 +0100 Subject: [PATCH 01/12] Add highlighting through Rouge. --- lib/org-ruby/highlighter.rb | 61 ++++++++++++++++++++++++++++++ lib/org-ruby/html_output_buffer.rb | 48 +++++------------------ 2 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 lib/org-ruby/highlighter.rb diff --git a/lib/org-ruby/highlighter.rb b/lib/org-ruby/highlighter.rb new file mode 100644 index 0000000..91fe0d4 --- /dev/null +++ b/lib/org-ruby/highlighter.rb @@ -0,0 +1,61 @@ +module Orgmode + # Highlight code + module Highlighter + def self.highlight(code, lang) + highlighter = guess_highlighter + highlighter.highlight(code, lang) + end + + def self.guess_highlighter + return RougeHighliter if gem_present?('rouge') + return PygmentsHighliter if gem_present?('pygments.rb') + return CodeRayHighliter if gem_present?('coderay') + + DefaultHighliter + end + + def self.gem_present?(gem) + Gem::Specification.find_all_by_name(gem).any? + end + + # Default highliter does nothing to code + class DefaultHighliter + def self.highlight(buffer, _lang) + buffer + end + end + + # Pygments wrapper + class PygmentsHighliter + def self.highlight(buffer, lang) + require 'pygments' + if Pygments::Lexer.find_by_alias(lang) + Pygments.highlight(buffer, lexer: lang) + else + Pygments.highlight(buffer, lexer: 'text') + end + end + end + + # CodeRay wrapper + class CodeRayHighliter + def self.highlight(buffer, lang) + require 'coderay' + CodeRay.scan(buffer, lang).html(wrap: nil, css: :style) + rescue ArgumentError => _e + CodeRay.scan(buffer, 'text').html(wrap: nil, css: :style) + end + end + + # Rouge wrapper + class RougeHighliter + def self.highlight(buffer, lang) + require 'rouge' + formatter = Rouge::Formatters::HTMLLegacy.new + lexer = Rouge::Lexer.find_fancy(lang, buffer) || + Rouge::Lexers::PlainText + formatter.format(lexer.lex(buffer.strip)) + end + end + end +end diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 180bd80..a3f9724 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -1,7 +1,7 @@ module Orgmode class HtmlOutputBuffer < OutputBuffer - + require_relative './highlighter.rb' HtmlBlockTag = { :paragraph => "p", :ordered_list => "ol", @@ -37,20 +37,6 @@ def initialize(output, opts = {}) @unclosed_tags = [] @logger.debug "HTML export options: #{@options.inspect}" @custom_blocktags = {} if @options[:markup_file] - - unless @options[:skip_syntax_highlight] - begin - require 'pygments' - rescue LoadError - # Pygments is not supported so we try instead with CodeRay - begin - require 'coderay' - rescue LoadError - # No code syntax highlighting - end - end - end - if @options[:markup_file] do_custom_markup end @@ -64,7 +50,7 @@ def push_mode(mode, indent, properties={}) super(mode, indent, properties) if HtmlBlockTag[mode] unless ((mode_is_table?(mode) and skip_tables?) or - (mode == :src and !@options[:skip_syntax_highlight] and defined? Pygments)) + (mode == :src and !@options[:skip_syntax_highlight])) css_class = case when (mode == :src and @block_lang.empty?) " class=\"src\"" @@ -100,7 +86,7 @@ def pop_mode(mode = nil) m = super(mode) if HtmlBlockTag[m] unless ((mode_is_table?(m) and skip_tables?) or - (m == :src and !@options[:skip_syntax_highlight] and defined? Pygments)) + (m == :src and !@options[:skip_syntax_highlight])) add_paragraph if @new_paragraph @new_paragraph = true @logger.debug "" @@ -110,6 +96,10 @@ def pop_mode(mode = nil) @list_indent_stack.pop end + def highlight(code, lang) + Highlighter.highlight code, lang + end + def flush! return false if @buffer.empty? case @@ -121,29 +111,9 @@ def flush! case when (current_mode == :src and @options[:skip_syntax_highlight]) @buffer = escapeHTML @buffer - when (current_mode == :src and defined? Pygments) + when (current_mode == :src) lang = normalize_lang @block_lang - @output << "\n" unless @new_paragraph == :start - @new_paragraph = true - - begin - @buffer = Pygments.highlight(@buffer, :lexer => lang) - rescue - # Not supported lexer from Pygments, we fallback on using the text lexer - @buffer = Pygments.highlight(@buffer, :lexer => 'text') - end - when (current_mode == :src and defined? CodeRay) - lang = normalize_lang @block_lang - - # CodeRay might throw a warning when unsupported lang is set, - # then fallback to using the text lexer - silence_warnings do - begin - @buffer = CodeRay.scan(@buffer, lang).html(:wrap => nil, :css => :style) - rescue ArgumentError - @buffer = CodeRay.scan(@buffer, 'text').html(:wrap => nil, :css => :style) - end - end + @buffer = highlight @buffer, lang when (current_mode == :html or current_mode == :raw_text) @buffer.gsub!(/\A\n/, "") if @new_paragraph == :start @new_paragraph = true From 2403848be154fe1c12eb16400171049d710df067 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Mon, 7 Sep 2020 19:57:09 -0500 Subject: [PATCH 02/12] Prevent included files get parsed twice. --- lib/org-ruby/parser.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index a57fd9e..c9d2624 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -79,17 +79,17 @@ def use_sub_superscripts? @options["^"] != "nil" end + def initialize_lines(lines) + return lines if lines.is_a? Array + return lines.split("\n") if lines.is_a? String + + raise "Unsupported type for +lines+: #{lines.class}" + end + # I can construct a parser object either with an array of lines # or with a single string that I will split along \n boundaries. def initialize(lines, parser_options={ }) - if lines.is_a? Array then - @lines = lines - elsif lines.is_a? String then - @lines = lines.split("\n") - else - raise "Unsupported type for +lines+: #{lines.class}" - end - + @lines = initialize_lines lines @custom_keywords = [] @headlines = Array.new @current_headline = nil @@ -156,7 +156,7 @@ def parse_lines(lines) if line.include_file? and not line.include_file_path.nil? next if not check_include_file line.include_file_path include_data = get_include_data line - include_lines = Orgmode::Parser.new(include_data, @parser_options).lines + include_lines = initialize_lines include_data parse_lines include_lines end end From 96e9ccecad492bdaeb3d6da2663af1a19641f5b6 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sat, 27 Mar 2021 16:03:44 -0600 Subject: [PATCH 03/12] Refactor HtmlOutputBuffer push_mode & flush methods. --- lib/org-ruby/html_output_buffer.rb | 195 ++++++++++++++--------- lib/org-ruby/output_buffer.rb | 19 ++- spec/org-ruby/html_output_buffer_spec.rb | 121 ++++++++++++++ spec/org-ruby/output_buffer_spec.rb | 10 ++ 4 files changed, 263 insertions(+), 82 deletions(-) create mode 100644 spec/org-ruby/html_output_buffer_spec.rb create mode 100644 spec/org-ruby/output_buffer_spec.rb diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index a3f9724..74b9d7a 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -1,7 +1,7 @@ -module Orgmode +require_relative './highlighter.rb' +module Orgmode class HtmlOutputBuffer < OutputBuffer - require_relative './highlighter.rb' HtmlBlockTag = { :paragraph => "p", :ordered_list => "ol", @@ -30,119 +30,118 @@ class HtmlOutputBuffer < OutputBuffer def initialize(output, opts = {}) super(output) - @buffer_tag = "HTML" @options = opts @new_paragraph = :start @footnotes = {} @unclosed_tags = [] - @logger.debug "HTML export options: #{@options.inspect}" @custom_blocktags = {} if @options[:markup_file] - if @options[:markup_file] - do_custom_markup - end + do_custom_markup if @options[:markup_file] + end + + def buffer_tag + 'HTML' end # Output buffer is entering a new mode. Use this opportunity to # write out one of the block tags in the HtmlBlockTag constant to # put this information in the HTML stream. def push_mode(mode, indent, properties={}) - @logger.debug "Properties: #{properties}" super(mode, indent, properties) - if HtmlBlockTag[mode] - unless ((mode_is_table?(mode) and skip_tables?) or - (mode == :src and !@options[:skip_syntax_highlight])) - css_class = case - when (mode == :src and @block_lang.empty?) - " class=\"src\"" - when (mode == :src and not @block_lang.empty?) - " class=\"src\" lang=\"#{@block_lang}\"" - when (mode == :example || mode == :inline_example) - " class=\"example\"" - when mode == :center - " style=\"text-align: center\"" - when @options[:decorate_title] - " class=\"title\"" - end - add_paragraph unless @new_paragraph == :start - @new_paragraph = true - - @logger.debug "#{mode}: <#{HtmlBlockTag[mode]}#{css_class}>" - # Check to see if we need to restart numbering from a - # previous interrupted li - if mode_is_ol?(mode) && properties.key?(HtmlBlockTag[:list_item]) - @output << "<#{HtmlBlockTag[mode]} start=#{properties[HtmlBlockTag[:list_item]]}#{css_class}>" - else - @output << "<#{HtmlBlockTag[mode]}#{css_class}>" - end - # Entering a new mode obliterates the title decoration - @options[:decorate_title] = nil - end + return unless html_tags.include?(mode) + return if skip_css?(mode) + css_class = get_css_attr(mode) + push_indentation(@new_paragraph != :start) + + html_tag = HtmlBlockTag[mode] + # Check to see if we need to restart numbering from a + # previous interrupted li + if restart_numbering?(mode, properties) + list_item_tag = HtmlBlockTag[:list_item] + start = properties[list_item_tag] + @output << "<#{html_tag} start=#{start}#{css_class}>" + else + @output << "<#{html_tag}#{css_class}>" end + # Entering a new mode obliterates the title decoration + @options[:decorate_title] = nil + end + + def restart_numbering?(mode, properties) + mode_is_ol?(mode) && properties.key?(HtmlBlockTag[:list_item]) + end + + def table?(mode) + %i[table table_row table_separator table_header].include?(mode) + end + + def src?(mode) + %i[src].include?(mode) + end + + def skip_syntax_highlight? + !options[:skip_syntax_highlight] + end + + def push_indentation(condition) + indent = " " * indentation_level + condition && @output.concat("\n", indent) + @new_paragraph = true + end + + def html_tags + HtmlBlockTag.keys + end + + def skip_css?(mode) + (table?(mode) && skip_tables?) || + (src?(mode) && skip_syntax_highlight?) end # We are leaving a mode. Close any tags that were opened when # entering this mode. def pop_mode(mode = nil) m = super(mode) - if HtmlBlockTag[m] - unless ((mode_is_table?(m) and skip_tables?) or - (m == :src and !@options[:skip_syntax_highlight])) - add_paragraph if @new_paragraph - @new_paragraph = true - @logger.debug "" - @output << "" - end - end + return @list_indent_stack.pop unless html_tags.include?(m) + return @list_indent_stack.pop if skip_css?(m) + push_indentation @new_paragraph + @output.concat("") @list_indent_stack.pop end def highlight(code, lang) - Highlighter.highlight code, lang + Highlighter.highlight(code, lang) end def flush! return false if @buffer.empty? - case - when preserve_whitespace? + return @buffer = "" if (mode_is_table?(current_mode) && skip_tables?) + + if preserve_whitespace? strip_code_block! if mode_is_code? current_mode - # NOTE: CodeRay and Pygments already escape the html once, so - # no need to escapeHTML - case - when (current_mode == :src and @options[:skip_syntax_highlight]) - @buffer = escapeHTML @buffer - when (current_mode == :src) - lang = normalize_lang @block_lang - @buffer = highlight @buffer, lang - when (current_mode == :html or current_mode == :raw_text) - @buffer.gsub!(/\A\n/, "") if @new_paragraph == :start - @new_paragraph = true + if (current_mode == :src) + highlight_html_buffer else - # *NOTE* Don't use escape_string! through its sensitivity to @@html:@@ forms - @buffer = escapeHTML @buffer + if (current_mode == :html || current_mode == :raw_text) + remove_new_lines_in_buffer(@new_paragraph == :start) + else + @buffer = escapeHTML @buffer + end end # Whitespace is significant in :code mode. Always output the # buffer and do not do any additional translation. - @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}" @output << @buffer - - when (mode_is_table? current_mode and skip_tables?) - @logger.debug "SKIP ==========> #{current_mode}" - else @buffer.lstrip! @new_paragraph = nil - @logger.debug "FLUSH ==========> #{current_mode}" - - case current_mode - when :definition_term + if (current_mode == :definition_term) d = @buffer.split(/\A(.*[ \t]+|)::(|[ \t]+.*?)$/, 4) - d[1] = d[1].strip - unless d[1].empty? - @output << inline_formatting(d[1]) - else + definition = d[1].strip + if definition.empty? @output << "???" + else + @output << inline_formatting(definition) end indent = @list_indent_stack.last pop_mode @@ -151,8 +150,8 @@ def flush! push_mode(:definition_descr, indent) @output << inline_formatting(d[2].strip + d[3]) @new_paragraph = nil + elsif (current_mode == :horizontal_rule) - when :horizontal_rule add_paragraph unless @new_paragraph == :start @new_paragraph = true @output << "
" @@ -164,13 +163,36 @@ def flush! @buffer = "" end + # Flush! helping methods + def highlight_html_buffer + if skip_syntax_hightlight? + @buffer = escapeHTML @buffer + else + lang = normalize_lang @block_lang + @buffer = highlight(@buffer, lang) + end + end + + def skip_syntax_hightlight? + current_mode == :src && options[:skip_syntax_highlight] + end + + def remove_new_lines_in_buffer(condition) + return unless %i[html raw_text].include?(current_mode) + + condition && @buffer.gsub!(/\A\n/, "") + @new_paragraph = true + end + #flush helpers ends here. + + def add_line_attributes headline - if @options[:export_heading_number] then + if @options[:export_heading_number] level = headline.level heading_number = get_next_headline_number(level) @output << "#{heading_number} " end - if @options[:export_todo] and headline.keyword then + if @options[:export_todo] and headline.keyword keyword = headline.keyword @output << "#{keyword} " end @@ -204,8 +226,23 @@ def preserve_whitespace? ###################################################################### private + def get_css_attr(mode) + case + when (mode == :src and block_lang.empty?) + " class=\"src\"" + when (mode == :src and not block_lang.empty?) + " class=\"src\" lang=\"#{block_lang}\"" + when (mode == :example || mode == :inline_example) + " class=\"example\"" + when mode == :center + " style=\"text-align: center\"" + when @options[:decorate_title] + " class=\"title\"" + end + end + def skip_tables? - @options[:skip_tables] + options[:skip_tables] end def mode_is_table?(mode) diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index 90a0aae..c58e577 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -46,7 +46,6 @@ def current_mode @mode_stack.last end - def push_mode(mode, indent, properties={}) @mode_stack.push(mode) @list_indent_stack.push(indent) @@ -77,7 +76,8 @@ def insert(line) when line.title? @buffer << line.output_text when line.raw_text? - @buffer << "\n" << line.output_text if line.raw_text_tag == @buffer_tag + # This case is for html buffer, because buffer_tag is a method + @buffer << "\n" << line.output_text if line.raw_text_tag == buffer_tag when preserve_whitespace? @buffer << "\n" << line.output_text unless line.block_type when line.assigned_paragraph_type == :code @@ -172,7 +172,20 @@ def no_custom_markup_file_exists @logger.debug "Continuing export with default tags." end - ###################################################################### + protected + + attr_reader :block_lang, :list_indent_stack + + def indentation_level + list_indent_stack.length - 1 + end + + # Implemented only in HtmlOutputBuffer + def buffer_tag + # raise NoImplementedError 'implemnt this in your output buffer' + nil + end + private def mode_is_heading?(mode) diff --git a/spec/org-ruby/html_output_buffer_spec.rb b/spec/org-ruby/html_output_buffer_spec.rb new file mode 100644 index 0000000..445d142 --- /dev/null +++ b/spec/org-ruby/html_output_buffer_spec.rb @@ -0,0 +1,121 @@ +# coding: utf-8 +require 'spec_helper' +require_relative '../../lib/org-ruby/html_output_buffer' + +module Orgmode + RSpec.describe HtmlOutputBuffer do + let(:output) { "Buffer" } + let(:buffer) { Orgmode::HtmlOutputBuffer.new(output) } + + describe '.new' do + it 'has an output buffer' do + expect(buffer).not_to be_nil + expect(buffer.output).to eq output + end + + it 'has HTML buffer_tag' do + expect(buffer.buffer_tag).to eq 'HTML' + end + + context 'when call with options' do + let(:options) { { option: 'value'} } + let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, options)} + it 'has options' do + expect(buffer.options).to eq options + end + end + end + + describe '#push_mode' do + xit 'calls super method' + context 'when mode is a HtmlBlockTag' do + let(:mode) { :paragraph } + let(:indent) { :some_value } + let(:properties) { Hash.new } + + it 'push HtmlBlock to the output buffer' do + buffer.push_mode(mode, indent, properties) + expect(buffer.output).to eq 'Buffer

' + end + + context 'when mode is example' do + let(:mode) { :example } + it 'sets class attributes to example' do + buffer.push_mode(mode, indent) + expect(buffer.output).to eq 'Buffer

'
+          end
+        end
+
+        context 'when mode is inline_example' do
+          let(:mode) { :inline_example }
+          it 'sets class attributes to example' do
+            buffer.push_mode(mode, indent)
+            expect(buffer.output).to eq 'Buffer
'
+          end
+        end
+
+        context 'when mode is center' do
+          let(:mode) { :center }
+          it 'sets style attribute to text-align: center' do
+            buffer.push_mode(mode, indent)
+            expect(buffer.output).to eq 'Buffer
' + end + end + + context 'when mode is src' do + let(:mode) { :src } + + context 'when Buffer options include skip_syntax_highligth = false' do + xit 'do not touch output buffer ' + end + + context 'when Buffer options include skip_syntax_highlight = true' do + let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, { skip_syntax_highlight: true })} + before(:each) do + allow(buffer).to receive(:block_lang).and_return('') + end + + it 'sets class attributes' do + buffer.push_mode(mode, indent) + expect(buffer.output).to eq 'Buffer
'
+            end
+
+            context 'when Buffer block_lang is not empty' do
+              let(:block_lang) { 'elisp' }
+
+              before(:each) do
+                allow(buffer).to receive(:block_lang).and_return(block_lang)
+              end
+
+              it 'set lang attribute' do
+                buffer.push_mode(mode, indent, properties)
+                expect(buffer.output).to eq 'Buffer
'
+              end
+            end
+          end
+        end
+
+        xcontext 'when tag is table' do
+        end
+
+        xit 'add new line and indentation when runs for first time' do
+          buffer.push_mode(mode, indent)
+          expect(buffer.output).to match /\Z/
+        end
+
+        context 'when called for second time' do
+          before(:each) do
+            buffer.push_mode(mode, indent)
+          end
+
+          it 'does not add paragprah' do
+            mode = :src
+            buffer.push_mode(mode, 'indent')
+            expect(buffer.output).not_to match /\Z\n/
+          end
+        end
+
+      end
+    end
+  end
+end
diff --git a/spec/org-ruby/output_buffer_spec.rb b/spec/org-ruby/output_buffer_spec.rb
new file mode 100644
index 0000000..6dcafe1
--- /dev/null
+++ b/spec/org-ruby/output_buffer_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+require_relative '../../lib/org-ruby/output_buffer'
+module Orgmode
+  RSpec.describe OutputBuffer do
+    describe '.new' do
+
+    end
+  end
+end

From 4c5bffbf40c4712faba8b19972e52a186e846643 Mon Sep 17 00:00:00 2001
From: Ricardo Arredondo 
Date: Wed, 31 Mar 2021 15:47:46 -0600
Subject: [PATCH 04/12] Refactor OutputBuffer buffer.

---
 lib/org-ruby/html_output_buffer.rb | 15 +++---
 lib/org-ruby/output_buffer.rb      | 79 +++++++++++++++++++-----------
 2 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 74b9d7a..021abfc 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -103,7 +103,7 @@ def pop_mode(mode = nil)
       m = super(mode)
       return @list_indent_stack.pop unless html_tags.include?(m)
       return @list_indent_stack.pop if skip_css?(m)
-      push_indentation  @new_paragraph
+      push_indentation(@new_paragraph)
       @output.concat("")
       @list_indent_stack.pop
     end
@@ -137,6 +137,7 @@ def flush!
         @new_paragraph = nil
         if (current_mode == :definition_term)
           d = @buffer.split(/\A(.*[ \t]+|)::(|[ \t]+.*?)$/, 4)
+
           definition = d[1].strip
           if definition.empty?
             @output << "???"
@@ -148,7 +149,7 @@ def flush!
 
           @new_paragraph = :start
           push_mode(:definition_descr, indent)
-          @output << inline_formatting(d[2].strip + d[3])
+          @output.concat inline_formatting(d[2].strip + d[3])
           @new_paragraph = nil
         elsif (current_mode == :horizontal_rule)
 
@@ -273,8 +274,7 @@ def quote_tags str
     end
 
     def buffer_indentation
-      indent = "  " * @list_indent_stack.length
-      @buffer << indent
+       "  " * @list_indent_stack.length
     end
 
     def add_paragraph
@@ -294,9 +294,10 @@ def add_paragraph
 
     # Applies inline formatting rules to a string.
     def inline_formatting(str)
-      @re_help.rewrite_emphasis str do |marker, s|
-        if marker == "=" or marker == "~"
-          s = escapeHTML s
+      @re_help.rewrite_emphasis(str) do |marker, s|
+
+        if marker == "=" || marker == "~"
+          s = escapeHTML(s)
           "<#{Tags[marker][:open]}>#{s}"
         else
           quote_tags("<#{Tags[marker][:open]}>") + s +
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index c58e577..98bc3ca 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -9,10 +9,10 @@ module Orgmode
   class OutputBuffer
 
     # This is the overall output buffer
-    attr_reader :output
+    attr_reader :output, :mode_stack
 
     # This is the current type of output being accumulated.
-    attr_accessor :output_type
+    attr_accessor :output_type, :headline_number_stack
 
     # Creates a new OutputBuffer object that is bound to an output object.
     # The output will get flushed to =output=.
@@ -30,31 +30,31 @@ def initialize(output)
       @output_type = :start
       @list_indent_stack = []
       @mode_stack = []
-      @code_block_indent = nil
 
+      # html_buffer
+      @code_block_indent = nil
+      # regexp module
+      @re_help = RegexpHelper.new
       @logger = Logger.new(STDERR)
-      if ENV['DEBUG'] or $DEBUG
+      if ENV['DEBUG'] || $DEBUG
         @logger.level = Logger::DEBUG
       else
         @logger.level = Logger::WARN
       end
-
-      @re_help = RegexpHelper.new
     end
 
     def current_mode
-      @mode_stack.last
+      mode_stack.last
     end
 
     def push_mode(mode, indent, properties={})
-      @mode_stack.push(mode)
-      @list_indent_stack.push(indent)
+      mode_stack.push(mode)
+      # Here seem that inherit buffers do their magic.
+      list_indent_stack.push(indent)
     end
 
-    def pop_mode(mode = nil)
-      m = @mode_stack.pop
-      @logger.warn "Modes don't match. Expected to pop #{mode}, but popped #{m}" if mode && mode != m
-      m
+    def pop_mode(mode=nil)
+      mode_stack.pop
     end
 
     def insert(line)
@@ -69,33 +69,54 @@ def insert(line)
         maintain_mode_stack(line)
       end
 
+      @buffer.concat(line_get_content(line))
+      html_buffer_code_block_indent(line)
+      @output_type = line.assigned_paragraph_type || line.paragraph_type
+    end
+
+    # Insert line Helpers
+    # This is a line method
+    def line_get_content(line)
       # Adds the current line to the output buffer
       case
       when line.assigned_paragraph_type == :comment
         # Don't add to buffer
+        return ""
       when line.title?
-        @buffer << line.output_text
+        return line.output_text
       when line.raw_text?
         # This case is for html buffer, because buffer_tag is a method
-        @buffer << "\n" << line.output_text if line.raw_text_tag == buffer_tag
+        if line.raw_text_tag == buffer_tag
+          return "\n#{line.output_text}"
+        else
+          return ""
+        end
       when preserve_whitespace?
-        @buffer << "\n" << line.output_text unless line.block_type
+        if line.block_type
+          return ""
+        else
+          return "\n#{line.output_text}"
+        end
       when line.assigned_paragraph_type == :code
         # If the line is contained within a code block but we should
         # not preserve whitespaces, then we do nothing.
+        return ""
       when (line.kind_of? Headline)
-        add_line_attributes line
-        @buffer << "\n" << line.output_text.strip
+        add_line_attributes(line)
+        return "\n#{line.output_text.strip}"
+
       when ([:definition_term, :list_item, :table_row, :table_header,
              :horizontal_rule].include? line.paragraph_type)
-        @buffer << "\n" << line.output_text.strip
+
+        return "\n#{line.output_text.strip}"
       when line.paragraph_type == :paragraph
-        @buffer << "\n"
-        buffer_indentation
-        @buffer << line.output_text.strip
+        return "\n""#{buffer_indentation}#{line.output_text.strip}"
+      else ""
       end
+    end
 
-      if mode_is_code? current_mode and not line.block_type
+    def html_buffer_code_block_indent(line)
+      if mode_is_code?(current_mode) && !(line.block_type)
         # Determines the amount of whitespaces to be stripped at the
         # beginning of each line in code block.
         if line.paragraph_type != :blank
@@ -106,23 +127,22 @@ def insert(line)
           end
         end
       end
-
-      @output_type = line.assigned_paragraph_type || line.paragraph_type
     end
+    # Insert helpers end here.
 
     # Gets the next headline number for a given level. The intent is
     # this function is called sequentially for each headline that
     # needs to get numbered. It does standard outline numbering.
     def get_next_headline_number(level)
       raise "Headline level not valid: #{level}" if level <= 0
+
       while level > @headline_number_stack.length do
         @headline_number_stack.push 0
       end
       while level < @headline_number_stack.length do
         @headline_number_stack.pop
       end
-      raise "Oops, shouldn't happen" unless level == @headline_number_stack.length
-      @headline_number_stack[@headline_number_stack.length - 1] += 1
+      @headline_number_stack[level - 1] += 1
       @headline_number_stack.join(".")
     end
 
@@ -301,7 +321,10 @@ def should_accumulate_output? line
       false
     end
 
-    def buffer_indentation; false; end
+    def buffer_indentation
+      ""
+    end
+
     def flush!; false; end
     def output_footnotes!; false; end
   end                           # class OutputBuffer

From 1f72e6b3748748e565707b71f1ff028aef22e8d7 Mon Sep 17 00:00:00 2001
From: Ricardo Arredondo 
Date: Fri, 2 Apr 2021 19:20:23 -0600
Subject: [PATCH 05/12] Add footnotes_title as a parser option (Fix #2).

---
 lib/org-ruby/html_output_buffer.rb       |  72 +++++++++++----
 lib/org-ruby/output_buffer.rb            |  24 ++---
 lib/org-ruby/parser.rb                   |  23 ++---
 lib/org-ruby/regexp_helper.rb            |   2 +-
 spec/html_examples/footnotes_title.html  | 111 +++++++++++++++++++++++
 spec/org-ruby/html_output_buffer_spec.rb |   1 -
 spec/org-ruby/output_buffer_spec.rb      |  28 ++++++
 spec/parser_spec.rb                      |  14 ++-
 8 files changed, 229 insertions(+), 46 deletions(-)
 create mode 100644 spec/html_examples/footnotes_title.html

diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 021abfc..d76b746 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -34,8 +34,10 @@ def initialize(output, opts = {})
       @new_paragraph = :start
       @footnotes = {}
       @unclosed_tags = []
-      @custom_blocktags = {} if @options[:markup_file]
-      do_custom_markup if @options[:markup_file]
+      # move from output_buffer
+      @code_block_indent = nil
+
+      do_custom_markup
     end
 
     def buffer_tag
@@ -101,11 +103,11 @@ def skip_css?(mode)
     # entering this mode.
     def pop_mode(mode = nil)
       m = super(mode)
-      return @list_indent_stack.pop unless html_tags.include?(m)
-      return @list_indent_stack.pop if skip_css?(m)
+      return list_indent_stack.pop unless html_tags.include?(m)
+      return list_indent_stack.pop if skip_css?(m)
       push_indentation(@new_paragraph)
       @output.concat("")
-      @list_indent_stack.pop
+      list_indent_stack.pop
     end
 
     def highlight(code, lang)
@@ -144,7 +146,7 @@ def flush!
           else
             @output << inline_formatting(definition)
           end
-          indent = @list_indent_stack.last
+          indent = list_indent_stack.last
           pop_mode
 
           @new_paragraph = :start
@@ -199,13 +201,15 @@ def add_line_attributes headline
       end
     end
 
+    # Only footnotes defined in the footnote (i.e., [fn:0:this is the footnote definition])
+    # will be automatically
+    # added to a separate Footnotes section at the end of the document. All footnotes that are
+    # defined separately from their references will be rendered where they appear in the original
+    # Org document.
     def output_footnotes!
-      # Only footnotes defined in the footnote (i.e., [fn:0:this is the footnote definition]) will be automatically
-      # added to a separate Footnotes section at the end of the document. All footnotes that are defined separately
-      # from their references will be rendered where they appear in the original Org document.
-      return false unless @options[:export_footnotes] and not @footnotes.empty?
+      return false if !options[:export_footnotes] || @footnotes.empty?
+      @output.concat footnotes_header
 
-      @output << "\n
\n

Footnotes:

\n
\n" @footnotes.each do |name, (defi, content)| @buffer = defi @output << "
#{name}" \ @@ -219,11 +223,40 @@ def output_footnotes! return true end + def footnotes_header + footnotes_title = options[:footnotes_title] || "Footnotes:" + "\n
\n

#{footnotes_title}

\n
\n" + end + # Test if we're in an output mode in which whitespace is significant. def preserve_whitespace? - super or current_mode == :html + super || current_mode == :html + end + + protected + + def do_custom_markup + file = options[:markup_file] + return unless file + return no_custom_markup_file_exists unless File.exists?(file) + + @custom_blocktags = load_custom_markup(file) + @custom_blocktags.empty? && no_valid_markup_found || + set_custom_markup end + def load_custom_markup(file) + require 'yaml' + if (self.class.to_s == 'Orgmode::MarkdownOutputBuffer') + filter = '^MarkdownMap$' + else + filter = '^HtmlBlockTag$|^Tags$' + end + @custom_blocktags = YAML.load_file(@options[:markup_file]).select {|k| k.to_s.match(filter) } + end + + + ###################################################################### private @@ -274,12 +307,12 @@ def quote_tags str end def buffer_indentation - " " * @list_indent_stack.length + " " * list_indent_stack.length end def add_paragraph - indent = " " * (@list_indent_stack.length - 1) - @output << "\n" << indent + indent = " " * (list_indent_stack.length - 1) + @output.concat "\n#{indent}" end Tags = { @@ -294,13 +327,12 @@ def add_paragraph # Applies inline formatting rules to a string. def inline_formatting(str) - @re_help.rewrite_emphasis(str) do |marker, s| - + @re_help.rewrite_emphasis(str) do |marker, text| if marker == "=" || marker == "~" - s = escapeHTML(s) - "<#{Tags[marker][:open]}>#{s}" + escaped_text = escapeHTML(text) + "<#{Tags[marker][:open]}>#{escaped_text}" else - quote_tags("<#{Tags[marker][:open]}>") + s + + quote_tags("<#{Tags[marker][:open]}>") + text + quote_tags("") end end diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index 98bc3ca..f5b621c 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -9,7 +9,7 @@ module Orgmode class OutputBuffer # This is the overall output buffer - attr_reader :output, :mode_stack + attr_reader :output, :mode_stack, :list_indent_stack # This is the current type of output being accumulated. attr_accessor :output_type, :headline_number_stack @@ -81,36 +81,36 @@ def line_get_content(line) case when line.assigned_paragraph_type == :comment # Don't add to buffer - return "" + "" when line.title? - return line.output_text + line.output_text when line.raw_text? # This case is for html buffer, because buffer_tag is a method if line.raw_text_tag == buffer_tag - return "\n#{line.output_text}" + "\n#{line.output_text}" else - return "" + "" end when preserve_whitespace? if line.block_type - return "" + "" else - return "\n#{line.output_text}" + "\n#{line.output_text}" end when line.assigned_paragraph_type == :code # If the line is contained within a code block but we should # not preserve whitespaces, then we do nothing. - return "" - when (line.kind_of? Headline) + "" + when line.is_a?(Headline) add_line_attributes(line) - return "\n#{line.output_text.strip}" + "\n#{line.output_text.strip}" when ([:definition_term, :list_item, :table_row, :table_header, :horizontal_rule].include? line.paragraph_type) - return "\n#{line.output_text.strip}" + "\n#{line.output_text.strip}" when line.paragraph_type == :paragraph - return "\n""#{buffer_indentation}#{line.output_text.strip}" + "\n""#{buffer_indentation}#{line.output_text.strip}" else "" end end diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index c9d2624..40e198a 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -100,7 +100,7 @@ def initialize(lines, parser_options={ }) @parser_options = parser_options # - # Include file feature disabled by default since + # Include file feature disabled by default since # it would be dangerous in some environments # # http://orgmode.org/manual/Include-files.html @@ -339,14 +339,15 @@ def to_markdown def to_html mark_trees_for_export export_options = { - :decorate_title => @in_buffer_settings["TITLE"], - :export_heading_number => export_heading_number?, - :export_todo => export_todo?, - :use_sub_superscripts => use_sub_superscripts?, - :export_footnotes => export_footnotes?, - :link_abbrevs => @link_abbrevs, - :skip_syntax_highlight => @parser_options[:skip_syntax_highlight], - :markup_file => @parser_options[:markup_file] + decorate_title: in_buffer_settings['TITLE'], + export_heading_number: export_heading_number?, + export_todo: export_todo?, + use_sub_superscripts: use_sub_superscripts?, + export_footnotes: export_footnotes?, + link_abbrevs: @link_abbrevs, + skip_syntax_highlight: @parser_options[:skip_syntax_highlight], + markup_file: @parser_options[:markup_file], + footnotes_title: @parser_options[:footnotes_title] } export_options[:skip_tables] = true if not export_tables? output = "" @@ -377,8 +378,8 @@ def to_html output << "\n" return output if @parser_options[:skip_rubypants_pass] - - rp = RubyPants.new(output) + + rp = RubyPants.new(output) rp.to_html end diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb index 9606338..7e79317 100644 --- a/lib/org-ruby/regexp_helper.rb +++ b/lib/org-ruby/regexp_helper.rb @@ -91,7 +91,7 @@ def match_all(str) # replace "*bold*", "/italic/", and "=code=", # respectively. (Clearly this sample string will use HTML-like # syntax, assuming +map+ is defined appropriately.) - def rewrite_emphasis str + def rewrite_emphasis(str) # escape the percent signs for safe restoring code snippets str.gsub!(/%/, "%%") format_str = "%s" diff --git a/spec/html_examples/footnotes_title.html b/spec/html_examples/footnotes_title.html new file mode 100644 index 0000000..bd563b7 --- /dev/null +++ b/spec/html_examples/footnotes_title.html @@ -0,0 +1,111 @@ +

Footnotes

+

Using letters and not defined in the footnote abc

+

Defined in the footnote itself with markup 0

+

Some example paragraph 1, with text at the end.

+

Some example paragraph 2, with text at the end.

+

Some example paragraph 3, with text at the end.

+

Some example paragraph 4, with text at the end.

+

Some example paragraph 5, with text at the end.

+

Some example paragraph 6, with text at the end.

+

Some example paragraph 7, with text at the end.

+

Some example paragraph 8, with text at the end.

+

Some example paragraph 9, with text at the end.

+

Some example paragraph 10, with text at the end.

+

Some example paragraph 11, with text at the end.

+

Some example paragraph 12, with text at the end.

+

Some example paragraph 13, with text at the end.

+

Some example paragraph 14, with text at the end.

+

Some example paragraph 15, with text at the end.

+

Some example paragraph 16, with text at the end.

+

Some example paragraph 17, with text at the end.

+

Some example paragraph 18, with text at the end.

+

Some example paragraph 19, with text at the end.

+

Some example paragraph 20, with text at the end.

+

Some example paragraph 21, with text at the end.

+

Some example paragraph 22, with text at the end.

+

Some example paragraph 23, with text at the end.

+

Some example paragraph 24, with text at the end.

+

Some example paragraph 25, with text at the end.

+

Some example paragraph 26, with text at the end.

+

Some example paragraph 27, with text at the end.

+

Some example paragraph 28, with text at the end.

+

Some example paragraph 29, with text at the end.

+

Some example paragraph 30, with text at the end.

+

Some example paragraph 31, with text at the end.

+

Some example paragraph 32, with text at the end.

+

Some example paragraph 33, with text at the end.

+

Some example paragraph 34, with text at the end.

+

Some example paragraph 35, with text at the end.

+

Some example paragraph 36, with text at the end.

+

Some example paragraph 37, with text at the end.

+

Some example paragraph 38, with text at the end.

+

Some example paragraph 39, with text at the end.

+

Some example paragraph 40, with text at the end.

+

Some example paragraph 41, with text at the end.

+

Some example paragraph 42, with text at the end.

+

Some example paragraph 43, with text at the end.

+

Some example paragraph 44, with text at the end.

+

Some example paragraph 45, with text at the end.

+

Some example paragraph 46, with text at the end.

+

Some example paragraph 47, with text at the end.

+

Some example paragraph 48, with text at the end.

+

Some example paragraph 49, with text at the end.

+

Some example paragraph 50, with text at the end.

+

1 And some example footnote

+

2 And some example footnote

+

3 And some example footnote

+

4 And some example footnote

+

5 And some example footnote

+

6 And some example footnote

+

7 And some example footnote

+

8 And some example footnote

+

9 And some example footnote

+

10 And some example footnote

+

11 And some example footnote

+

12 And some example footnote

+

13 And some example footnote

+

14 And some example footnote

+

15 And some example footnote

+

16 And some example footnote

+

17 And some example footnote

+

18 And some example footnote

+

19 And some example footnote

+

20 And some example footnote

+

21 And some example footnote

+

22 And some example footnote

+

23 And some example footnote

+

24 And some example footnote

+

25 And some example footnote

+

26 And some example footnote

+

27 And some example footnote

+

28 And some example footnote

+

29 And some example footnote

+

30 And some example footnote

+

31 And some example footnote

+

32 And some example footnote

+

33 And some example footnote

+

34 And some example footnote

+

35 And some example footnote

+

36 And some example footnote

+

37 And some example footnote

+

38 And some example footnote

+

39 And some example footnote

+

40 And some example footnote

+

41 And some example footnote

+

42 And some example footnote

+

43 And some example footnote

+

44 And some example footnote

+

45 And some example footnote

+

46 And some example footnote

+

47 And some example footnote

+

48 And some example footnote

+

49 And some example footnote

+

50 And some example footnote

+

Using letters and defined in the footnote abc

+
+

Footnotes Title

+
+
0

blub

+
abc

definition of abc

+
+
diff --git a/spec/org-ruby/html_output_buffer_spec.rb b/spec/org-ruby/html_output_buffer_spec.rb index 445d142..88866d2 100644 --- a/spec/org-ruby/html_output_buffer_spec.rb +++ b/spec/org-ruby/html_output_buffer_spec.rb @@ -1,4 +1,3 @@ -# coding: utf-8 require 'spec_helper' require_relative '../../lib/org-ruby/html_output_buffer' diff --git a/spec/org-ruby/output_buffer_spec.rb b/spec/org-ruby/output_buffer_spec.rb index 6dcafe1..ea81f29 100644 --- a/spec/org-ruby/output_buffer_spec.rb +++ b/spec/org-ruby/output_buffer_spec.rb @@ -3,8 +3,36 @@ require_relative '../../lib/org-ruby/output_buffer' module Orgmode RSpec.describe OutputBuffer do + let(:output) { 'Output' } + let(:buffer) { Orgmode::OutputBuffer.new(output) } + describe '.new' do + it 'receives and has an output' do + expect(buffer.output).to eq output + end + end + + describe 'get_next_headline_number' do + let(:level) { 1 } + context 'when @headline_number_stack is empty' do + it 'returns 1' do + headline_number = buffer.get_next_headline_number(level) + expect(headline_number).to eq '1' + end + end + + context 'when @headline_number_stack has numbers' do + let(:level) { 2 } + before(:each) do + buffer.headline_number_stack.push(4) + buffer.headline_number_stack.push(2) + end + it 'returns 4.3' do + headline_number = buffer.get_next_headline_number(level) + expect(headline_number).to eq '4.3' + end + end end end end diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 55aeb20..af2207e 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -329,6 +329,19 @@ end end + describe "Footnotes title" do + base_dir = File.join(File.dirname(__FILE__), "html_examples") + org_file = File.join(base_dir, "footnotes.org") + html_file = File.join(base_dir, "footnotes_title.html") + it 'accept footnotes_title option' do + expected = IO.read(html_file) + parser = Orgmode::Parser.new(IO.read(org_file), :footnotes_title => "Footnotes Title") + actual = parser.to_html + expect(actual).to be_kind_of(String) + expect(actual).to eq(expected) + end + end + describe "Export to Markdown test cases" do data_directory = File.join(File.dirname(__FILE__), "markdown_examples") org_files = File.expand_path(File.join(data_directory, "*.org" )) @@ -489,4 +502,3 @@ end end end - From bbd794a224d6084b688a5a4cf73bb08e97efe323 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Wed, 7 Apr 2021 19:52:51 -0500 Subject: [PATCH 06/12] Adjust headlines number when title is present (Fix #88). --- lib/org-ruby/headline.rb | 10 +- lib/org-ruby/html_output_buffer.rb | 21 ++- lib/org-ruby/output_buffer.rb | 18 +-- lib/org-ruby/parser.rb | 129 ++++++++++-------- .../advanced-code-coderay.html | 28 ++-- .../advanced-code-no-color.html | 6 +- .../advanced-code-pygments.html | 34 ++--- .../code-block-exports-coderay.html | 12 +- .../code-block-exports-no-color.html | 24 ++-- .../code-block-exports-pygments.html | 12 +- spec/html_examples/custom-seq-todo.html | 16 +-- spec/html_examples/custom-todo.html | 16 +-- spec/html_examples/custom-typ-todo.html | 16 +-- spec/html_examples/deflist.html | 12 +- spec/html_examples/entities.html | 6 +- spec/html_examples/export-exclude-only.html | 12 +- spec/html_examples/export-keywords.html | 4 +- spec/html_examples/export-tags.html | 8 +- spec/html_examples/include-file-disabled.html | 18 +-- spec/html_examples/include-file.html | 26 ++-- spec/html_examples/link-features.html | 10 +- spec/html_examples/options-parsing.html | 2 +- spec/html_examples/skip-header.html | 2 +- spec/markdown_examples/custom-seq-todo.md | 16 +-- spec/markdown_examples/custom-todo.md | 16 +-- spec/markdown_examples/custom-typ-todo.md | 16 +-- spec/markdown_examples/deflist.md | 10 +- spec/markdown_examples/entities.md | 6 +- spec/markdown_examples/export-exclude-only.md | 12 +- spec/markdown_examples/export-keywords.md | 4 +- spec/markdown_examples/export-tags.md | 8 +- spec/markdown_examples/footnotes.md | 2 +- spec/markdown_examples/include-file.md | 18 +-- spec/markdown_examples/link-features.md | 10 +- spec/markdown_examples/skip-header.md | 2 +- spec/textile_examples/footnotes.textile | 2 +- 36 files changed, 293 insertions(+), 271 deletions(-) diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb index c4761b6..6152063 100644 --- a/lib/org-ruby/headline.rb +++ b/lib/org-ruby/headline.rb @@ -45,14 +45,15 @@ class Headline < Line # This matches a headline marked as COMMENT CommentHeadlineRegexp = /^COMMENT\s+/ - def initialize(line, parser = nil, offset=0) + def initialize(line, parser = nil, offset = 0) super(line, parser) @body_lines = [] @tags = [] @export_state = :exclude @property_drawer = { } if (@line =~ LineRegexp) then - @level = $&.strip.length + offset + new_offset = (parser && parser.title?) ? offset + 1 : offset + @level = $&.strip.length + new_offset @headline_text = $'.strip if (@headline_text =~ TagsRegexp) then @tags = $&.split(/:/) # split tag text on semicolon @@ -88,6 +89,11 @@ def paragraph_type :"heading#{@level}" end + def headline_level + title_offset = (parser && parser.title?) ? 1 : 0 + level - title_offset + end + ###################################################################### private diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index d76b746..72cd034 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -34,6 +34,7 @@ def initialize(output, opts = {}) @new_paragraph = :start @footnotes = {} @unclosed_tags = [] + # move from output_buffer @code_block_indent = nil @@ -189,10 +190,11 @@ def remove_new_lines_in_buffer(condition) #flush helpers ends here. - def add_line_attributes headline + def add_line_attributes(headline) if @options[:export_heading_number] level = headline.level - heading_number = get_next_headline_number(level) + headline_level = headline.headline_level + heading_number = get_next_headline_number(headline_level) @output << "#{heading_number} " end if @options[:export_todo] and headline.keyword @@ -201,6 +203,21 @@ def add_line_attributes headline end end + def html_buffer_code_block_indent(line) + if mode_is_code?(current_mode) && !(line.block_type) + # Determines the amount of whitespaces to be stripped at the + # beginning of each line in code block. + if line.paragraph_type != :blank + if @code_block_indent + @code_block_indent = [@code_block_indent, line.indent].min + else + @code_block_indent = line.indent + end + end + end + end + + # Only footnotes defined in the footnote (i.e., [fn:0:this is the footnote definition]) # will be automatically # added to a separate Footnotes section at the end of the document. All footnotes that are diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index f5b621c..d26b286 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -31,8 +31,6 @@ def initialize(output) @list_indent_stack = [] @mode_stack = [] - # html_buffer - @code_block_indent = nil # regexp module @re_help = RegexpHelper.new @logger = Logger.new(STDERR) @@ -73,8 +71,8 @@ def insert(line) html_buffer_code_block_indent(line) @output_type = line.assigned_paragraph_type || line.paragraph_type end - # Insert line Helpers + # This is a line method def line_get_content(line) # Adds the current line to the output buffer @@ -116,17 +114,7 @@ def line_get_content(line) end def html_buffer_code_block_indent(line) - if mode_is_code?(current_mode) && !(line.block_type) - # Determines the amount of whitespaces to be stripped at the - # beginning of each line in code block. - if line.paragraph_type != :blank - if @code_block_indent - @code_block_indent = [@code_block_indent, line.indent].min - else - @code_block_indent = line.indent - end - end - end + # this is implemented in html output buffer only end # Insert helpers end here. @@ -277,7 +265,7 @@ def maintain_mode_stack(line) end end - def add_line_attributes headline + def add_line_attributes(headline) # Implemented by specific output buffers end diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index 40e198a..d90de05 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -88,15 +88,15 @@ def initialize_lines(lines) # I can construct a parser object either with an array of lines # or with a single string that I will split along \n boundaries. - def initialize(lines, parser_options={ }) + def initialize(lines, parser_options = {}) @lines = initialize_lines lines @custom_keywords = [] - @headlines = Array.new + @headlines = [] @current_headline = nil @header_lines = [] - @in_buffer_settings = { } - @options = { } - @link_abbrevs = { } + @in_buffer_settings = {} + @options = {} + @link_abbrevs = {} @parser_options = parser_options # @@ -116,8 +116,8 @@ def initialize(lines, parser_options={ }) # e.g. Orgmode::Parser.new(org_text, { :allow_include_files => false }) # if @parser_options[:allow_include_files].nil? - if ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] == 'true' \ - or not ENV['ORG_RUBY_INCLUDE_ROOT'].nil? + if (ENV['ORG_RUBY_ENABLE_INCLUDE_FILES'] == 'true') \ + || !ENV['ORG_RUBY_INCLUDE_ROOT'].nil? @parser_options[:allow_include_files] = true end end @@ -129,17 +129,15 @@ def initialize(lines, parser_options={ }) # Check include file availability and permissions def check_include_file(file_path) - can_be_included = File.exists? file_path + can_be_included = File.exist? file_path - if not ENV['ORG_RUBY_INCLUDE_ROOT'].nil? + unless ENV['ORG_RUBY_INCLUDE_ROOT'].nil? # Ensure we have full paths root_path = File.expand_path ENV['ORG_RUBY_INCLUDE_ROOT'] file_path = File.expand_path file_path # Check if file is in the defined root path and really exists - if file_path.slice(0, root_path.length) != root_path - can_be_included = false - end + can_be_included = false if file_path.slice(0, root_path.length) != root_path end can_be_included @@ -153,8 +151,9 @@ def parse_lines(lines) line = Line.new text, self if @parser_options[:allow_include_files] - if line.include_file? and not line.include_file_path.nil? - next if not check_include_file line.include_file_path + if line.include_file? && !line.include_file_path.nil? + next unless check_include_file line.include_file_path + include_data = get_include_data line include_lines = initialize_lines include_data parse_lines include_lines @@ -167,20 +166,20 @@ def parse_lines(lines) @link_abbrevs[link_abbrev_data[0]] = link_abbrev_data[1] end - mode = :normal if line.end_block? and [line.paragraph_type, :comment].include?(mode) - mode = :normal if line.property_drawer_end_block? and mode == :property_drawer + mode = :normal if line.end_block? && [line.paragraph_type, :comment].include?(mode) + mode = :normal if line.property_drawer_end_block? && (mode == :property_drawer) case mode when :normal, :quote, :center if Headline.headline? line.to_s line = Headline.new line.to_s, self, @parser_options[:offset] elsif line.table_separator? - if previous_line and previous_line.paragraph_type == :table_row and !table_header_set + if previous_line && (previous_line.paragraph_type == :table_row) && !table_header_set previous_line.assigned_paragraph_type = :table_header table_header_set = true end end - table_header_set = false if !line.table? + table_header_set = false unless line.table? when :example, :html, :src if previous_line @@ -211,15 +210,15 @@ def parse_lines(lines) # We treat the results code block differently since the exporting can be omitted if line.begin_block? - if line.results_block_should_be_exported? - @next_results_block_should_be_exported = true - else - @next_results_block_should_be_exported = false - end + @next_results_block_should_be_exported = if line.results_block_should_be_exported? + true + else + false + end end end - if mode == :property_drawer and @current_headline + if (mode == :property_drawer) && @current_headline @current_headline.property_drawer[line.property_drawer_item.first] = line.property_drawer_item.last end @@ -245,14 +244,14 @@ def get_include_data(line) # Get options include_file_lines = line.include_file_options[1].gsub('"', '').split('-') include_file_lines[0] = include_file_lines[0].empty? ? 1 : include_file_lines[0].to_i - include_file_lines[1] = include_file_lines[1].to_i if !include_file_lines[1].nil? + include_file_lines[1] = include_file_lines[1].to_i unless include_file_lines[1].nil? # Extract request lines. Note that the second index is excluded, according to the doc line_index = 1 include_data = [] - File.open(line.include_file_path, "r") do |fd| + File.open(line.include_file_path, 'r') do |fd| while line_data = fd.gets - if (line_index >= include_file_lines[0] and (include_file_lines[1].nil? or line_index < include_file_lines[1])) + if (line_index >= include_file_lines[0]) && (include_file_lines[1].nil? || (line_index < include_file_lines[1])) include_data << line_data.chomp end line_index += 1 @@ -261,14 +260,14 @@ def get_include_data(line) when 'src', 'example', 'quote' # Prepare tags - begin_tag = '#+BEGIN_%s' % [line.include_file_options[0].upcase] - if line.include_file_options[0] == 'src' and !line.include_file_options[1].nil? + begin_tag = format('#+BEGIN_%s', line.include_file_options[0].upcase) + if (line.include_file_options[0] == 'src') && !line.include_file_options[1].nil? begin_tag += ' ' + line.include_file_options[1] end - end_tag = '#+END_%s' % [line.include_file_options[0].upcase] + end_tag = format('#+END_%s', line.include_file_options[0].upcase) # Get lines. Will be transformed into an array at processing - include_data = "%s\n%s\n%s" % [begin_tag, IO.read(line.include_file_path), end_tag] + include_data = format("%s\n%s\n%s", begin_tag, IO.read(line.include_file_path), end_tag) else include_data = [] @@ -286,22 +285,22 @@ def set_name_for_code_block(previous_line, line) def set_mode_for_results_block_contents(previous_line, line) if previous_line.start_of_results_code_block? \ - or previous_line.assigned_paragraph_type == :comment - unless @next_results_block_should_be_exported or line.paragraph_type == :blank + || (previous_line.assigned_paragraph_type == :comment) + unless @next_results_block_should_be_exported || (line.paragraph_type == :blank) line.assigned_paragraph_type = :comment end end end # Creates a new parser from the data in a given file - def self.load(fname, opts = {}) + def self.load(fname, _opts = {}) lines = IO.readlines(fname) - return self.new(lines, opts = {}) + new(lines, opts = {}) end # Saves the loaded orgmode file as a textile file. def to_textile - output = "" + output = '' output_buffer = TextileOutputBuffer.new(output) translate(@header_lines, output_buffer) @@ -315,14 +314,15 @@ def to_textile def to_markdown mark_trees_for_export export_options = { - :markup_file => @parser_options[:markup_file] + markup_file: @parser_options[:markup_file] } - output = "" + output = '' output_buffer = MarkdownOutputBuffer.new(output, export_options) translate(@header_lines, output_buffer) @headlines.each do |headline| next if headline.export_state == :exclude + case headline.export_state when :exclude # NOTHING @@ -349,23 +349,23 @@ def to_html markup_file: @parser_options[:markup_file], footnotes_title: @parser_options[:footnotes_title] } - export_options[:skip_tables] = true if not export_tables? - output = "" + export_options[:skip_tables] = true unless export_tables? + output = '' output_buffer = HtmlOutputBuffer.new(output, export_options) - if @in_buffer_settings["TITLE"] - + if title? # If we're given a new title, then just create a new line # for that title. - title = Line.new(@in_buffer_settings["TITLE"], self, :title) - translate([title], output_buffer) + title_line = Line.new(title, self, :title) + translate([title_line], output_buffer) end translate(@header_lines, output_buffer) unless skip_header_lines? # If we've output anything at all, remove the :decorate_title option. - export_options.delete(:decorate_title) if (output.length > 0) + export_options.delete(:decorate_title) if output.length > 0 @headlines.each do |headline| next if headline.export_state == :exclude + case headline.export_state when :exclude # NOTHING @@ -383,6 +383,15 @@ def to_html rp.to_html end + # Hack note (another) + def title? + !in_buffer_settings['TITLE'].nil? + end + def title + in_buffer_settings['TITLE'] + end + #ends hack + ###################################################################### private @@ -409,18 +418,19 @@ def mark_trees_for_export # First pass: See if any headlines are explicitly selected @headlines.each do |headline| - ancestor_stack.pop while not ancestor_stack.empty? and headline.level <= ancestor_stack.last.level - if inherit_export_level and headline.level > inherit_export_level + ancestor_stack.pop while !ancestor_stack.empty? && + (headline.level <= ancestor_stack.last.level) + if inherit_export_level && (headline.level > inherit_export_level) headline.export_state = :all else inherit_export_level = nil headline.tags.each do |tag| - if (select.include? tag) then - marked_any = true - headline.export_state = :all - ancestor_stack.each { |a| a.export_state = :headline_only unless a.export_state == :all } - inherit_export_level = headline.level - end + next unless select.include? tag + + marked_any = true + headline.export_state = :all + ancestor_stack.each { |a| a.export_state = :headline_only unless a.export_state == :all } + inherit_export_level = headline.level end end ancestor_stack.push headline @@ -431,12 +441,12 @@ def mark_trees_for_export # Second pass. Look for things that should be excluded, and get rid of them. @headlines.each do |headline| - if inherit_export_level and headline.level > inherit_export_level + if inherit_export_level && (headline.level > inherit_export_level) headline.export_state = :exclude else inherit_export_level = nil headline.tags.each do |tag| - if (exclude.include? tag) then + if exclude.include? tag headline.export_state = :exclude inherit_export_level = headline.level end @@ -451,7 +461,7 @@ def mark_trees_for_export # Stores an in-buffer setting. def store_in_buffer_setting(key, value) - if key == "OPTIONS" + if key == 'OPTIONS' # Options are stored in a hash. Special-case. value.scan(/([^ ]*):((((\(.*\))))|([^ ])*)/) do |o, v| @@ -460,13 +470,14 @@ def store_in_buffer_setting(key, value) elsif key =~ /^(TODO|SEQ_TODO|TYP_TODO)$/ # Handle todo keywords specially. value.split.each do |keyword| - keyword.gsub!(/\(.*\)/, "") # Get rid of any parenthetical notes + keyword.gsub!(/\(.*\)/, '') # Get rid of any parenthetical notes keyword = Regexp.escape(keyword) - next if keyword == "\\|" # Special character in the todo format, not really a keyword + next if keyword == '\\|' # Special character in the todo format, not really a keyword + @custom_keywords << keyword end else - @in_buffer_settings[key] = value + in_buffer_settings[key] = value end end end # class Parser diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html index f99dc7e..77689ff 100644 --- a/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html +++ b/spec/html_code_syntax_highlight_examples/advanced-code-coderay.html @@ -1,6 +1,6 @@

advanced-code-coderay.org

Turns out there’s more way to do code than just BEGIN_EXAMPLE.

-

1 Inline examples

+

1 Inline examples

This should work:

   fixed width? how does this work?   
@@ -14,7 +14,7 @@ 

1 Inline examples

....

Two ASCII blobs.

-

2 BEGIN_SRC

+

2 BEGIN_SRC

And this:

 # Finds all emphasis matches in a string.
@@ -49,7 +49,7 @@ 

2 BEGIN_SRC

 echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers
 
-

3 It should be possible to write a colon at the beginning of an example

+

3 It should be possible to write a colon at the beginning of an example

I really love to write about :symbols. They sure are the @@ -69,12 +69,12 @@

3 It should be possible "1.0-SNAPSHOT"]] :main helloworld)

-

4 Code syntax highlight with Coderay

-

4.1 No language selected

+

4 Code syntax highlight with Coderay

+

4.1 No language selected

 Nothing to see here
 
-

4.2 CSS example

+

4.2 CSS example

 * {
  /* apply a natural box layout model to all elements */
@@ -83,7 +83,7 @@ 

4.2 CSS example

-webkit-box-sizing: border-box; }
-

4.3 HTML example

+

4.3 HTML example

 <html>
   <head>
@@ -94,7 +94,7 @@ 

4.3 HTML example

</body> </html>
-

4.4 Ruby example

+

4.4 Ruby example

 class Post << ActiveRecord::Base
   def print_title
@@ -102,14 +102,14 @@ 

4.4 Ruby example

end end
-

4.5 Python example

+

4.5 Python example

 import mapnik
 
 m = mapnik.Map(600, 800)
 m.background = Map.Color('steelblue')
 
-

4.6 Javascript example

+

4.6 Javascript example

 exports = this;
 
@@ -123,25 +123,25 @@ 

4.6 Javascript example< })(jQuery);

-

4.7 JSON example

+

4.7 JSON example

 { name: "Waldemar"
 , surname: "Quevedo"
 }
 
-

4.8 PHP example

+

4.8 PHP example

 echo "Hello";
 phpinfo();
 var_dump(some_var);
 
-

4.9 Elisp example

+

4.9 Elisp example

 (defun hello()
   (interactive)
   (message "hello"))
 
-

4.10 Not supported language example

+

4.10 Not supported language example

 !+!+++!++!++!++!+
 
diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-no-color.html b/spec/html_code_syntax_highlight_examples/advanced-code-no-color.html index 2f04744..7c054e5 100644 --- a/spec/html_code_syntax_highlight_examples/advanced-code-no-color.html +++ b/spec/html_code_syntax_highlight_examples/advanced-code-no-color.html @@ -1,6 +1,6 @@

advanced-code.org

Turns out there’s more way to do code than just BEGIN_EXAMPLE.

-

1 Inline examples

+

1 Inline examples

This should work:

   fixed width? how does this work?   
@@ -14,7 +14,7 @@ 

1 Inline examples

....

Two ASCII blobs.

-

2 BEGIN_SRC

+

2 BEGIN_SRC

And this:

 # Finds all emphasis matches in a string.
@@ -49,7 +49,7 @@ 

2 BEGIN_SRC

 echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers
 
-

3 It should be possible to write a colon at the beginning of an example

+

3 It should be possible to write a colon at the beginning of an example

I really love to write about :symbols. They sure are the diff --git a/spec/html_code_syntax_highlight_examples/advanced-code-pygments.html b/spec/html_code_syntax_highlight_examples/advanced-code-pygments.html index 418616d..612b10c 100644 --- a/spec/html_code_syntax_highlight_examples/advanced-code-pygments.html +++ b/spec/html_code_syntax_highlight_examples/advanced-code-pygments.html @@ -1,6 +1,6 @@

advanced-code.org

Turns out there’s more way to do code than just BEGIN_EXAMPLE.

-

1 Inline examples

+

1 Inline examples

This should work:

   fixed width? how does this work?   
@@ -14,7 +14,7 @@ 

1 Inline examples

....

Two ASCII blobs.

-

2 BEGIN_SRC

+

2 BEGIN_SRC

And this:

# Finds all emphasis matches in a string.
 # Supply a block that will get the marker and body as parameters.
@@ -45,7 +45,7 @@ 

2 BEGIN_SRC

Even if no language is set, it is still wrapped in code tags but class is empty.

echo 'Defaults env_keeps="http_proxy https_proxy ftp_proxy"' | sudo tee -a /etc/sudoers
 
-

3 It should be possible to write a colon at the beginning of an example

+

3 It should be possible to write a colon at the beginning of an example

I really love to write about :symbols. They sure are the @@ -63,19 +63,19 @@

3 It should be possible "1.0-SNAPSHOT"]] :main helloworld)

-

4 Code syntax highlight with Pygments

-

4.1 No language selected

+

4 Code syntax highlight with Pygments

+

4.1 No language selected

<script>alert('hello world')</script>
 
-

4.2 CSS example

+

4.2 CSS example

* {
  /* apply a natural box layout model to all elements */
- box-sizing: border-box; 
- -moz-box-sizing: border-box; 
- -webkit-box-sizing: border-box; 
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
 }
 
-

4.3 HTML example

+

4.3 HTML example

<html>
   <head>
     <title>Hello</title>
@@ -85,20 +85,20 @@ 

4.3 HTML example

</body> </html>
-

4.4 Ruby example

+

4.4 Ruby example

class Post << ActiveRecord::Base
   def print_title
     puts "#{self.title}"
   end
 end
 
-

4.5 Python example

+

4.5 Python example

import mapnik
 
 m = mapnik.Map(600, 800)
 m.background = Map.Color('steelblue')
 
-

4.6 Javascript example

+

4.6 Javascript example

exports = this;
 
 (function($){
@@ -111,21 +111,21 @@ 

4.6 Javascript example< })(jQuery);

-

4.7 JSON example

+

4.7 JSON example

{ name: "Waldemar"
 , surname: "Quevedo"
 }
 
-

4.8 PHP example

+

4.8 PHP example

echo "Hello";
 phpinfo();
 var_dump(some_var);
 
-

4.9 Elisp example

+

4.9 Elisp example

(defun hello()
   (interactive)
   (message "hello"))
 
-

4.10 Not supported language example

+

4.10 Not supported language example

!+!+++!++!++!++!+
 
diff --git a/spec/html_code_syntax_highlight_examples/code-block-exports-coderay.html b/spec/html_code_syntax_highlight_examples/code-block-exports-coderay.html index 2be28fc..4077573 100644 --- a/spec/html_code_syntax_highlight_examples/code-block-exports-coderay.html +++ b/spec/html_code_syntax_highlight_examples/code-block-exports-coderay.html @@ -1,7 +1,7 @@

Support for :exports options from code blocks

According to the Org mode docs, it is possible to customize whether the code block will be exported or not.

-

About the #+RESULTS: block

+

About the #+RESULTS: block

Using Org Babel features, it is possible to set :results output to a code block and render the results within a #+RESULTS: code block:

@@ -78,7 +78,7 @@ 

About the #+RESULTS: block

-

Default options

+

Default options

The default is to export only the code blocks.

The following is an code block written in Emacs Lisp and its result should not be exported.

@@ -93,7 +93,7 @@

Default options

-

:exports code

+

:exports code

Only the code would be in the output, the same as when no option is set.

@@ -110,13 +110,13 @@ 

:exports code

-

:exports none

+

:exports none

This omits both the resulting block, and the code block itself.

This should work as well when using an example block.

-

:exports both

+

:exports both

 Math::PI + 1
 
@@ -150,7 +150,7 @@

:exports both

block that was executed. This happens after 10 lines by default.
-

:exports results

+

:exports results

This option can’t be completely supported by OrgRuby since we would have to eval the code block using :lang, so Org Babel features would have to be implemented as well.

diff --git a/spec/html_code_syntax_highlight_examples/code-block-exports-no-color.html b/spec/html_code_syntax_highlight_examples/code-block-exports-no-color.html index a2e10e4..27622fc 100644 --- a/spec/html_code_syntax_highlight_examples/code-block-exports-no-color.html +++ b/spec/html_code_syntax_highlight_examples/code-block-exports-no-color.html @@ -1,7 +1,7 @@

Support for :exports options from code blocks

According to the Org mode docs, it is possible to customize whether the code block will be exported or not.

-

About the #+RESULTS: block

+

About the #+RESULTS: block

Using Org Babel features, it is possible to set :results output to a code block and render the results within a #+RESULTS: code block:

@@ -78,7 +78,7 @@ 

About the #+RESULTS: block

-

Default options

+

Default options

The default is to export only the code blocks.

The following is an code block written in Emacs Lisp and its result should not be exported.

@@ -93,7 +93,7 @@

Default options

-

:exports code

+

:exports code

Only the code would be in the output, the same as when no option is set.

@@ -110,13 +110,13 @@ 

:exports code

-

:exports none

+

:exports none

This omits both the resulting block, and the code block itself.

This should work as well when using an example block.

-

:exports both

+

:exports both

 Math::PI + 1
 
@@ -150,7 +150,7 @@

:exports both

block that was executed. This happens after 10 lines by default.
-

:exports results

+

:exports results

This option can’t be completely supported by OrgRuby since we would have to eval the code block using :lang, so Org Babel features would have to be implemented as well.

@@ -173,7 +173,7 @@

:exports results

any string any string
-

When results are graphics…

+

When results are graphics…

A code block which is evaled within a Org mode buffer using Org babel features will have its results appear within another code block prepended with a #+RESULTS directive.

@@ -203,8 +203,8 @@

When results are graphics…

workflow.png

-

When blocks have a name, the results should be the same

-

exports code

+

When blocks have a name, the results should be the same

+

exports code

 var message = "Hello world!";
 
@@ -218,10 +218,10 @@ 

exports code

-

exports none

+

exports none

-

exports both

+

exports both

 Math::PI + 1
 
@@ -254,7 +254,7 @@

exports both

block that was executed. This happens after 10 lines by default. -

exports results

+

exports results

 3.141592653589793
 
diff --git a/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html b/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html index 0d7c101..d490721 100644 --- a/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html +++ b/spec/html_code_syntax_highlight_examples/code-block-exports-pygments.html @@ -1,7 +1,7 @@

Support for :exports options from code blocks

According to the Org mode docs, it is possible to customize whether the code block will be exported or not.

-

About the #+RESULTS: block

+

About the #+RESULTS: block

Using Org Babel features, it is possible to set :results output to a code block and render the results within a #+RESULTS: code block:

#+begin_src ruby :results output :exports both
@@ -74,7 +74,7 @@ 

About the #+RESULTS: block

-

Default options

+

Default options

The default is to export only the code blocks.

The following is an code block written in Emacs Lisp and its result should not be exported.

@@ -87,7 +87,7 @@

Default options

-

:exports code

+

:exports code

Only the code would be in the output, the same as when no option is set.

var message = "Hello world!";
@@ -102,13 +102,13 @@ 

:exports code

-

:exports none

+

:exports none

This omits both the resulting block, and the code block itself.

This should work as well when using an example block.

-

:exports both

+

:exports both

Math::PI + 1
 
@@ -140,7 +140,7 @@ 

:exports both

block that was executed. This happens after 10 lines by default.
-

:exports results

+

:exports results

This option can’t be completely supported by OrgRuby since we would have to eval the code block using :lang, so Org Babel features would have to be implemented as well.

diff --git a/spec/html_examples/custom-seq-todo.html b/spec/html_examples/custom-seq-todo.html index 1c3ced4..78e6070 100644 --- a/spec/html_examples/custom-seq-todo.html +++ b/spec/html_examples/custom-seq-todo.html @@ -2,18 +2,18 @@

custom-todo.org

I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)

-

TODO Sample

+

TODO Sample

  • State “CANCELED” from “INPROGRESS” [2009-12-29 Tue 22:26]
    I gave up.
  • State “WAITING” from “” [2009-12-29 Tue 22:25]
    huh?
-

INPROGRESS this one’s in progress

-

WAITING who am I waiting on?

-

DONE Finished this one!

-

CANCELED I gave up here.

-

DONT be fooled by just a random word in all caps.

-

todo <== this word doesn’t match because the case doesn’t match.

-

TODOX

+

INPROGRESS this one’s in progress

+

WAITING who am I waiting on?

+

DONE Finished this one!

+

CANCELED I gave up here.

+

DONT be fooled by just a random word in all caps.

+

todo <== this word doesn’t match because the case doesn’t match.

+

TODOX

don’t be fooled by the initial substring above!

diff --git a/spec/html_examples/custom-todo.html b/spec/html_examples/custom-todo.html index 1c3ced4..78e6070 100644 --- a/spec/html_examples/custom-todo.html +++ b/spec/html_examples/custom-todo.html @@ -2,18 +2,18 @@

custom-todo.org

I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)

-

TODO Sample

+

TODO Sample

  • State “CANCELED” from “INPROGRESS” [2009-12-29 Tue 22:26]
    I gave up.
  • State “WAITING” from “” [2009-12-29 Tue 22:25]
    huh?
-

INPROGRESS this one’s in progress

-

WAITING who am I waiting on?

-

DONE Finished this one!

-

CANCELED I gave up here.

-

DONT be fooled by just a random word in all caps.

-

todo <== this word doesn’t match because the case doesn’t match.

-

TODOX

+

INPROGRESS this one’s in progress

+

WAITING who am I waiting on?

+

DONE Finished this one!

+

CANCELED I gave up here.

+

DONT be fooled by just a random word in all caps.

+

todo <== this word doesn’t match because the case doesn’t match.

+

TODOX

don’t be fooled by the initial substring above!

diff --git a/spec/html_examples/custom-typ-todo.html b/spec/html_examples/custom-typ-todo.html index cf6d202..4b401b1 100644 --- a/spec/html_examples/custom-typ-todo.html +++ b/spec/html_examples/custom-typ-todo.html @@ -2,18 +2,18 @@

custom-typ-todo.org

I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let’s make sure all of these are recognized (and therefore NOT exported.)

-

TODO Sample

+

TODO Sample

  • State “CANCELED” from “INPROGRESS” [2009-12-29 Tue 22:26]
    I gave up.
  • State “WAITING” from “” [2009-12-29 Tue 22:25]
    huh?
-

INPROGRESS this one’s in progress

-

WAITING who am I waiting on?

-

DONE Finished this one!

-

CANCELED I gave up here.

-

DONT be fooled by just a random word in all caps.

-

todo <== this word doesn’t match because the case doesn’t match.

-

TODOX

+

INPROGRESS this one’s in progress

+

WAITING who am I waiting on?

+

DONE Finished this one!

+

CANCELED I gave up here.

+

DONT be fooled by just a random word in all caps.

+

todo <== this word doesn’t match because the case doesn’t match.

+

TODOX

don’t be fooled by the initial substring above!

diff --git a/spec/html_examples/deflist.html b/spec/html_examples/deflist.html index 2749b4b..880ed9d 100644 --- a/spec/html_examples/deflist.html +++ b/spec/html_examples/deflist.html @@ -4,17 +4,17 @@

Hallo

b
world

Text

-

Asterisk can be used for lists

+

Asterisk can be used for lists

One
The first number.
Two
The second number.
Three
The second number.
-

Corner cases of definition lists

+

Corner cases of definition lists

The following examples show how org-ruby behave when handling some cases of definition lists. (Many thanks to vonavi for his contributions here)

-

Definition List Items

+

Definition List Items

  • Regular list
    @@ -63,7 +63,7 @@

    Definition List Items

-

Not Definition List Items

+

Not Definition List Items

The following cases will not be considered as definition lists but just regular lists.

    @@ -75,7 +75,7 @@

    Not Definition List Items

  • Key :: Value (n5)
-

Definition List Item without Definition

+

Definition List Item without Definition

??? will be shown in this case

  • Example list @@ -89,7 +89,7 @@

    Definition List Item without Definition

-

Definition List with markup inline

+

Definition List with markup inline

Description
bold
Description
italic
diff --git a/spec/html_examples/entities.html b/spec/html_examples/entities.html index 60696d7..7c38cbf 100644 --- a/spec/html_examples/entities.html +++ b/spec/html_examples/entities.html @@ -6,7 +6,7 @@

ENTITIES

  • Question: What does org-mode do for ampersands, like R&R? or &lt;?
  • Answer: Those get escaped, too. ☺
  • -

    <Even in headlines! funner & funner!>

    +

    <Even in headlines! funner & funner!>

    « They α should β be γ able δ to η exist θ in ε the same line √ ».

    @@ -19,7 +19,7 @@

    <Even in headlines! funner & funner!>

    ⌊ — — — — — — ⌋

    To work they have to be separated, like ♥ ♥, not like ♥\hearts.

    -

    List of entities supported

    +

    List of entities supported

     # Script to generate the list of currently supported entities
     require 'org-ruby'
    @@ -376,6 +376,6 @@ 

    List of entities supported

  • Writing \Diamond, results in: ⋄
  • Writing \loz, results in: ◊
  • -

    Some special cases

    +

    Some special cases

    In case nothing matches, the string is returned as is.

    \for \example \this \wont \break

    diff --git a/spec/html_examples/export-exclude-only.html b/spec/html_examples/export-exclude-only.html index 6807eb1..d55d5dc 100644 --- a/spec/html_examples/export-exclude-only.html +++ b/spec/html_examples/export-exclude-only.html @@ -1,11 +1,11 @@

    export-headline-levels.org

    What happens when you exceed the number of headline levels to export?

    -

    1 Headline 1

    -

    1.1 Headline 2

    +

    1 Headline 1

    +

    1.1 Headline 2

    This bit of body should get exported.

    -

    1.1.1 Headline 3

    +

    1.1.1 Headline 3

    This bit of body gets exported.

    -

    1.1.1.1 Headline 4 (include)

    +
    1.1.1.1 Headline 4 (include)

    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo @@ -21,7 +21,7 @@

    1.1.1.1 Headline 4 (inc voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

    -

    1.1.2 Another headline 3

    +

    1.1.2 Another headline 3

    This one should not get exported!!

    -

    1.1.2.1 Another headline 4

    +
    1.1.2.1 Another headline 4

    This also cannot get exported!!

    diff --git a/spec/html_examples/export-keywords.html b/spec/html_examples/export-keywords.html index 894bd6f..2ec3ad3 100644 --- a/spec/html_examples/export-keywords.html +++ b/spec/html_examples/export-keywords.html @@ -1,4 +1,4 @@

    export-keywords.org

    Testing that I can export keywords.

    -

    1 TODO This is a todo item.

    -

    2 DONE this item is done!

    +

    1 TODO This is a todo item.

    +

    2 DONE this item is done!

    diff --git a/spec/html_examples/export-tags.html b/spec/html_examples/export-tags.html index d183c73..3ffa20e 100644 --- a/spec/html_examples/export-tags.html +++ b/spec/html_examples/export-tags.html @@ -1,10 +1,10 @@

    export-headline-levels.org

    What happens when you exceed the number of headline levels to export?

    -

    1 Headline 1

    -

    1.1 Headline 2

    -

    1.1.1 Headline 3

    +

    1 Headline 1

    +

    1.1 Headline 2

    +

    1.1.1 Headline 3

    This bit of body gets exported.

    -

    1.1.1.1 Headline 4 (include)

    +
    1.1.1.1 Headline 4 (include)

    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo diff --git a/spec/html_examples/include-file-disabled.html b/spec/html_examples/include-file-disabled.html index ad71e68..e3dd07a 100644 --- a/spec/html_examples/include-file-disabled.html +++ b/spec/html_examples/include-file-disabled.html @@ -1,21 +1,21 @@

    Example of including a file

    -

    Basic tests

    -

    Within a commented block

    -

    Within a center block

    +

    Basic tests

    +

    Within a commented block

    +

    Within a center block

    The following included file will be centered:

    -

    Within a blockquote

    +

    Within a blockquote

    This is similar to the center block:

    Before

    After

    -

    Within an example block, it should not be possible to include a file.

    +

    Within an example block, it should not be possible to include a file.

     #+INCLUDE: "./spec/html_examples/only-list.org"
     
    -

    Within a list

    +

    Within a list

    • A list that has an included file directive
        @@ -33,11 +33,11 @@

        Within a list

        • 3rd level, though it should be a different list
        -

        Within a table, cannot be included

        +

        Within a table, cannot be included

        OneTwoThree
        #+INCLUDE: “./spec/html_examples/only-list.org”FiveSix
        SevenEightNine
        -

        When including a file as an example

        -

        When including a file as an quote

        +

        When including a file as an example

        +

        When including a file as an quote

        diff --git a/spec/html_examples/include-file.html b/spec/html_examples/include-file.html index f535586..ab56cb6 100644 --- a/spec/html_examples/include-file.html +++ b/spec/html_examples/include-file.html @@ -1,8 +1,8 @@

        Example of including a file

        -

        Basic tests

        +

        Basic tests

        Advanced Lists

        org-ruby supports the following list features of org-mode:

        -

        Nested lists

        +

        Nested lists

        • You can have nested lists
        • This is first-level @@ -21,7 +21,7 @@

          Nested lists

        Note the list ends just some more text. Make sure both list blocks are closed.

        -

        Multi-paragraph list items

        +

        Multi-paragraph list items

        This list will end with the end-of-file. Make sure all blocks are closed.

        • This is a list item
        • @@ -36,7 +36,7 @@

          Multi-paragraph list items

      -

      Hyphen, Plus and Asterisk can be used to create lists

      +

      Hyphen, Plus and Asterisk can be used to create lists

      • One
          @@ -61,7 +61,7 @@

          Hyphen, Plus and Asterisk can be used to create lists

        • Three
        • Four
        -

        Continue numbered list

        +

        Continue numbered list

        Here comes a multi-part list.

        1. Item the first.
        2. @@ -75,14 +75,14 @@

          Continue numbered list

          BLOCKCOMMENT

          Testing that the next part is ignored

          And now back to normal!

          -

          Within a commented block

          +

          Within a commented block

           <li>[ ] &#8220;smart quotes&#8221;</li> 
           <li>[ ] I think I need this for &#8216;single quotes&#8217; too. Don&#8217;t I?</li> 
           <li>[ ] Em dashes would be great &#8212; wouldn&#8217;t they?</li> 
           <li>[ ] I hope to develop an en dash sometime in 2010 &#8211; 2011.</li> 
           
          -

          Within a center block

          +

          Within a center block

          The following included file will be centered:

          Inline Images

          @@ -108,7 +108,7 @@

          Within a center block

          Sample relative link to .svgz:

          images/conform-viewers-01-t.svgz

          -

          Within a blockquote

          +

          Within a blockquote

          This is similar to the center block:

          Before @@ -136,11 +136,11 @@

          Within a blockquote

          images/conform-viewers-01-t.svgz

          After

          -

          Within an example block, it should not be possible to include a file.

          +

          Within an example block, it should not be possible to include a file.

           #+INCLUDE: "./spec/html_examples/only-list.org"
           
          -

          Within a list

          +

          Within a list

          • A list that has an included file directive
              @@ -161,20 +161,20 @@

              Within a list

              • 3rd level, though it should be a different list
              -

              Within a table, cannot be included

              +

              Within a table, cannot be included

              OneTwoThree
              #+INCLUDE: “./spec/html_examples/only-list.org”FiveSix
              SevenEightNine
              -

              When including a file as an example

              +

              When including a file as an example

               - This file has only a list
               - Note it will end with nothing other than a list item.
               - the world wants to know: Will org-ruby write the closing ul tag?
               
               
              -

              When including a file as an quote

              +

              When including a file as an quote

              • This file has only a list
              • diff --git a/spec/html_examples/link-features.html b/spec/html_examples/link-features.html index 81ef845..30b0854 100644 --- a/spec/html_examples/link-features.html +++ b/spec/html_examples/link-features.html @@ -2,28 +2,28 @@

                link-features.org

                Org-mode export supports a lot of link features. I’ve covered “simple” HTML links elsewhere. Now let’s cover links to other org files, other sections within documents, etc.

                -

                Links to other org files

                +

                Links to other org files

                This is a link to the code-comment.org file in the same directory. In emacs, if you click it, the other file opens. We want the same behavior in the HTML export.

                Code Comment

                Emacs Code Comment

                Sys Code Comment

                -

                Search links

                +

                Search links

                This is a search link into code-comment.org.

                Code Comment

                -

                Correct handling of .org URIs in HTML markup routine (thanks @rayl!)

                +

                Correct handling of .org URIs in HTML markup routine (thanks @rayl!)

                -

                In these links, .org used to be converted to .html. Not anymore since 0.9.2 version of the gem

                +

                In these links, .org used to be converted to .html. Not anymore since 0.9.2 version of the gem

                -

                Links abbreviations

                +

                Links abbreviations

                URLs can be abbreviated by a LINK definition in the org file

                This is an abbreviated link example

                diff --git a/spec/html_examples/options-parsing.html b/spec/html_examples/options-parsing.html index 448657b..8860022 100644 --- a/spec/html_examples/options-parsing.html +++ b/spec/html_examples/options-parsing.html @@ -1,4 +1,4 @@

                Options parsing

                The options hash should not make the parser throw exceptions upon unrecognized options.

                -

                0.0.1 TODO Hello world

                +

                0.0.1 TODO Hello world

                Hi

                diff --git a/spec/html_examples/skip-header.html b/spec/html_examples/skip-header.html index bdbc02d..bf44621 100644 --- a/spec/html_examples/skip-header.html +++ b/spec/html_examples/skip-header.html @@ -1,3 +1,3 @@

                skip-header.org

                -

                1 First heading

                +

                1 First heading

                This should be the first text in the output.

                diff --git a/spec/markdown_examples/custom-seq-todo.md b/spec/markdown_examples/custom-seq-todo.md index 06c57f6..e908f6b 100644 --- a/spec/markdown_examples/custom-seq-todo.md +++ b/spec/markdown_examples/custom-seq-todo.md @@ -3,18 +3,18 @@ I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let's make sure all of these are recognized (and therefore NOT exported.) -# Sample +## Sample * State "CANCELED" from "INPROGRESS" [2009-12-29 Tue 22:26] \\ I gave up. * State "WAITING" from "" [2009-12-29 Tue 22:25] \\ huh? -# this one's in progress -# who am I waiting on? -# Finished this one! -# I gave up here. -# DONT be fooled by just a random word in all caps. -# todo <== this word doesn't match because the case doesn't match. -# TODOX +## this one's in progress +## who am I waiting on? +## Finished this one! +## I gave up here. +## DONT be fooled by just a random word in all caps. +## todo <== this word doesn't match because the case doesn't match. +## TODOX don't be fooled by the initial substring above! diff --git a/spec/markdown_examples/custom-todo.md b/spec/markdown_examples/custom-todo.md index 06c57f6..e908f6b 100644 --- a/spec/markdown_examples/custom-todo.md +++ b/spec/markdown_examples/custom-todo.md @@ -3,18 +3,18 @@ I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let's make sure all of these are recognized (and therefore NOT exported.) -# Sample +## Sample * State "CANCELED" from "INPROGRESS" [2009-12-29 Tue 22:26] \\ I gave up. * State "WAITING" from "" [2009-12-29 Tue 22:25] \\ huh? -# this one's in progress -# who am I waiting on? -# Finished this one! -# I gave up here. -# DONT be fooled by just a random word in all caps. -# todo <== this word doesn't match because the case doesn't match. -# TODOX +## this one's in progress +## who am I waiting on? +## Finished this one! +## I gave up here. +## DONT be fooled by just a random word in all caps. +## todo <== this word doesn't match because the case doesn't match. +## TODOX don't be fooled by the initial substring above! diff --git a/spec/markdown_examples/custom-typ-todo.md b/spec/markdown_examples/custom-typ-todo.md index 06c57f6..e908f6b 100644 --- a/spec/markdown_examples/custom-typ-todo.md +++ b/spec/markdown_examples/custom-typ-todo.md @@ -3,18 +3,18 @@ I copied this todo sequence from Worg. It shows a lot of power of the built-in todo functionality. Now, let's make sure all of these are recognized (and therefore NOT exported.) -# Sample +## Sample * State "CANCELED" from "INPROGRESS" [2009-12-29 Tue 22:26] \\ I gave up. * State "WAITING" from "" [2009-12-29 Tue 22:25] \\ huh? -# this one's in progress -# who am I waiting on? -# Finished this one! -# I gave up here. -# DONT be fooled by just a random word in all caps. -# todo <== this word doesn't match because the case doesn't match. -# TODOX +## this one's in progress +## who am I waiting on? +## Finished this one! +## I gave up here. +## DONT be fooled by just a random word in all caps. +## todo <== this word doesn't match because the case doesn't match. +## TODOX don't be fooled by the initial substring above! diff --git a/spec/markdown_examples/deflist.md b/spec/markdown_examples/deflist.md index 006ce15..4e953f9 100644 --- a/spec/markdown_examples/deflist.md +++ b/spec/markdown_examples/deflist.md @@ -4,19 +4,19 @@ b :: world Text -# Asterisk can be used for lists +## Asterisk can be used for lists One :: The first number. Two :: The second number. Three :: The second number. -# Corner cases of definition lists +## Corner cases of definition lists The following examples show how org-ruby behave when handling some cases of definition lists. (Many thanks to [vonavi](https://github.com/vonavi) for his contributions here) -## Definition List Items +### Definition List Items * Regular list Key :: Value (k1) @@ -45,7 +45,7 @@ Key:: MoreKey :: Value (k2) * Case 3 :: Key :: Value (k3) -## Not Definition List Items +### Not Definition List Items The following cases will not be considered as definition lists but just regular lists. @@ -58,7 +58,7 @@ Value (n4) * Key :: Value (n5) -## Definition List Item without Definition +### Definition List Item without Definition ??? will be shown in this case diff --git a/spec/markdown_examples/entities.md b/spec/markdown_examples/entities.md index b007d72..4134230 100644 --- a/spec/markdown_examples/entities.md +++ b/spec/markdown_examples/entities.md @@ -6,7 +6,7 @@ things... like elipses. Oh -- and dashes. * Question: What does org-mode do for ampersands, like R&R? or <? * Answer: Those get escaped, too. ☺ -# +## « They α should β be γ able δ to η exist θ in ε @@ -24,7 +24,7 @@ Though they appear in center blocks To work they have to be separated, like ♥ ♥, not like ♥\hearts. -# List of entities supported +## List of entities supported ``` # Script to generate the list of currently supported entities @@ -383,7 +383,7 @@ bundle exec ruby /tmp/print_entities.rb * Writing `\Diamond`, results in: ⋄ * Writing `\loz`, results in: ◊ -# Some special cases +## Some special cases In case nothing matches, the string is returned as is. diff --git a/spec/markdown_examples/export-exclude-only.md b/spec/markdown_examples/export-exclude-only.md index 30a2584..19b0822 100644 --- a/spec/markdown_examples/export-exclude-only.md +++ b/spec/markdown_examples/export-exclude-only.md @@ -1,17 +1,17 @@ What happens when you exceed the number of headline levels to export? -# Headline 1 +## Headline 1 -## Headline 2 +### Headline 2 This bit of body **should** get exported. -### Headline 3 +#### Headline 3 This bit of body gets exported. -#### Headline 4 (include) +##### Headline 4 (include) Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam @@ -29,10 +29,10 @@ voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. -### Another headline 3 +#### Another headline 3 This one **should not** get exported!! -#### Another headline 4 +##### Another headline 4 This also **cannot** get exported!! diff --git a/spec/markdown_examples/export-keywords.md b/spec/markdown_examples/export-keywords.md index b73112a..7bf23ab 100644 --- a/spec/markdown_examples/export-keywords.md +++ b/spec/markdown_examples/export-keywords.md @@ -1,4 +1,4 @@ Testing that I can export keywords. -# This is a todo item. -# this item is done! +## This is a todo item. +## this item is done! diff --git a/spec/markdown_examples/export-tags.md b/spec/markdown_examples/export-tags.md index d8c1b42..d0862f0 100644 --- a/spec/markdown_examples/export-tags.md +++ b/spec/markdown_examples/export-tags.md @@ -1,13 +1,13 @@ What happens when you exceed the number of headline levels to export? -# Headline 1 -## Headline 2 -### Headline 3 +## Headline 1 +### Headline 2 +#### Headline 3 This bit of body gets exported. -#### Headline 4 (include) +##### Headline 4 (include) Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam diff --git a/spec/markdown_examples/footnotes.md b/spec/markdown_examples/footnotes.md index a0e290e..b4ce5ac 100644 --- a/spec/markdown_examples/footnotes.md +++ b/spec/markdown_examples/footnotes.md @@ -1,5 +1,5 @@ -# Footnotes +## Footnotes Using numbers [fn:0] diff --git a/spec/markdown_examples/include-file.md b/spec/markdown_examples/include-file.md index 3ba88ac..1b677d2 100644 --- a/spec/markdown_examples/include-file.md +++ b/spec/markdown_examples/include-file.md @@ -1,29 +1,29 @@ -# Basic tests +## Basic tests -# Within a commented block +## Within a commented block -# Within a center block +## Within a center block The following included file will be centered: -# Within a blockquote +## Within a blockquote This is similar to the center block: > Before > After -# Within an example block, it should not be possible to include a file. +## Within an example block, it should not be possible to include a file. #+INCLUDE: "./spec/html_examples/only-list.org" -# Within a list +## Within a list * A list that has an included file directive * Only go to the first level @@ -31,15 +31,15 @@ This is similar to the center block: * 3rd level * 3rd level, though it should be a different list -# Within a table, cannot be included +## Within a table, cannot be included | One | Two | Three | | #+INCLUDE: "./spec/html_examples/only-list.org" | Five | Six | | Seven | Eight | Nine | -# When including a file as an example +## When including a file as an example -# When including a file as an quote +## When including a file as an quote diff --git a/spec/markdown_examples/link-features.md b/spec/markdown_examples/link-features.md index de481e5..667b0b6 100644 --- a/spec/markdown_examples/link-features.md +++ b/spec/markdown_examples/link-features.md @@ -3,7 +3,7 @@ Org-mode export supports a lot of link features. I've covered "simple" HTML links elsewhere. Now let's cover links to other org files, other sections within documents, etc. -# Links to other org files +## Links to other org files This is a link to the `code-comment.org` file in the same directory. In `emacs`, if you click it, the other file opens. We @@ -11,13 +11,13 @@ want the same behavior in the HTML export. [Code Comment](file:code-comment.org) -# Search links +## Search links This is a search link into code-comment.org. [Code Comment](file:code-comment.org::*Code%20Comment) -# Correct handling of .org URIs in HTML markup routine (thanks @rayl!) +## Correct handling of .org URIs in HTML markup routine (thanks @rayl!) * [foo.com website](http://foo.com) @@ -27,13 +27,13 @@ This is a search link into code-comment.org. * [localhost:4567/foo.org](http://localhost:4567/foo.org) -# In these links, .org is converted to .html +## In these links, .org is converted to .html * [file:path.org label](file:path.org) * [file:notes/path.org label](file:notes/path.org) -# Links abbreviations +## Links abbreviations URLs can be abbreviated by a LINK definition in the org file diff --git a/spec/markdown_examples/skip-header.md b/spec/markdown_examples/skip-header.md index 7787fb8..0a3cf41 100644 --- a/spec/markdown_examples/skip-header.md +++ b/spec/markdown_examples/skip-header.md @@ -9,6 +9,6 @@ Even this code snippet shouldn't be there. Like a ninja. You can't see me. ``` -# First heading +## First heading This should be the first text in the output. diff --git a/spec/textile_examples/footnotes.textile b/spec/textile_examples/footnotes.textile index 73e6cde..aaaffe6 100644 --- a/spec/textile_examples/footnotes.textile +++ b/spec/textile_examples/footnotes.textile @@ -1,5 +1,5 @@ -h1. Footnotes +h2. Footnotes p. Using numbers [0] From 66ef9f2385f1991e2bd41801c76a67301bc34135 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Fri, 23 Apr 2021 21:42:33 -0500 Subject: [PATCH 07/12] Refactor conditionals . --- lib/org-ruby/html_output_buffer.rb | 6 +++--- lib/org-ruby/line.rb | 16 ++++------------ lib/org-ruby/output_buffer.rb | 17 ++++++++--------- lib/org-ruby/parser.rb | 6 +----- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 72cd034..4efb6c8 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -225,8 +225,8 @@ def html_buffer_code_block_indent(line) # Org document. def output_footnotes! return false if !options[:export_footnotes] || @footnotes.empty? - @output.concat footnotes_header + @output.concat footnotes_header @footnotes.each do |name, (defi, content)| @buffer = defi @output << "
                #{name}" \ @@ -235,9 +235,9 @@ def output_footnotes! << "

                \n" end - @output << "\n" + @output.concat "\n" - return true + true end def footnotes_header diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb index 9fc5b5b..e7fd32b 100644 --- a/lib/org-ruby/line.rb +++ b/lib/org-ruby/line.rb @@ -232,22 +232,14 @@ def block_header_arguments # TODO: COMMENT block should be considered here def block_should_be_exported? export_state = block_header_arguments[':exports'] - case - when ['both', 'code', nil, ''].include?(export_state) - true - when ['none', 'results'].include?(export_state) - false - end + ['both', 'code', nil, ''].include?(export_state) || + !['none', 'results'].include?(export_state) end def results_block_should_be_exported? export_state = block_header_arguments[':exports'] - case - when ['results', 'both'].include?(export_state) - true - when ['code', 'none', nil, ''].include?(export_state) - false - end + ['results', 'both'].include?(export_state) || + !['code', 'none', nil, ''].include?(export_state) end InlineExampleRegexp = /^\s*:\s/ diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index d26b286..1caadaa 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -211,18 +211,17 @@ def mode_is_code?(mode) def boundary_of_block?(line) # Boundary of inline example - return true if ((line.paragraph_type == :inline_example) ^ - (@output_type == :inline_example)) - # Boundary of begin...end block - return true if mode_is_block? @output_type + ((line.paragraph_type == :inline_example) ^ (@output_type == :inline_example)) || + # Boundary of begin...end block + mode_is_block?(@output_type) end def maintain_mode_stack(line) # Always close the following lines - pop_mode if (mode_is_heading? current_mode or - current_mode == :paragraph or - current_mode == :horizontal_rule or - current_mode == :inline_example or + pop_mode if (mode_is_heading?(current_mode) || + current_mode == :paragraph || + current_mode == :horizontal_rule || + current_mode == :inline_example || current_mode == :raw_text) # End-block line closes every mode within block @@ -281,7 +280,7 @@ def should_accumulate_output? line # Special case: Handles accumulating block content and example lines if mode_is_code? current_mode - return true unless (line.end_block? and + return true unless (line.end_block? && line.paragraph_type == current_mode) end return false if boundary_of_block? line diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index d90de05..4572cfa 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -210,11 +210,7 @@ def parse_lines(lines) # We treat the results code block differently since the exporting can be omitted if line.begin_block? - @next_results_block_should_be_exported = if line.results_block_should_be_exported? - true - else - false - end + @next_results_block_should_be_exported = line.results_block_should_be_exported? end end From d39bbf2388e92ee1c2fddf3d0a58b21f0895dfa0 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sun, 7 Nov 2021 16:12:12 -0600 Subject: [PATCH 08/12] Modify emphasis regexp to fix #48 --- lib/org-ruby/html_output_buffer.rb | 14 +- lib/org-ruby/output_buffer.rb | 12 +- lib/org-ruby/regexp_helper.rb | 91 ++++++------ spec/html_examples/emphasis.html | 1 + spec/html_examples/emphasis.org | 172 +++++++++++------------ spec/org-ruby/html_output_buffer_spec.rb | 13 +- 6 files changed, 152 insertions(+), 151 deletions(-) diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 4efb6c8..11b9317 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -460,6 +460,8 @@ def strip_code_block! end end + private + # The CGI::escapeHTML function backported from the Ruby standard library # as of commit fd2fc885b43283aa3d76820b2dfa9de19a77012f # @@ -474,14 +476,14 @@ def strip_code_block! '&' => '&', '"' => '"', '<' => '<', - '>' => '>', - } + '>' => '>' + }.freeze + # Escape special characters in HTML, namely &\"<> # escapeHTML('Usage: foo "bar" ') # # => "Usage: foo "bar" <baz>" - private def escapeHTML(string) - string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__) + string.gsub(/['&"<>]/, TABLE_FOR_ESCAPE_HTML__) end - end # class HtmlOutputBuffer -end # module Orgmode + end +end diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index 1caadaa..22e25d4 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -269,12 +269,12 @@ def add_line_attributes(headline) end def output_footnotes! - return false + false end # Tests if the current line should be accumulated in the current # output buffer. - def should_accumulate_output? line + def should_accumulate_output?(line) # Special case: Assign mode if not yet done. return false unless current_mode @@ -287,9 +287,9 @@ def should_accumulate_output? line return true if current_mode == :inline_example # Special case: Don't accumulate the following lines. - return false if (mode_is_heading? @output_type or - @output_type == :comment or - @output_type == :horizontal_rule or + return false if (mode_is_heading?(@output_type) || + @output_type == :comment || + @output_type == :horizontal_rule || @output_type == :raw_text) # Special case: Blank line at least splits paragraphs @@ -298,7 +298,7 @@ def should_accumulate_output? line if line.paragraph_type == :paragraph # Paragraph gets accumulated only if its indent level is # greater than the indent level of the previous mode. - if @mode_stack[-2] and not mode_is_block? @mode_stack[-2] + if @mode_stack[-2] && !mode_is_block?(@mode_stack[-2]) return false if line.indent <= @list_indent_stack[-2] end # Special case: Multiple "paragraphs" get accumulated. diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb index 7e79317..57be200 100644 --- a/lib/org-ruby/regexp_helper.rb +++ b/lib/org-ruby/regexp_helper.rb @@ -44,18 +44,9 @@ class RegexpHelper def initialize # Set up the emphasis regular expression. - @pre_emphasis = ' \t\(\'"\{' - @post_emphasis = '- \t\.,:!\?;\'"\)\}\\\\' - @border_forbidden = ' \t\r\n' - @body_regexp = '.*?' - @max_newlines = 1 - @body_regexp = "#{@body_regexp}" + - "(?:\\n#{@body_regexp}){0,#{@max_newlines}}" if @max_newlines > 0 - @markers = '\*\/_=~\+' @code_snippet_stack = [] @logger = Logger.new(STDERR) @logger.level = Logger::WARN - build_org_emphasis_regexp build_org_link_regexp @org_subp_regexp = /([_^])\{(.*?)\}/ @org_footnote_regexp = /\[fn:(.+?)(:(.*))?\]/ @@ -65,8 +56,8 @@ def initialize # Finds all emphasis matches in a string. # Supply a block that will get the marker and body as parameters. def match_all(str) - str.scan(@org_emphasis_regexp) do |match| - yield $2, $3 + str.scan(org_emphasis_regexp) do |_match| + yield Regexp.last_match[2], Regexp.last_match[3] end end @@ -95,39 +86,38 @@ def rewrite_emphasis(str) # escape the percent signs for safe restoring code snippets str.gsub!(/%/, "%%") format_str = "%s" - str.gsub! @org_emphasis_regexp do |match| - pre = $1 + str.gsub!(org_emphasis_regexp) do |_match| + pre = Regexp.last_match(1) # preserve the code snippet from further formatting - if $2 == "=" or $2 == "~" - inner = yield $2, $3 + inner = yield Regexp.last_match(2), Regexp.last_match(3) + if %w[= ~].include?(Regexp.last_match(2)) # code is not formatted, so turn to single percent signs inner.gsub!(/%%/, "%") @code_snippet_stack.push inner "#{pre}#{format_str}" else - inner = yield $2, $3 "#{pre}#{inner}" end end end # rewrite subscript and superscript (_{foo} and ^{bar}) - def rewrite_subp str # :yields: type ("_" for subscript and "^" for superscript), text - str.gsub! @org_subp_regexp do |match| - yield $1, $2 + def rewrite_subp(str) # :yields: type ("_" for subscript and "^" for superscript), text + str.gsub! @org_subp_regexp do |_match| + yield Regexp.last_match(1), Regexp.last_match(2) end end # rewrite footnotes - def rewrite_footnote str # :yields: name, definition or nil - str.gsub! @org_footnote_regexp do |match| - yield $1, $3 + def rewrite_footnote(str) # :yields: name, definition or nil + str.gsub! @org_footnote_regexp do |_match| + yield Regexp.last_match(1), Regexp.last_match(3) end end - def rewrite_footnote_definition str - str.gsub! @org_footnote_def_regexp do |match| - yield $1, $5 + def rewrite_footnote_definition(str) + str.gsub! @org_footnote_def_regexp do |_match| + yield Regexp.last_match(1), Regexp.last_match(5) end end @@ -156,33 +146,52 @@ def rewrite_footnote_definition str # +http://www.hotmail.com+. In both cases, the block returns an # HTML-style link, and that is how things will get recorded in # +result+. - def rewrite_links str # :yields: link, text - str.gsub! @org_link_regexp do |match| - yield $1, $3 + def rewrite_links(str) + str.gsub! @org_link_regexp do |_match| + yield Regexp.last_match(1), Regexp.last_match(3) end - str.gsub! @org_angle_link_text_regexp do |match| - yield $1, nil + str.gsub! @org_angle_link_text_regexp do |_match| + yield Regexp.last_match(1), nil end str # for testing end - def restore_code_snippets str + def restore_code_snippets(str) str = str % @code_snippet_stack @code_snippet_stack = [] str end + def org_emphasis_regexp + Regexp.new("(#{pre_emphasis_regexp})" \ + "(#{markers_regexp})" \ + "(#{border_forbidden}|" \ + "#{border_forbidden}#{body_regexp}" \ + "#{border_forbidden})\\2" \ + "(?=#{post_emphasis})") + end + private - def build_org_emphasis_regexp - @org_emphasis_regexp = Regexp.new("([#{@pre_emphasis}]|^)" + - "([#{@markers}])(?!\\2)" + - "([^#{@border_forbidden}]|" + - "[^#{@border_forbidden}]#{@body_regexp}" + - "[^#{@border_forbidden}])\\2" + - "(?=[#{@post_emphasis}]|$)") - @logger.debug "Just created regexp: #{@org_emphasis_regexp}" + def pre_emphasis_regexp + '^|\s|[\(\'"\{]' + end + + def markers_regexp + '[\*\/_=~\+]' + end + + def border_forbidden + '\S' + end + + def post_emphasis + '\s|[-,\.;:!\?\'"\)\}]|$' + end + + def body_regexp + '.*?(?:\\n.*?){0,1}' end def build_org_link_regexp @@ -194,5 +203,5 @@ def build_org_link_regexp @org_angle_link_text_regexp = /<(\w+:[^\]\s<>]+)>/ @org_image_file_regexp = /\.(gif|jpe?g|p(?:bm|gm|n[gm]|pm)|svgz?|tiff?|x[bp]m)/i end - end # class Emphasis -end # module Orgmode + end +end diff --git a/spec/html_examples/emphasis.html b/spec/html_examples/emphasis.html index f837428..a4bc464 100644 --- a/spec/html_examples/emphasis.html +++ b/spec/html_examples/emphasis.html @@ -1,4 +1,5 @@

                Inline Formatting test for emphasis

                +

                Fix issue #48 ~/.bash and C-'

                Simple feature test

                bold

                italic

                diff --git a/spec/html_examples/emphasis.org b/spec/html_examples/emphasis.org index 5e06815..1421d71 100644 --- a/spec/html_examples/emphasis.org +++ b/spec/html_examples/emphasis.org @@ -1,4 +1,5 @@ * Inline Formatting test for emphasis +Fix issue [[https://github.com/wallyqs/org-ruby/issues/48][#48]] ~~/.bash~ and ~C-'~ ** Simple feature test *bold* @@ -9,7 +10,7 @@ ~verbatim~ -_underline_ +_underline_ +strikethrough+ @@ -231,112 +232,112 @@ end all.each {|e| puts e} #+end_example -*Starting the line here +*Starting the line here *and continuing here to close** -*Starting the line here +*Starting the line here /and continuing here to close/* -*Starting the line here +*Starting the line here =and continuing here to close=* -*Starting the line here +*Starting the line here ~and continuing here to close~* -*Starting the line here +*Starting the line here _and continuing here to close_* -*Starting the line here +*Starting the line here +and continuing here to close+* -/Starting the line here +/Starting the line here *and continuing here to close*/ -/Starting the line here +/Starting the line here /and continuing here to close// -/Starting the line here +/Starting the line here =and continuing here to close=/ -/Starting the line here +/Starting the line here ~and continuing here to close~/ -/Starting the line here +/Starting the line here _and continuing here to close_/ -/Starting the line here +/Starting the line here +and continuing here to close+/ -=Starting the line here +=Starting the line here *and continuing here to close*= -=Starting the line here +=Starting the line here /and continuing here to close/= -=Starting the line here +=Starting the line here =and continuing here to close== -=Starting the line here +=Starting the line here ~and continuing here to close~= -=Starting the line here +=Starting the line here _and continuing here to close_= -=Starting the line here +=Starting the line here +and continuing here to close+= -~Starting the line here +~Starting the line here *and continuing here to close*~ -~Starting the line here +~Starting the line here /and continuing here to close/~ -~Starting the line here +~Starting the line here =and continuing here to close=~ -~Starting the line here +~Starting the line here ~and continuing here to close~~ -~Starting the line here +~Starting the line here _and continuing here to close_~ -~Starting the line here +~Starting the line here +and continuing here to close+~ -_Starting the line here +_Starting the line here *and continuing here to close*_ -_Starting the line here +_Starting the line here /and continuing here to close/_ -_Starting the line here +_Starting the line here =and continuing here to close=_ -_Starting the line here +_Starting the line here ~and continuing here to close~_ -_Starting the line here +_Starting the line here _and continuing here to close__ -_Starting the line here +_Starting the line here +and continuing here to close+_ -+Starting the line here ++Starting the line here *and continuing here to close*+ -+Starting the line here ++Starting the line here /and continuing here to close/+ -+Starting the line here ++Starting the line here =and continuing here to close=+ -+Starting the line here ++Starting the line here ~and continuing here to close~+ -+Starting the line here ++Starting the line here _and continuing here to close_+ -+Starting the line here ++Starting the line here +and continuing here to close++ ** Multiline support test :: two lines @@ -353,147 +354,147 @@ end all.each {|e| puts e} #+end_example -*Starting the line here +*Starting the line here *and continuing here to close** -*Starting the line here +*Starting the line here /and continuing here to close/* -*Starting the line here +*Starting the line here =and continuing here to close=* -*Starting the line here +*Starting the line here ~and continuing here to close~* -*Starting the line here +*Starting the line here _and continuing here to close_* -*Starting the line here +*Starting the line here +and continuing here to close+* -/Starting the line here +/Starting the line here *and continuing here to close*/ -/Starting the line here +/Starting the line here /and continuing here to close// -/Starting the line here +/Starting the line here =and continuing here to close=/ -/Starting the line here +/Starting the line here ~and continuing here to close~/ -/Starting the line here +/Starting the line here _and continuing here to close_/ -/Starting the line here +/Starting the line here +and continuing here to close+/ -=Starting the line here +=Starting the line here *and continuing here to close*= -=Starting the line here +=Starting the line here /and continuing here to close/= -=Starting the line here +=Starting the line here =and continuing here to close== -=Starting the line here +=Starting the line here ~and continuing here to close~= -=Starting the line here +=Starting the line here _and continuing here to close_= -=Starting the line here +=Starting the line here +and continuing here to close+= -~Starting the line here +~Starting the line here *and continuing here to close*~ -~Starting the line here +~Starting the line here /and continuing here to close/~ -~Starting the line here +~Starting the line here =and continuing here to close=~ -~Starting the line here +~Starting the line here ~and continuing here to close~~ -~Starting the line here +~Starting the line here _and continuing here to close_~ -~Starting the line here +~Starting the line here +and continuing here to close+~ -_Starting the line here +_Starting the line here *and continuing here to close*_ -_Starting the line here +_Starting the line here /and continuing here to close/_ -_Starting the line here +_Starting the line here =and continuing here to close=_ -_Starting the line here +_Starting the line here ~and continuing here to close~_ -_Starting the line here +_Starting the line here _and continuing here to close__ -_Starting the line here +_Starting the line here +and continuing here to close+_ -+Starting the line here ++Starting the line here *and continuing here to close*+ -+Starting the line here ++Starting the line here /and continuing here to close/+ -+Starting the line here ++Starting the line here =and continuing here to close=+ -+Starting the line here ++Starting the line here ~and continuing here to close~+ -+Starting the line here ++Starting the line here _and continuing here to close_+ -+Starting the line here ++Starting the line here +and continuing here to close++ @@ -507,7 +508,7 @@ to close++ ~verbatim~ *bold* ~verbatim~ -_underline_ *bold* _underline_ +_underline_ *bold* _underline_ +strikethrough+ *bold* +strikethrough+ @@ -531,7 +532,7 @@ _underline_ *bold* _underline_ ~verbatim~ /italic/ ~verbatim~ -_underline_ /italic/ _underline_ +_underline_ /italic/ _underline_ +strikethrough+ /italic/ +strikethrough+ @@ -555,7 +556,7 @@ _underline_ /italic/ _underline_ ~verbatim~ =code= ~verbatim~ -_underline_ =code= _underline_ +_underline_ =code= _underline_ +strikethrough+ =code= +strikethrough+ @@ -579,7 +580,7 @@ _underline_ =code= _underline_ ~verbatim~ ~verbatim~ ~verbatim~ -_underline_ ~verbatim~ _underline_ +_underline_ ~verbatim~ _underline_ +strikethrough+ ~verbatim~ +strikethrough+ @@ -603,7 +604,7 @@ _underline_ ~verbatim~ _underline_ ~verbatim~ _underline_ ~verbatim~ -_underline_ _underline_ _underline_ +_underline_ _underline_ _underline_ +strikethrough+ _underline_ +strikethrough+ @@ -627,7 +628,7 @@ _underline_ _underline_ _underline_ ~verbatim~ +strikethrough+ ~verbatim~ -_underline_ +strikethrough+ _underline_ +_underline_ +strikethrough+ _underline_ +strikethrough+ +strikethrough+ +strikethrough+ @@ -651,7 +652,7 @@ _underline_ +strikethrough+ _underline_ ~verbatim~ [[http://www.bing.com]] ~verbatim~ -_underline_ [[http://www.bing.com]] _underline_ +_underline_ [[http://www.bing.com]] _underline_ +strikethrough+ [[http://www.bing.com]] +strikethrough+ @@ -675,7 +676,7 @@ _underline_ [[http://www.bing.com]] _underline_ ~verbatim~ [[http://www.google.com]] ~verbatim~ -_underline_ [[http://www.google.com]] _underline_ +_underline_ [[http://www.google.com]] _underline_ +strikethrough+ [[http://www.google.com]] +strikethrough+ @@ -699,7 +700,7 @@ _underline_ [[http://www.google.com]] _underline_ ~verbatim~ [[http://www.xkcd.com][helpful text link]] ~verbatim~ -_underline_ [[http://www.xkcd.com][helpful text link]] _underline_ +_underline_ [[http://www.xkcd.com][helpful text link]] _underline_ +strikethrough+ [[http://www.xkcd.com][helpful text link]] +strikethrough+ @@ -723,7 +724,7 @@ _underline_ [[http://www.xkcd.com][helpful text link]] _underline_ ~verbatim~ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] ~verbatim~ -_underline_ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] _underline_ +_underline_ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] _underline_ +strikethrough+ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] +strikethrough+ @@ -747,7 +748,7 @@ _underline_ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] _ ~verbatim~ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] ~verbatim~ -_underline_ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] _underline_ +_underline_ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] _underline_ +strikethrough+ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] +strikethrough+ @@ -771,7 +772,7 @@ _underline_ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] _u ~verbatim~ ~verbatim~ -_underline_ _underline_ +_underline_ _underline_ +strikethrough+ +strikethrough+ @@ -801,4 +802,3 @@ _underline_ _underline_ | *bold* [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | /italic/ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | =code= [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | ~verbatim~ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | _underline_ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | +strikethrough+ [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://www.bing.com]] [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://www.google.com]] [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://www.xkcd.com][helpful text link]] [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | | *bold* [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | /italic/ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | =code= [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | ~verbatim~ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | _underline_ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | +strikethrough+ [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://www.bing.com]] [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://www.google.com]] [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://www.xkcd.com][helpful text link]] [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | | *bold* | /italic/ | =code= | ~verbatim~ | _underline_ | +strikethrough+ | [[http://www.bing.com]] | [[http://www.google.com]] | [[http://www.xkcd.com][helpful text link]] | [[http://farm7.static.flickr.com/6078/6084185195_552aa270b2.jpg]] | [[http://www.xkcd.com][http://imgs.xkcd.com/comics/t_cells.png]] | | - diff --git a/spec/org-ruby/html_output_buffer_spec.rb b/spec/org-ruby/html_output_buffer_spec.rb index 88866d2..031a7db 100644 --- a/spec/org-ruby/html_output_buffer_spec.rb +++ b/spec/org-ruby/html_output_buffer_spec.rb @@ -26,7 +26,6 @@ module Orgmode end describe '#push_mode' do - xit 'calls super method' context 'when mode is a HtmlBlockTag' do let(:mode) { :paragraph } let(:indent) { :some_value } @@ -64,10 +63,6 @@ module Orgmode context 'when mode is src' do let(:mode) { :src } - context 'when Buffer options include skip_syntax_highligth = false' do - xit 'do not touch output buffer ' - end - context 'when Buffer options include skip_syntax_highlight = true' do let(:buffer) { Orgmode::HtmlOutputBuffer.new(output, { skip_syntax_highlight: true })} before(:each) do @@ -97,11 +92,6 @@ module Orgmode xcontext 'when tag is table' do end - xit 'add new line and indentation when runs for first time' do - buffer.push_mode(mode, indent) - expect(buffer.output).to match /\Z/ - end - context 'when called for second time' do before(:each) do buffer.push_mode(mode, indent) @@ -110,10 +100,9 @@ module Orgmode it 'does not add paragprah' do mode = :src buffer.push_mode(mode, 'indent') - expect(buffer.output).not_to match /\Z\n/ + expect(buffer.output).not_to match(/\Z\n/) end end - end end end From 1ca685cb0f552647303153858e59a2871961fa58 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sun, 14 Nov 2021 19:43:57 -0600 Subject: [PATCH 09/12] Inlcude brackets to emphasis regexp. Fix #85 --- lib/org-ruby/html_output_buffer.rb | 2 +- lib/org-ruby/regexp_helper.rb | 56 ++++++++++++++---------- spec/org-ruby/html_output_buffer_spec.rb | 3 -- spec/regexp_helper_spec.rb | 20 ++++++++- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 11b9317..7109998 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -319,7 +319,7 @@ def escape_string! str str.gsub! /@@html:(<[^<>\n]*>)@@/, "\\1" end - def quote_tags str + def quote_tags(str) str.gsub /(<[^<>\n]*>)/, "@@html:\\1@@" end diff --git a/lib/org-ruby/regexp_helper.rb b/lib/org-ruby/regexp_helper.rb index 57be200..a5abaf7 100644 --- a/lib/org-ruby/regexp_helper.rb +++ b/lib/org-ruby/regexp_helper.rb @@ -40,17 +40,11 @@ class RegexpHelper # non-shy groups here, and don't allow newline here. # newline The maximum number of newlines allowed in an emphasis exp. - attr_reader :org_image_file_regexp - def initialize # Set up the emphasis regular expression. @code_snippet_stack = [] @logger = Logger.new(STDERR) @logger.level = Logger::WARN - build_org_link_regexp - @org_subp_regexp = /([_^])\{(.*?)\}/ - @org_footnote_regexp = /\[fn:(.+?)(:(.*))?\]/ - @org_footnote_def_regexp = /^\[fn:(.+?)(:(.*))?\]( (.+))?/ end # Finds all emphasis matches in a string. @@ -102,21 +96,21 @@ def rewrite_emphasis(str) end # rewrite subscript and superscript (_{foo} and ^{bar}) - def rewrite_subp(str) # :yields: type ("_" for subscript and "^" for superscript), text - str.gsub! @org_subp_regexp do |_match| + def rewrite_subp(str) + str.gsub!(org_subp_regexp) do |_match| yield Regexp.last_match(1), Regexp.last_match(2) end end # rewrite footnotes - def rewrite_footnote(str) # :yields: name, definition or nil - str.gsub! @org_footnote_regexp do |_match| + def rewrite_footnote(str) + str.gsub!(org_footnote_regexp) do |_match| yield Regexp.last_match(1), Regexp.last_match(3) end end def rewrite_footnote_definition(str) - str.gsub! @org_footnote_def_regexp do |_match| + str.gsub!(org_footnote_def_regexp) do |_match| yield Regexp.last_match(1), Regexp.last_match(5) end end @@ -147,10 +141,10 @@ def rewrite_footnote_definition(str) # HTML-style link, and that is how things will get recorded in # +result+. def rewrite_links(str) - str.gsub! @org_link_regexp do |_match| - yield Regexp.last_match(1), Regexp.last_match(3) + str.gsub!(org_link_regexp) do |_match| + yield Regexp.last_match['url'], Regexp.last_match['friendly_text'] end - str.gsub! @org_angle_link_text_regexp do |_match| + str.gsub!(org_angle_link_text_regexp) do |_match| yield Regexp.last_match(1), nil end @@ -172,10 +166,18 @@ def org_emphasis_regexp "(?=#{post_emphasis})") end + def org_link_regexp + /\[\[(?[^\[\]]+)\](\[(?[^\[\]]+)\])?\]/x + end + + def org_image_file_regexp + /\.(gif|jpe?g|p(?:bm|gm|n[gm]|pm)|svgz?|tiff?|x[bp]m)/i + end + private def pre_emphasis_regexp - '^|\s|[\(\'"\{]' + '^|\s|[\(\'"\{\[]' end def markers_regexp @@ -187,21 +189,27 @@ def border_forbidden end def post_emphasis - '\s|[-,\.;:!\?\'"\)\}]|$' + '\s|[-,\.;:!\?\'"\)\}\]]|$' end def body_regexp '.*?(?:\\n.*?){0,1}' end - def build_org_link_regexp - @org_link_regexp = /\[\[ - ([^\]\[]+) # This is the URL - \](\[ - ([^\]\[]+) # This is the friendly text - \])?\]/x - @org_angle_link_text_regexp = /<(\w+:[^\]\s<>]+)>/ - @org_image_file_regexp = /\.(gif|jpe?g|p(?:bm|gm|n[gm]|pm)|svgz?|tiff?|x[bp]m)/i + def org_subp_regexp + /([_^])\{(.*?)\}/ + end + + def org_footnote_regexp + /\[fn:(.+?)(:(.*))?\]/ + end + + def org_footnote_def_regexp + /^\[fn:(.+?)(:(.*))?\]( (.+))?/ + end + + def org_angle_link_text_regexp + /<(\w+:[^\]\s<>]+)>/ end end end diff --git a/spec/org-ruby/html_output_buffer_spec.rb b/spec/org-ruby/html_output_buffer_spec.rb index 031a7db..5ead7e0 100644 --- a/spec/org-ruby/html_output_buffer_spec.rb +++ b/spec/org-ruby/html_output_buffer_spec.rb @@ -89,9 +89,6 @@ module Orgmode end end - xcontext 'when tag is table' do - end - context 'when called for second time' do before(:each) do buffer.push_mode(mode, indent) diff --git a/spec/regexp_helper_spec.rb b/spec/regexp_helper_spec.rb index 694405a..3e43dac 100644 --- a/spec/regexp_helper_spec.rb +++ b/spec/regexp_helper_spec.rb @@ -1,6 +1,24 @@ require 'spec_helper' describe Orgmode::RegexpHelper do + let(:helper) { Orgmode::RegexpHelper.new } + + describe '#org-emphasis-regexp' do + it 'match emphasis expresions' do + expect(helper.org_emphasis_regexp).to match '~code~' + end + example { expect(helper.org_emphasis_regexp).to match '[[a][~a~]]' } + end + + describe '#org-link-regexp' do + it 'match org-links' do + expect(helper.org_link_regexp).to match '[[url][description]]' + end + + example { expect(helper.org_link_regexp).to match '[[url]]' } + example { expect(helper.org_link_regexp).to match '[[a][~a~]]' } + end + it "should recognize simple markup" do e = Orgmode::RegexpHelper.new total = 0 @@ -73,4 +91,4 @@ expect(n).to eql("This string contains a quote using code markup: \"") end -end # describe Orgmode::RegexpHelper +end From ecd74738c0070863db2665570b3e28521473f654 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Mon, 22 Nov 2021 12:00:42 -0600 Subject: [PATCH 10/12] Refactor Output_buffer.rb --- lib/org-ruby/output_buffer.rb | 135 +++++++++++++++------------------- 1 file changed, 60 insertions(+), 75 deletions(-) diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb index 22e25d4..3f6e35d 100644 --- a/lib/org-ruby/output_buffer.rb +++ b/lib/org-ruby/output_buffer.rb @@ -1,13 +1,11 @@ require 'logger' module Orgmode - # The OutputBuffer is used to accumulate multiple lines of orgmode # text, and then emit them to the output all in one go. The class # will do the final textile substitution for inline formatting and # add a newline character prior emitting the output. class OutputBuffer - # This is the overall output buffer attr_reader :output, :mode_stack, :list_indent_stack @@ -34,32 +32,24 @@ def initialize(output) # regexp module @re_help = RegexpHelper.new @logger = Logger.new(STDERR) - if ENV['DEBUG'] || $DEBUG - @logger.level = Logger::DEBUG - else - @logger.level = Logger::WARN - end + @logger.level = Logger::INFO end def current_mode mode_stack.last end - def push_mode(mode, indent, properties={}) + def push_mode(mode, indent, _properties = {}) mode_stack.push(mode) # Here seem that inherit buffers do their magic. list_indent_stack.push(indent) end - def pop_mode(mode=nil) + def pop_mode(_mode = nil) mode_stack.pop end def insert(line) - # Prepares the output buffer to receive content from a line. - # As a side effect, this may flush the current accumulated text. - @logger.debug "Looking at #{line.paragraph_type}|#{line.assigned_paragraph_type}(#{current_mode}) : #{line.to_s}" - # We try to get the lang from #+BEGIN_SRC blocks @block_lang = line.block_lang if line.begin_block? unless should_accumulate_output?(line) @@ -77,42 +67,40 @@ def insert(line) def line_get_content(line) # Adds the current line to the output buffer case - when line.assigned_paragraph_type == :comment + when skip_buffer(line) # Don't add to buffer - "" + '' when line.title? line.output_text - when line.raw_text? - # This case is for html buffer, because buffer_tag is a method - if line.raw_text_tag == buffer_tag - "\n#{line.output_text}" - else - "" - end - when preserve_whitespace? - if line.block_type - "" - else - "\n#{line.output_text}" - end + when line.raw_text? && line.raw_text_tag != buffer_tag + '' + when line.raw_text? && line.raw_text_tag == buffer_tag + "\n#{line.output_text}" + when preserve_whitespace? && line.block_type + '' + when preserve_whitespace? && !line.block_type + "\n#{line.output_text}" when line.assigned_paragraph_type == :code # If the line is contained within a code block but we should # not preserve whitespaces, then we do nothing. - "" + '' when line.is_a?(Headline) add_line_attributes(line) "\n#{line.output_text.strip}" - when ([:definition_term, :list_item, :table_row, :table_header, - :horizontal_rule].include? line.paragraph_type) - + when %i[definition_term list_item table_row table_header + horizontal_rule].include?(line.paragraph_type) "\n#{line.output_text.strip}" when line.paragraph_type == :paragraph "\n""#{buffer_indentation}#{line.output_text.strip}" - else "" + else '' end end + def skip_buffer(line) + line.assigned_paragraph_type == :comment + end + def html_buffer_code_block_indent(line) # this is implemented in html output buffer only end @@ -124,14 +112,11 @@ def html_buffer_code_block_indent(line) def get_next_headline_number(level) raise "Headline level not valid: #{level}" if level <= 0 - while level > @headline_number_stack.length do - @headline_number_stack.push 0 - end - while level < @headline_number_stack.length do - @headline_number_stack.pop - end + @headline_number_stack.push(0) while level > @headline_number_stack.length + @headline_number_stack.pop while level < @headline_number_stack.length + @headline_number_stack[level - 1] += 1 - @headline_number_stack.join(".") + @headline_number_stack.join('.') end # Gets the current list indent level. @@ -141,11 +126,11 @@ def list_indent_level # Test if we're in an output mode in which whitespace is significant. def preserve_whitespace? - [:example, :inline_example, :raw_text, :src].include? current_mode + %i[example inline_example raw_text src].include? current_mode end def do_custom_markup - if File.exists? @options[:markup_file] + if File.exist?(@options[:markup_file]) load_custom_markup if @custom_blocktags.empty? no_valid_markup_found @@ -159,30 +144,35 @@ def do_custom_markup def load_custom_markup require 'yaml' - self.class.to_s == 'Orgmode::MarkdownOutputBuffer' ? filter = '^MarkdownMap$' : filter = '^HtmlBlockTag$|^Tags$' - @custom_blocktags = YAML.load_file(@options[:markup_file]).select {|k| k.to_s.match(filter) } + filter = if self.class.to_s == 'Orgmode::MarkdownOutputBuffer' + '^MarkdownMap$' + else + '^HtmlBlockTag$|^Tags$' + end + @custom_blocktags = YAML.load_file(@options[:markup_file]).select do |k| + k.to_s.match(filter) + end end def set_custom_markup - @custom_blocktags.keys.each do |k| - @custom_blocktags[k].each {|key,v| self.class.const_get(k.to_s)[key] = v if self.class.const_get(k.to_s).key? key} + @custom_blocktags.each_key do |k| + @custom_blocktags[k].each do |key, v| + self.class.const_get(k.to_s)[key] = v if self.class.const_get(k.to_s).key?(key) + end end end def no_valid_markup_found - self.class.to_s == 'Orgmode::MarkdownOutputBuffer' ? tags = 'MarkdownMap' : tags = 'HtmlBlockTag or Tags' - @logger.debug "Setting Custom Markup failed. No #{tags} key where found in: #{@options[:markup_file]}." - @logger.debug "Continuing export with default markup." + self.class.to_s == 'Orgmode::MarkdownOutputBuffer' ? 'MarkdownMap' : 'HtmlBlockTag or Tags' end def no_custom_markup_file_exists - @logger.debug "Setting Custom Markup failed. No such file exists: #{@options[:markup_file]}." - @logger.debug "Continuing export with default tags." + nil end protected - attr_reader :block_lang, :list_indent_stack + attr_reader :block_lang def indentation_level list_indent_stack.length - 1 @@ -197,16 +187,15 @@ def buffer_tag private def mode_is_heading?(mode) - [:heading1, :heading2, :heading3, - :heading4, :heading5, :heading6].include? mode + %i[heading1 heading2 heading3 heading4 heading5 heading6].include?(mode) end def mode_is_block?(mode) - [:quote, :center, :example, :src].include? mode + %i[quote center example src].include?(mode) end def mode_is_code?(mode) - [:example, :src].include? mode + %i[example src].include?(mode) end def boundary_of_block?(line) @@ -225,20 +214,17 @@ def maintain_mode_stack(line) current_mode == :raw_text) # End-block line closes every mode within block - if line.end_block? and @mode_stack.include? line.paragraph_type + if line.end_block? && @mode_stack.include?(line.paragraph_type) pop_mode until current_mode == line.paragraph_type end - if ((not line.paragraph_type == :blank) or - @output_type == :blank) + if line.paragraph_type != :blank || @output_type == :blank # Close previous tags on demand. Two blank lines close all tags. - while ((not @list_indent_stack.empty?) and - @list_indent_stack.last >= line.indent and - # Don't allow an arbitrary line to close block - (not mode_is_block? current_mode)) + while !@list_indent_stack.empty? && @list_indent_stack.last >= line.indent && + # Don't allow an arbitrary line to close block + !mode_is_block?(current_mode) # Item can't close its major mode - if (@list_indent_stack.last == line.indent and - line.major_mode == current_mode) + if @list_indent_stack.last == line.indent && line.major_mode == current_mode break else pop_mode @@ -247,14 +233,14 @@ def maintain_mode_stack(line) end # Special case: Only end-block line closes block - pop_mode if line.end_block? and line.paragraph_type == current_mode + pop_mode if line.end_block? && line.paragraph_type == current_mode - unless line.paragraph_type == :blank or line.assigned_paragraph_type == :comment - if (@list_indent_stack.empty? or - @list_indent_stack.last <= line.indent or - mode_is_block? current_mode) + unless line.paragraph_type == :blank || line.assigned_paragraph_type == :comment + if (@list_indent_stack.empty? || + @list_indent_stack.last <= line.indent || + mode_is_block?(current_mode)) # Opens the major mode of line if it exists - if @list_indent_stack.last != line.indent or mode_is_block? current_mode + if @list_indent_stack.last != line.indent || mode_is_block?(current_mode) push_mode(line.major_mode, line.indent, line.properties) if line.major_mode end # Opens tag that precedes text immediately @@ -309,10 +295,9 @@ def should_accumulate_output?(line) end def buffer_indentation - "" + '' end def flush!; false; end - def output_footnotes!; false; end - end # class OutputBuffer -end # module Orgmode + end +end From a855e99ffa98e39eb56700e14580b02cea0aab03 Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sun, 6 Mar 2022 15:59:23 -0600 Subject: [PATCH 11/12] Support right-to-left languages. Fix #60. This add 'dir="auto"' as a global attribute (all elements) when left_to_right option is set to 't'. It could be as a parser_option (when parser is created) or as a buffer option (with #+OPTIONS: left_to_right: t) --- lib/org-ruby/html_output_buffer.rb | 2 ++ lib/org-ruby/parser.rb | 9 ++++++++- spec/html_examples/left-to-right-with-dir.html | 6 ++++++ spec/html_examples/left-to-right-with-dir.org | 10 ++++++++++ spec/html_examples/left-to-right.html | 6 ++++++ spec/html_examples/left-to-right.org | 8 ++++++++ spec/parser_spec.rb | 13 +++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 spec/html_examples/left-to-right-with-dir.html create mode 100644 spec/html_examples/left-to-right-with-dir.org create mode 100644 spec/html_examples/left-to-right.html create mode 100644 spec/html_examples/left-to-right.org diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index 7109998..afae966 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -289,6 +289,8 @@ def get_css_attr(mode) " style=\"text-align: center\"" when @options[:decorate_title] " class=\"title\"" + when @options[:left_to_right] + " dir=\"auto\"" end end diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index 4572cfa..2bb13e5 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -44,6 +44,7 @@ def export_select_tags # that subtree will not get exported. def export_exclude_tags return Array.new unless @in_buffer_settings["EXPORT_EXCLUDE_TAGS"] + @in_buffer_settings["EXPORT_EXCLUDE_TAGS"].split end @@ -79,6 +80,11 @@ def use_sub_superscripts? @options["^"] != "nil" end + # Support for left to right when buffer or parser option. + def left_to_right? + @options["left_to_right"] == 't' || @parser_options[:left_to_right] + end + def initialize_lines(lines) return lines if lines.is_a? Array return lines.split("\n") if lines.is_a? String @@ -343,7 +349,8 @@ def to_html link_abbrevs: @link_abbrevs, skip_syntax_highlight: @parser_options[:skip_syntax_highlight], markup_file: @parser_options[:markup_file], - footnotes_title: @parser_options[:footnotes_title] + footnotes_title: @parser_options[:footnotes_title], + left_to_right: left_to_right? } export_options[:skip_tables] = true unless export_tables? output = '' diff --git a/spec/html_examples/left-to-right-with-dir.html b/spec/html_examples/left-to-right-with-dir.html new file mode 100644 index 0000000..bd43f54 --- /dev/null +++ b/spec/html_examples/left-to-right-with-dir.html @@ -0,0 +1,6 @@ +

                عنوان

                +

                فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى

                +

                عنوان فرعي

                +

                فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية

                +

                عنوان وكلمة أنجليزية english معه

                +

                فقرة تحتوي على كلمات أنجليزية (english words) فيها من ما يجعلها لا تظهر بشكل صحيح not correct rendering

                diff --git a/spec/html_examples/left-to-right-with-dir.org b/spec/html_examples/left-to-right-with-dir.org new file mode 100644 index 0000000..952a865 --- /dev/null +++ b/spec/html_examples/left-to-right-with-dir.org @@ -0,0 +1,10 @@ +#+OPTIONS: left_to_right:t + +* عنوان +فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى + +** عنوان فرعي +فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية + +* عنوان وكلمة أنجليزية english معه +فقرة تحتوي على كلمات أنجليزية (english words) فيها من ما يجعلها لا تظهر بشكل صحيح not correct rendering diff --git a/spec/html_examples/left-to-right.html b/spec/html_examples/left-to-right.html new file mode 100644 index 0000000..6a803ea --- /dev/null +++ b/spec/html_examples/left-to-right.html @@ -0,0 +1,6 @@ +

                عنوان

                +

                فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى

                +

                عنوان فرعي

                +

                فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية

                +

                عنوان وكلمة أنجليزية english معه

                +

                فقرة تحتوي على كلمات أنجليزية (english words) فيها من ما يجعلها لا تظهر بشكل صحيح not correct rendering

                diff --git a/spec/html_examples/left-to-right.org b/spec/html_examples/left-to-right.org new file mode 100644 index 0000000..2174feb --- /dev/null +++ b/spec/html_examples/left-to-right.org @@ -0,0 +1,8 @@ +* عنوان +فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى + +** عنوان فرعي +فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية فقرة ثانية + +* عنوان وكلمة أنجليزية english معه +فقرة تحتوي على كلمات أنجليزية (english words) فيها من ما يجعلها لا تظهر بشكل صحيح not correct rendering diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index af2207e..26f2cec 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -342,6 +342,19 @@ end end + describe "Left to right support by" do + base_dir = File.join(File.dirname(__FILE__), "html_examples") + org_file = File.join(base_dir, "left-to-right.org") + html_file = File.join(base_dir, "left-to-right-with-dir.html") + + it 'adds dir="auto" as global attribute' do + expected = IO.read(html_file) + parser = Orgmode::Parser.new(IO.read(org_file), :left_to_right => 't') + actual = parser.to_html + expect(actual).to eq(expected) + end + end + describe "Export to Markdown test cases" do data_directory = File.join(File.dirname(__FILE__), "markdown_examples") org_files = File.expand_path(File.join(data_directory, "*.org" )) From 01ae8c54854c895cbed84effef6b01784034269d Mon Sep 17 00:00:00 2001 From: Ricardo Arredondo Date: Sun, 13 Mar 2022 20:52:51 -0600 Subject: [PATCH 12/12] Rename left_to_right to ltr. Remove coderay and pygments gems. --- Gemfile | 8 -------- lib/org-ruby/html_output_buffer.rb | 2 +- lib/org-ruby/parser.rb | 4 ++-- spec/html_examples/left-to-right-with-dir.org | 2 +- spec/parser_spec.rb | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 74c6541..dc0928e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,11 +7,3 @@ group :development, :test do gem 'rspec', '>= 3' gem 'tilt' end - -group :coderay do - gem 'coderay' -end - -group :pygments do - gem 'pygments.rb' -end diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb index afae966..42d98df 100644 --- a/lib/org-ruby/html_output_buffer.rb +++ b/lib/org-ruby/html_output_buffer.rb @@ -289,7 +289,7 @@ def get_css_attr(mode) " style=\"text-align: center\"" when @options[:decorate_title] " class=\"title\"" - when @options[:left_to_right] + when @options[:ltr] " dir=\"auto\"" end end diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb index 2bb13e5..f9dc256 100644 --- a/lib/org-ruby/parser.rb +++ b/lib/org-ruby/parser.rb @@ -82,7 +82,7 @@ def use_sub_superscripts? # Support for left to right when buffer or parser option. def left_to_right? - @options["left_to_right"] == 't' || @parser_options[:left_to_right] + @options["ltr"] == 't' || @parser_options[:ltr] end def initialize_lines(lines) @@ -350,7 +350,7 @@ def to_html skip_syntax_highlight: @parser_options[:skip_syntax_highlight], markup_file: @parser_options[:markup_file], footnotes_title: @parser_options[:footnotes_title], - left_to_right: left_to_right? + ltr: left_to_right? } export_options[:skip_tables] = true unless export_tables? output = '' diff --git a/spec/html_examples/left-to-right-with-dir.org b/spec/html_examples/left-to-right-with-dir.org index 952a865..6763424 100644 --- a/spec/html_examples/left-to-right-with-dir.org +++ b/spec/html_examples/left-to-right-with-dir.org @@ -1,4 +1,4 @@ -#+OPTIONS: left_to_right:t +#+OPTIONS: ltr:t * عنوان فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى فقرة أولى diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 26f2cec..965ef7b 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -349,7 +349,7 @@ it 'adds dir="auto" as global attribute' do expected = IO.read(html_file) - parser = Orgmode::Parser.new(IO.read(org_file), :left_to_right => 't') + parser = Orgmode::Parser.new(IO.read(org_file), :ltr => 't') actual = parser.to_html expect(actual).to eq(expected) end