summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-01-20 22:30:42 -0700
committerDan Allen <dan.j.allen@gmail.com>2014-01-20 22:30:42 -0700
commit8915b4614fac4e9e82e9478bfb30640cc421dc05 (patch)
tree24efa9e7b6bfb8443b4fce9fcbc3bf615d2588a3
parenta83061aeeebbbc174af311bc535dab97e8666bee (diff)
Opal compatibility fixes
-rwxr-xr-xlib/asciidoctor.rb4
-rw-r--r--lib/asciidoctor/backends/html5.rb4
-rw-r--r--lib/asciidoctor/renderer.rb2
-rw-r--r--lib/asciidoctor/substitutors.rb7
-rw-r--r--test/lists_test.rb10
5 files changed, 19 insertions, 8 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index 6d347e20..75289b4a 100755
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -927,7 +927,9 @@ module Asciidoctor
# +
# Foo +
#
- LineBreakRx = /^(.*)#{CC_BLANK}\+#{CC_EOL}/
+ # NOTE: JavaScript only treats ^ and $ as line boundaries in multiline regexp
+ #LineBreakRx = /^(.*)[[:blank:]]\+$/
+ LineBreakRx = ::RUBY_ENGINE_OPAL ? %x(/^(.*?)[ \\t]\\+$/m) : %r{^(.*)[[:blank:]]\+$}
# Matches an AsciiDoc horizontal rule or AsciiDoc page break.
#
diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb
index eca540a6..0a62fe05 100644
--- a/lib/asciidoctor/backends/html5.rb
+++ b/lib/asciidoctor/backends/html5.rb
@@ -426,9 +426,9 @@ class BlockDlistTemplate < BaseTemplate
result_buffer << '<table>'
if (node.attr? 'labelwidth') || (node.attr? 'itemwidth')
result_buffer << '<colgroup>'
- col_style_attribute = (node.attr? 'labelwidth') ? %( style="width:#{(node.attr 'labelwidth').chomp '%'}%;") : nil
+ col_style_attribute = (node.attr? 'labelwidth') ? %( style="width: #{(node.attr 'labelwidth').chomp '%'}%;") : nil
result_buffer << %(<col#{col_style_attribute}#{short_tag_slash_local}>)
- col_style_attribute = (node.attr? 'itemwidth') ? %( style="width:#{(node.attr 'itemwidth').chomp '%'}%;") : nil
+ col_style_attribute = (node.attr? 'itemwidth') ? %( style="width: #{(node.attr 'itemwidth').chomp '%'}%;") : nil
result_buffer << %(<col#{col_style_attribute}#{short_tag_slash_local}>)
result_buffer << '</colgroup>'
end
diff --git a/lib/asciidoctor/renderer.rb b/lib/asciidoctor/renderer.rb
index c7a7feb5..7944c989 100644
--- a/lib/asciidoctor/renderer.rb
+++ b/lib/asciidoctor/renderer.rb
@@ -176,7 +176,7 @@ class Renderer
end
if name == 'erb'
- # autoload erb and return constant
+ Helpers.require_library 'erb'
::ERB
elsif name == 'erubis'
Helpers.require_library 'erubis'
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 51ad1c0e..17d9095b 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -12,6 +12,8 @@ module Substitutors
SPECIAL_CHARS_PATTERN = /[#{SPECIAL_CHARS.keys.join}]/
+ USE_GSUB_RESULT_HASH = ::RUBY_MIN_VERSION_1_9 && !::RUBY_ENGINE_OPAL
+
SUBS = {
:basic => [:specialcharacters],
:normal => [:specialcharacters, :quotes, :attributes, :replacements, :macros, :post_replacements],
@@ -243,7 +245,7 @@ module Substitutors
#
# returns The String text with special characters replaced
def sub_specialcharacters(text)
- ::RUBY_MIN_VERSION_1_9 ?
+ USE_GSUB_RESULT_HASH ?
text.gsub(SPECIAL_CHARS_PATTERN, SPECIAL_CHARS) :
text.gsub(SPECIAL_CHARS_PATTERN) { SPECIAL_CHARS[$&] }
end
@@ -616,7 +618,8 @@ module Substitutors
m = $~
# honor the escape
if m[2].start_with? '\\'
- next %(#{m[1]}#{m[2][1..-1]}#{m[3]})
+ # NOTE Opal doesn't like %() as an enclosure around this string
+ next "#{m[1]}#{m[2][1..-1]}#{m[3]}"
# not a valid macro syntax w/o trailing square brackets
# we probably shouldn't even get here...our regex is doing too much
elsif m[1] == 'link:' && !m[3]
diff --git a/test/lists_test.rb b/test/lists_test.rb
index 07844772..1c2de4ad 100644
--- a/test/lists_test.rb
+++ b/test/lists_test.rb
@@ -2448,8 +2448,8 @@ term:: def
assert_css 'table', output, 1
assert_css 'table > colgroup', output, 1
assert_css 'table > colgroup > col', output, 2
- assert_xpath '(//table/colgroup/col)[1][@style="width:25%;"]', output, 1
- assert_xpath '(//table/colgroup/col)[2][@style="width:75%;"]', output, 1
+ assert_xpath '(//table/colgroup/col)[1][@style="width: 25%;"]', output, 1
+ assert_xpath '(//table/colgroup/col)[2][@style="width: 75%;"]', output, 1
end
test 'should set col widths of item and label in docbook if specified' do
@@ -2540,6 +2540,8 @@ Question 1::
Answer 1.
Question 2::
Answer 2.
++
+NOTE: A note about Answer 2.
EOS
output = render_embedded_string input
assert_css '.qlist.qanda', output, 1
@@ -2552,6 +2554,7 @@ Question 2::
assert_css ".qanda > ol > li:nth-child(#{idx}) > p:last-child > *", output, 0
assert_xpath "/*[@class = 'qlist qanda']/ol/li[#{idx}]/p[2][normalize-space(text()) = 'Answer #{idx}.']", output, 1
end
+ assert_xpath "/*[@class = 'qlist qanda']/ol/li[2]/p[2]/following-sibling::div[@class='admonitionblock note']", output, 1
end
test 'should render qanda list in DocBook with proper semantics' do
@@ -2561,6 +2564,8 @@ Question 1::
Answer 1.
Question 2::
Answer 2.
++
+NOTE: A note about Answer 2.
EOS
output = render_embedded_string input, :backend => 'docbook'
assert_css 'qandaset', output, 1
@@ -2573,6 +2578,7 @@ Question 2::
assert_css "qandaset > qandaentry:nth-child(#{idx}) > answer > simpara", output, 1
assert_xpath "/qandaset/qandaentry[#{idx}]/answer/simpara[normalize-space(text()) = 'Answer #{idx}.']", output, 1
end
+ assert_xpath "/qandaset/qandaentry[2]/answer/simpara/following-sibling::note", output, 1
end
test 'consecutive questions should share same question element in docbook' do