summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/asciidoctor.rb20
-rw-r--r--lib/asciidoctor/lexer.rb2
-rw-r--r--lib/asciidoctor/renderer.rb2
-rw-r--r--lib/asciidoctor/substitutors.rb73
4 files changed, 60 insertions, 37 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index 8779ca05..d2046372 100755
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -54,7 +54,7 @@ $:.unshift(File.dirname __FILE__)
# end
module Asciidoctor
- unless RUBY_ENGINE_OPAL
+ unless ::RUBY_ENGINE_OPAL
# .chomp keeps Opal from trying to load the library
::Object.autoload :Base64, 'base64'.chomp
::Object.autoload :ERB, 'erb'.chomp
@@ -186,13 +186,13 @@ module Asciidoctor
ROOT_PATH = ::File.dirname LIB_PATH
# The user's home directory, as best we can determine it
- USER_HOME = RUBY_VERSION >= '1.9' ? ::Dir.home : ENV['HOME']
+ USER_HOME = ::RUBY_VERSION >= '1.9' ? ::Dir.home : ENV['HOME']
# Flag to indicate whether encoding can be coerced to UTF-8
# _All_ input data must be force encoded to UTF-8 if Encoding.default_external is *not* UTF-8
# Addresses failures performing string operations that are reported as "invalid byte sequence in US-ASCII"
# Ruby 1.8 doesn't seem to experience this problem (perhaps because it isn't validating the encodings)
- COERCE_ENCODING = !RUBY_ENGINE_OPAL && RUBY_VERSION >= '1.9'
+ COERCE_ENCODING = !::RUBY_ENGINE_OPAL && ::RUBY_VERSION >= '1.9'
# Flag to indicate whether encoding of external strings needs to be forced to UTF-8
FORCE_ENCODING = COERCE_ENCODING && ::Encoding.default_external != ::Encoding::UTF_8
@@ -204,7 +204,7 @@ module Asciidoctor
BOM_BYTES_UTF_16BE = "\xfe\xff".bytes.to_a
# Flag to indicate that line length should be calculated using a unicode mode hint
- FORCE_UNICODE_LINE_LENGTH = RUBY_VERSION < '1.9'
+ FORCE_UNICODE_LINE_LENGTH = ::RUBY_VERSION < '1.9'
# The endline character to use when rendering output
EOL = "\n"
@@ -340,7 +340,7 @@ module Asciidoctor
FLEXIBLE_ATTRIBUTES = %w(numbered)
# Regular expression character classes (dependent on regexp engine)
- if RUBY_ENGINE_OPAL
+ if ::RUBY_ENGINE_OPAL
CC_ALPHA = 'a-zA-Z'
CC_ALNUM = 'a-zA-Z0-9'
CC_BLANK = '[ \t]'
@@ -361,9 +361,9 @@ module Asciidoctor
# See http://www.aivosto.com/vbtips/control-characters.html#listabout for characters to use
PASS_PLACEHOLDER = {
# SPA, start of guarded protected area
- :start => RUBY_ENGINE_OPAL ? 150.chr : "\u0096",
+ :start => ::RUBY_ENGINE_OPAL ? 150.chr : "\u0096",
# EPA, end of guarded protected area
- :end => RUBY_ENGINE_OPAL ? 151.chr : "\u0097",
+ :end => ::RUBY_ENGINE_OPAL ? 151.chr : "\u0097",
# match placeholder record
:match => /\u0096(\d+)\u0097/,
# fix placeholder record after syntax highlighting
@@ -850,7 +850,7 @@ module Asciidoctor
end
attrs = (options[:attributes] ||= {})
- if attrs.is_a?(::Hash) || (RUBY_ENGINE_JRUBY && attrs.is_a?(::Java::JavaUtil::Map))
+ if attrs.is_a?(::Hash) || (::RUBY_ENGINE_JRUBY && attrs.is_a?(::Java::JavaUtil::Map))
# all good; placed here as optimization
elsif attrs.is_a? ::Array
attrs = options[:attributes] = attrs.inject({}) do |accum, entry|
@@ -1108,7 +1108,7 @@ module Asciidoctor
end
# autoload
- unless RUBY_ENGINE_OPAL
+ unless ::RUBY_ENGINE_OPAL
autoload :Debug, 'asciidoctor/debug'
autoload :VERSION, 'asciidoctor/version'
end
@@ -1136,7 +1136,7 @@ module Asciidoctor
require 'asciidoctor/table'
# backends
- if RUBY_ENGINE_OPAL
+ if ::RUBY_ENGINE_OPAL
require 'asciidoctor/backends/html5-erb'
end
end
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index 7da5fe42..967d0ddd 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -1897,7 +1897,7 @@ class Lexer
end
author_metadata[key_map[:email]] = segments[3] unless names_only || segments[3].nil?
else
- author_metadata[key_map[:author]] = author_metadata[key_map[:firstname]] = fname = author_entry.strip.squeeze(' ')
+ author_metadata[key_map[:author]] = author_metadata[key_map[:firstname]] = fname = author_entry.strip.tr_s(' ', ' ')
author_metadata[key_map[:authorinitials]] = fname[0, 1]
end
diff --git a/lib/asciidoctor/renderer.rb b/lib/asciidoctor/renderer.rb
index d4b48682..7ce8dfc8 100644
--- a/lib/asciidoctor/renderer.rb
+++ b/lib/asciidoctor/renderer.rb
@@ -22,7 +22,7 @@ class Renderer
@cache = nil
backend = options[:backend]
- if RUBY_ENGINE_OPAL
+ if ::RUBY_ENGINE_OPAL
::Template.instance_variable_get('@_cache').each do |path, tmpl|
@views[(File.basename path)] = tmpl
end
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 1c31d497..23edacb9 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -251,10 +251,18 @@ module Substitutors
#
# returns The String text with quoted text rendered using the backend templates
def sub_quotes(text)
- result = text.dup
- QUOTE_SUBS.each {|type, scope, pattern|
- result.gsub!(pattern) { transform_quoted_text($~, type, scope) }
- }
+ if ::RUBY_ENGINE_OPAL
+ result = text
+ QUOTE_SUBS.each {|type, scope, pattern|
+ result = result.gsub(pattern) { transform_quoted_text $~, type, scope }
+ }
+ else
+ # Use gsub! as optimization
+ result = text.dup
+ QUOTE_SUBS.each {|type, scope, pattern|
+ result.gsub!(pattern) { transform_quoted_text $~, type, scope }
+ }
+ end
result
end
@@ -265,29 +273,44 @@ module Substitutors
#
# returns The String text with the replacement characters substituted
def sub_replacements(text)
- result = text.dup
- REPLACEMENTS.each {|pattern, replacement, restore|
- result.gsub!(pattern) {
- m = $~
- matched = $&
- if matched.include?('\\')
- matched.tr('\\', '')
- else
- case restore
- when :none
- replacement
- when :leading
- "#{m[1]}#{replacement}"
- when :bounding
- "#{m[1]}#{replacement}#{m[2]}"
- end
- end
+ if ::RUBY_ENGINE_OPAL
+ result = text
+ REPLACEMENTS.each {|pattern, replacement, restore|
+ result = result.gsub(pattern) {
+ do_replacement $~, replacement, restore
+ }
}
- }
+ else
+ # Use gsub! as optimization
+ result = text.dup
+ REPLACEMENTS.each {|pattern, replacement, restore|
+ result.gsub!(pattern) {
+ do_replacement $~, replacement, restore
+ }
+ }
+ end
result
end
+ # Internal: Substitute replacement text for matched location
+ #
+ # returns The String text with the replacement characters substituted
+ def do_replacement m, replacement, restore
+ if (matched = m[0]).include? '\\'
+ matched.tr '\\', ''
+ else
+ case restore
+ when :none
+ replacement
+ when :leading
+ "#{m[1]}#{replacement}"
+ when :bounding
+ "#{m[1]}#{replacement}#{m[2]}"
+ end
+ end
+ end
+
# Public: Substitute attribute references
#
# Attribute references are in the format +{name}+.
@@ -815,13 +838,13 @@ module Substitutors
if m[0].start_with? '\\'
next m[0][1..-1]
end
- if m[1].nil? || (RUBY_ENGINE_OPAL && m[1].to_s == '')
+ if m[1].nil? || (::RUBY_ENGINE_OPAL && m[1].to_s == '')
id = m[2]
reftext = !m[3].empty? ? m[3] : nil
else
id, reftext = m[1].split(',', 2).map(&:strip)
- id = id.sub(REGEXP[:dbl_quoted], RUBY_ENGINE_OPAL ? '$2' : '\2')
- reftext = reftext.sub(REGEXP[:m_dbl_quoted], RUBY_ENGINE_OPAL ? '$2' : '\2') unless reftext.nil?
+ id = id.sub(REGEXP[:dbl_quoted], ::RUBY_ENGINE_OPAL ? '$2' : '\2')
+ reftext = reftext.sub(REGEXP[:m_dbl_quoted], ::RUBY_ENGINE_OPAL ? '$2' : '\2') unless reftext.nil?
end
if id.include? '#'