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