summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-02-10 03:39:52 -0700
committerGitHub <noreply@github.com>2019-02-10 03:39:52 -0700
commitc55fc9fea20d57f14e9552073dab5a27a4728f71 (patch)
treeed57ea951b139345ad2e29ad3e57c4c4e2613b03
parentb6a5b14f74ca75491d395d40ed455969e644a1a0 (diff)
resolves #3054 never mutate strings; add `frozen_string_literal: true` comment to source files (PR #3055)
- replace gsub! and sub! with gsub and sub, respectively - add `frozen_string_literal: true` magic comment to all Ruby source files - see https://www.mikeperham.com/2018/02/28/ruby-optimization-with-one-magic-comment/
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--Rakefile1
-rwxr-xr-xbin/asciidoctor1
-rw-r--r--features/step_definitions.rb1
-rw-r--r--lib/asciidoctor.rb1
-rw-r--r--lib/asciidoctor/abstract_block.rb1
-rw-r--r--lib/asciidoctor/abstract_node.rb1
-rw-r--r--lib/asciidoctor/attribute_list.rb1
-rw-r--r--lib/asciidoctor/block.rb1
-rw-r--r--lib/asciidoctor/callouts.rb1
-rw-r--r--lib/asciidoctor/cli.rb1
-rw-r--r--lib/asciidoctor/cli/invoker.rb1
-rw-r--r--lib/asciidoctor/cli/options.rb1
-rw-r--r--lib/asciidoctor/converter.rb6
-rw-r--r--lib/asciidoctor/converter/composite.rb1
-rw-r--r--lib/asciidoctor/converter/docbook5.rb1
-rw-r--r--lib/asciidoctor/converter/html5.rb1
-rw-r--r--lib/asciidoctor/converter/manpage.rb1
-rw-r--r--lib/asciidoctor/converter/template.rb1
-rw-r--r--lib/asciidoctor/core_ext.rb1
-rw-r--r--lib/asciidoctor/core_ext/float/truncate.rb1
-rw-r--r--lib/asciidoctor/core_ext/match_data/names.rb1
-rw-r--r--lib/asciidoctor/core_ext/nil_or_empty.rb1
-rw-r--r--lib/asciidoctor/core_ext/regexp/is_match.rb1
-rw-r--r--lib/asciidoctor/document.rb1
-rw-r--r--lib/asciidoctor/extensions.rb2
-rw-r--r--lib/asciidoctor/helpers.rb1
-rw-r--r--lib/asciidoctor/inline.rb1
-rw-r--r--lib/asciidoctor/list.rb1
-rw-r--r--lib/asciidoctor/logging.rb1
-rw-r--r--lib/asciidoctor/parser.rb12
-rw-r--r--lib/asciidoctor/path_resolver.rb1
-rw-r--r--lib/asciidoctor/reader.rb1
-rw-r--r--lib/asciidoctor/rouge_ext.rb1
-rw-r--r--lib/asciidoctor/section.rb1
-rw-r--r--lib/asciidoctor/stylesheets.rb1
-rw-r--r--lib/asciidoctor/substitutors.rb69
-rw-r--r--lib/asciidoctor/syntax_highlighter.rb8
-rw-r--r--lib/asciidoctor/syntax_highlighter/coderay.rb1
-rw-r--r--lib/asciidoctor/syntax_highlighter/highlightjs.rb1
-rw-r--r--lib/asciidoctor/syntax_highlighter/html_pipeline.rb1
-rw-r--r--lib/asciidoctor/syntax_highlighter/prettify.rb1
-rw-r--r--lib/asciidoctor/syntax_highlighter/pygments.rb1
-rw-r--r--lib/asciidoctor/syntax_highlighter/rouge.rb1
-rw-r--r--lib/asciidoctor/table.rb1
-rw-r--r--lib/asciidoctor/timings.rb1
-rw-r--r--lib/asciidoctor/version.rb1
-rw-r--r--lib/asciidoctor/writer.rb1
-rw-r--r--test/api_test.rb1
-rw-r--r--test/attribute_list_test.rb1
-rw-r--r--test/attributes_test.rb5
-rw-r--r--test/blocks_test.rb1
-rw-r--r--test/converter_test.rb1
-rw-r--r--test/document_test.rb1
-rw-r--r--test/extensions_test.rb1
-rw-r--r--test/invoker_test.rb1
-rw-r--r--test/links_test.rb1
-rw-r--r--test/lists_test.rb1
-rw-r--r--test/logger_test.rb1
-rw-r--r--test/manpage_test.rb1
-rw-r--r--test/options_test.rb1
-rw-r--r--test/paragraphs_test.rb1
-rw-r--r--test/parser_test.rb1
-rw-r--r--test/paths_test.rb1
-rw-r--r--test/preamble_test.rb1
-rw-r--r--test/reader_test.rb5
-rw-r--r--test/sections_test.rb1
-rw-r--r--test/substitutions_test.rb1
-rw-r--r--test/syntax_highlighter_test.rb1
-rw-r--r--test/tables_test.rb1
-rw-r--r--test/test_helper.rb1
-rw-r--r--test/text_test.rb1
72 files changed, 110 insertions, 62 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 5b908899..278c8fc9 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -63,6 +63,7 @@ Improvements::
* don't store the options attribute on the block once the options are parsed (#3051)
* add an options method on AbstractNode to retrieve the set of option names (#3051)
* pass :input_mtime option to Document constructor; let Document constructor assign docdate/time/year attributes (#3029)
+ * never mutate strings; add a `frozen_string_literal: true` magic comment to top of all Ruby source files (#3054)
Bug Fixes::
diff --git a/Rakefile b/Rakefile
index 5bff7d4a..799331a2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
def prepare_test_env
# rather than hardcoding gc settings in test task,
# could use https://gist.github.com/benders/788695
diff --git a/bin/asciidoctor b/bin/asciidoctor
index b01aaefb..ef635cfd 100755
--- a/bin/asciidoctor
+++ b/bin/asciidoctor
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
asciidoctor = File.absolute_path '../lib/asciidoctor.rb', __dir__
if File.exist? asciidoctor
diff --git a/features/step_definitions.rb b/features/step_definitions.rb
index ebaa9bac..e7aad806 100644
--- a/features/step_definitions.rb
+++ b/features/step_definitions.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
ASCIIDOCTOR_FEATURES_DIR = File.absolute_path __dir__
ASCIIDOCTOR_LIB_DIR = ENV['ASCIIDOCTOR_LIB_DIR'] || File.join(ASCIIDOCTOR_FEATURES_DIR, '../lib')
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index bc956b96..64312640 100644
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'set'
# NOTE RUBY_ENGINE == 'opal' conditional blocks like this are filtered by the Opal preprocessor
diff --git a/lib/asciidoctor/abstract_block.rb b/lib/asciidoctor/abstract_block.rb
index 18d06274..555c38a6 100644
--- a/lib/asciidoctor/abstract_block.rb
+++ b/lib/asciidoctor/abstract_block.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class AbstractBlock < AbstractNode
# Public: Get the Array of Asciidoctor::AbstractBlock sub-blocks for this block
diff --git a/lib/asciidoctor/abstract_node.rb b/lib/asciidoctor/abstract_node.rb
index 39202e01..bb173d88 100644
--- a/lib/asciidoctor/abstract_node.rb
+++ b/lib/asciidoctor/abstract_node.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: An abstract base class that provides state and methods for managing a
# node of AsciiDoc content. The state and methods on this class are common to
diff --git a/lib/asciidoctor/attribute_list.rb b/lib/asciidoctor/attribute_list.rb
index 92bad194..c9f1f57b 100644
--- a/lib/asciidoctor/attribute_list.rb
+++ b/lib/asciidoctor/attribute_list.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Handles parsing AsciiDoc attribute lists into a Hash of key/value
# pairs. By default, attributes must each be separated by a comma and quotes
diff --git a/lib/asciidoctor/block.rb b/lib/asciidoctor/block.rb
index 78fc4bc0..9fad2f65 100644
--- a/lib/asciidoctor/block.rb
+++ b/lib/asciidoctor/block.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods for managing blocks of Asciidoc content in a section.
#
diff --git a/lib/asciidoctor/callouts.rb b/lib/asciidoctor/callouts.rb
index 0ce7287a..65c2d359 100644
--- a/lib/asciidoctor/callouts.rb
+++ b/lib/asciidoctor/callouts.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Maintains a catalog of callouts and their associations.
class Callouts
diff --git a/lib/asciidoctor/cli.rb b/lib/asciidoctor/cli.rb
index f666b4e9..045bb9b8 100644
--- a/lib/asciidoctor/cli.rb
+++ b/lib/asciidoctor/cli.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'optparse'
require_relative 'cli/options'
require_relative 'cli/invoker'
diff --git a/lib/asciidoctor/cli/invoker.rb b/lib/asciidoctor/cli/invoker.rb
index ed80d701..7bbc080b 100644
--- a/lib/asciidoctor/cli/invoker.rb
+++ b/lib/asciidoctor/cli/invoker.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
module Cli
# Public Invocation class for starting Asciidoctor via CLI
diff --git a/lib/asciidoctor/cli/options.rb b/lib/asciidoctor/cli/options.rb
index d30fe884..1c699dc8 100644
--- a/lib/asciidoctor/cli/options.rb
+++ b/lib/asciidoctor/cli/options.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
module Cli
FS = '/'
diff --git a/lib/asciidoctor/converter.rb b/lib/asciidoctor/converter.rb
index 91063c70..91703a29 100644
--- a/lib/asciidoctor/converter.rb
+++ b/lib/asciidoctor/converter.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A module for defining converters that are used to convert {AbstractNode} objects in a parsed AsciiDoc document to an
# output (aka backend) format such as HTML or DocBook.
@@ -182,9 +183,8 @@ module Converter
default.create backend, opts
end
- # Public: Register a custom converter with this factory to handle conversion to the specified backends. If the
- # backend value is an asterisk (i.e., +*+), the converter is used as a catch all to handle any backend for which a
- # converter is not registered.
+ # Public: Register a custom converter with this factory to handle conversion for the specified backends. If the
+ # backend is an asterisk (i.e., +*+), the converter will handle any backend for which a converter is not registered.
#
# converter - The Converter class to register.
# backends - One or more String backend names that this converter should be registered to handle.
diff --git a/lib/asciidoctor/converter/composite.rb b/lib/asciidoctor/converter/composite.rb
index 9aa927d2..610e91d2 100644
--- a/lib/asciidoctor/converter/composite.rb
+++ b/lib/asciidoctor/converter/composite.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A {Converter} implementation that delegates to the chain of {Converter}
# objects passed to the constructor. Selects the first {Converter} that
diff --git a/lib/asciidoctor/converter/docbook5.rb b/lib/asciidoctor/converter/docbook5.rb
index 80743a31..86569f28 100644
--- a/lib/asciidoctor/converter/docbook5.rb
+++ b/lib/asciidoctor/converter/docbook5.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A built-in {Converter} implementation that generates DocBook 5 output. The output is inspired by the output produced
# by the docbook45 backend from AsciiDoc Python, except it has been migrated to the DocBook 5 specification.
diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb
index 37e6949f..3bdc9f7e 100644
--- a/lib/asciidoctor/converter/html5.rb
+++ b/lib/asciidoctor/converter/html5.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A built-in {Converter} implementation that generates HTML 5 output
# consistent with the html5 backend from AsciiDoc Python.
diff --git a/lib/asciidoctor/converter/manpage.rb b/lib/asciidoctor/converter/manpage.rb
index d0ccfe58..f835a617 100644
--- a/lib/asciidoctor/converter/manpage.rb
+++ b/lib/asciidoctor/converter/manpage.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A built-in {Converter} implementation that generates the man page (troff) format.
#
diff --git a/lib/asciidoctor/converter/template.rb b/lib/asciidoctor/converter/template.rb
index 78958ceb..8d5bd971 100644
--- a/lib/asciidoctor/converter/template.rb
+++ b/lib/asciidoctor/converter/template.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A {Converter} implementation that uses templates composed in template
# languages supported by {https://github.com/rtomayko/tilt Tilt} to convert
diff --git a/lib/asciidoctor/core_ext.rb b/lib/asciidoctor/core_ext.rb
index c5a570dd..76a0fa00 100644
--- a/lib/asciidoctor/core_ext.rb
+++ b/lib/asciidoctor/core_ext.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'core_ext/float/truncate'
require_relative 'core_ext/match_data/names' if RUBY_ENGINE == 'opal'
require_relative 'core_ext/nil_or_empty'
diff --git a/lib/asciidoctor/core_ext/float/truncate.rb b/lib/asciidoctor/core_ext/float/truncate.rb
index 96662aa9..5fca64e5 100644
--- a/lib/asciidoctor/core_ext/float/truncate.rb
+++ b/lib/asciidoctor/core_ext/float/truncate.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# NOTE remove once minimum required Ruby version is at least 2.4
Float.prepend(Module.new do
def truncate *args
diff --git a/lib/asciidoctor/core_ext/match_data/names.rb b/lib/asciidoctor/core_ext/match_data/names.rb
index 7656a705..ee61e077 100644
--- a/lib/asciidoctor/core_ext/match_data/names.rb
+++ b/lib/asciidoctor/core_ext/match_data/names.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# NOTE remove once implemented in Opal
class MatchData
def names
diff --git a/lib/asciidoctor/core_ext/nil_or_empty.rb b/lib/asciidoctor/core_ext/nil_or_empty.rb
index 6c56f958..bed6f5fc 100644
--- a/lib/asciidoctor/core_ext/nil_or_empty.rb
+++ b/lib/asciidoctor/core_ext/nil_or_empty.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# A core library extension that defines the method nil_or_empty? as an alias to
# optimize checks for nil? or empty? on common object types such as NilClass,
# String, Array, Hash, and Numeric.
diff --git a/lib/asciidoctor/core_ext/regexp/is_match.rb b/lib/asciidoctor/core_ext/regexp/is_match.rb
index 36bdde73..44edd567 100644
--- a/lib/asciidoctor/core_ext/regexp/is_match.rb
+++ b/lib/asciidoctor/core_ext/regexp/is_match.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
# NOTE remove once minimum required Ruby version is at least 2.4
class Regexp
alias match? ===
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index 41f305b9..bad2ae1b 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: The Document class represents a parsed AsciiDoc document.
#
diff --git a/lib/asciidoctor/extensions.rb b/lib/asciidoctor/extensions.rb
index 7cb250e2..72601ee4 100644
--- a/lib/asciidoctor/extensions.rb
+++ b/lib/asciidoctor/extensions.rb
@@ -1,4 +1,4 @@
-# allow `require 'asciidoctor/extensions'` to be used to fully load asciidoctor gem
+# frozen_string_literal: true
(require 'asciidoctor' unless defined? Asciidoctor.load) unless RUBY_ENGINE == 'opal'
module Asciidoctor
diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb
index e5dd9265..3fefd5eb 100644
--- a/lib/asciidoctor/helpers.rb
+++ b/lib/asciidoctor/helpers.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Internal: Except where noted, a module that contains internal helper functions.
module Helpers
diff --git a/lib/asciidoctor/inline.rb b/lib/asciidoctor/inline.rb
index c0f0e6fe..3c7b39b0 100644
--- a/lib/asciidoctor/inline.rb
+++ b/lib/asciidoctor/inline.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods for managing inline elements in AsciiDoc block
class Inline < AbstractNode
diff --git a/lib/asciidoctor/list.rb b/lib/asciidoctor/list.rb
index fa068be6..af734236 100644
--- a/lib/asciidoctor/list.rb
+++ b/lib/asciidoctor/list.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods for managing AsciiDoc lists (ordered, unordered and description lists)
class List < AbstractBlock
diff --git a/lib/asciidoctor/logging.rb b/lib/asciidoctor/logging.rb
index 036004b9..82674343 100644
--- a/lib/asciidoctor/logging.rb
+++ b/lib/asciidoctor/logging.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'logger'
module Asciidoctor
diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb
index 8aac70d3..183c47ff 100644
--- a/lib/asciidoctor/parser.rb
+++ b/lib/asciidoctor/parser.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Internal: Methods to parse lines of AsciiDoc into an object hierarchy
# representing the structure of the document. All methods are class methods and
@@ -2680,15 +2681,19 @@ class Parser
line
elsif (tab_idx = line.index TAB)
if tab_idx == 0
- line = line.sub(TabIndentRx) { full_tab_space * $&.length }
+ leading_tabs = 0
+ line.each_byte do |b|
+ break unless b == 9
+ leading_tabs += 1
+ end
+ line = %(#{full_tab_space * leading_tabs}#{line.slice leading_tabs, line.length})
next line unless line.include? TAB
end
# keeps track of how many spaces were added to adjust offset in match data
spaces_added = 0
- idx = -1
+ idx = 0
result = ''
line.each_char do |c|
- idx += 1
if c == TAB
# calculate how many spaces this tab represents, then replace tab with spaces
if (offset = idx + spaces_added) % tab_size == 0
@@ -2703,6 +2708,7 @@ class Parser
else
result = result + c
end
+ idx += 1
end
result
else
diff --git a/lib/asciidoctor/path_resolver.rb b/lib/asciidoctor/path_resolver.rb
index f5d3d5d9..ba86ff88 100644
--- a/lib/asciidoctor/path_resolver.rb
+++ b/lib/asciidoctor/path_resolver.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Handles all operations for resolving, cleaning and joining paths.
# This class includes operations for handling both web paths (request URIs) and
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index 34967dc5..0da25470 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods for retrieving lines from AsciiDoc source files
class Reader
diff --git a/lib/asciidoctor/rouge_ext.rb b/lib/asciidoctor/rouge_ext.rb
index 9f63af2a..8af4154e 100644
--- a/lib/asciidoctor/rouge_ext.rb
+++ b/lib/asciidoctor/rouge_ext.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'rouge' unless defined? Rouge.version
module Asciidoctor; module RougeExt; module Formatters
diff --git a/lib/asciidoctor/section.rb b/lib/asciidoctor/section.rb
index f116fead..d67131c1 100644
--- a/lib/asciidoctor/section.rb
+++ b/lib/asciidoctor/section.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods for managing sections of AsciiDoc content in a document.
# The section responds as an Array of content blocks by delegating
diff --git a/lib/asciidoctor/stylesheets.rb b/lib/asciidoctor/stylesheets.rb
index 7d0a7dd4..3b04a2d7 100644
--- a/lib/asciidoctor/stylesheets.rb
+++ b/lib/asciidoctor/stylesheets.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A utility class for working with the built-in stylesheets.
#--
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 6e138574..e4dd264b 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods to perform substitutions on lines of AsciiDoc text. This module
# is intented to be mixed-in to Section and Block to provide operations for performing
@@ -330,58 +331,32 @@ module Substitutors
passes.clear if outer
end
- if RUBY_ENGINE == 'opal'
- def sub_quotes text
- if QuotedTextSniffRx[compat = @document.compat_mode].match? text
- QUOTE_SUBS[compat].each do |type, scope, pattern|
- text = text.gsub(pattern) { convert_quoted_text $~, type, scope }
- end
- end
- text
- end
-
- def sub_replacements text
- if ReplaceableTextRx.match? text
- REPLACEMENTS.each do |pattern, replacement, restore|
- text = text.gsub(pattern) { do_replacement $~, replacement, restore }
- end
- end
- text
- end
- else
- # Public: Substitute quoted text (includes emphasis, strong, monospaced, etc)
- #
- # text - The String text to process
- #
- # returns The converted String text
- def sub_quotes text
- if QuotedTextSniffRx[compat = @document.compat_mode].match? text
- # NOTE interpolation is faster than String#dup
- text = %(#{text})
- QUOTE_SUBS[compat].each do |type, scope, pattern|
- # NOTE using gsub! here as an MRI Ruby optimization
- text.gsub!(pattern) { convert_quoted_text $~, type, scope }
- end
+ # Public: Substitute quoted text (includes emphasis, strong, monospaced, etc.)
+ #
+ # text - The String text to process
+ #
+ # returns The converted [String] text
+ def sub_quotes text
+ if QuotedTextSniffRx[compat = @document.compat_mode].match? text
+ QUOTE_SUBS[compat].each do |type, scope, pattern|
+ text = text.gsub(pattern) { convert_quoted_text $~, type, scope }
end
- text
end
+ text
+ end
- # Public: Substitute replacement characters (e.g., copyright, trademark, etc)
- #
- # text - The String text to process
- #
- # returns The String text with the replacement characters substituted
- def sub_replacements text
- if ReplaceableTextRx.match? text
- # NOTE interpolation is faster than String#dup
- text = %(#{text})
- REPLACEMENTS.each do |pattern, replacement, restore|
- # NOTE Using gsub! as optimization
- text.gsub!(pattern) { do_replacement $~, replacement, restore }
- end
+ # Public: Substitute replacement characters (e.g., copyright, trademark, etc.)
+ #
+ # text - The String text to process
+ #
+ # returns The [String] text with the replacement characters substituted
+ def sub_replacements text
+ if ReplaceableTextRx.match? text
+ REPLACEMENTS.each do |pattern, replacement, restore|
+ text = text.gsub(pattern) { do_replacement $~, replacement, restore }
end
- text
end
+ text
end
# Public: Substitute special characters (i.e., encode XML)
diff --git a/lib/asciidoctor/syntax_highlighter.rb b/lib/asciidoctor/syntax_highlighter.rb
index 9ab6e3fb..6e29f0e6 100644
--- a/lib/asciidoctor/syntax_highlighter.rb
+++ b/lib/asciidoctor/syntax_highlighter.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: A pluggable adapter for integrating a syntax (aka code) highlighter into AsciiDoc processing.
#
@@ -49,7 +50,7 @@ module SyntaxHighlighter
# node - The source Block to syntax highlight.
# source - The raw source text String of this source block (after preprocessing).
# lang - The source language String specified on this block (e.g., ruby).
- # opts - A Hash of options that control syntax highlighting:
+ # opts - A Hash of options that configure the syntax highlighting:
# :callouts - A Hash of callouts extracted from the source, indexed by line number (1-based) (optional).
# :css_mode - The Symbol CSS mode (:class or :inline).
# :highlight_lines - A 1-based Array of Integer line numbers to highlight (aka emphasize) (optional).
@@ -74,9 +75,8 @@ module SyntaxHighlighter
raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method)
end
- # Public: Indicates whether this syntax highlighter wants to write a stylesheet to disk.
- #
- # Only called if both the linkcss and copycss attributes are set on the document.
+ # Public: Indicates whether this syntax highlighter wants to write a stylesheet to disk. Only called if both the
+ # linkcss and copycss attributes are set on the document.
#
# doc - The Document in which this syntax highlighter is being used.
#
diff --git a/lib/asciidoctor/syntax_highlighter/coderay.rb b/lib/asciidoctor/syntax_highlighter/coderay.rb
index d5f94bda..9fe7a56a 100644
--- a/lib/asciidoctor/syntax_highlighter/coderay.rb
+++ b/lib/asciidoctor/syntax_highlighter/coderay.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::CodeRayAdapter < SyntaxHighlighter::Base
register_for 'coderay'
diff --git a/lib/asciidoctor/syntax_highlighter/highlightjs.rb b/lib/asciidoctor/syntax_highlighter/highlightjs.rb
index e89043c4..452913cd 100644
--- a/lib/asciidoctor/syntax_highlighter/highlightjs.rb
+++ b/lib/asciidoctor/syntax_highlighter/highlightjs.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::HighlightJsAdapter < SyntaxHighlighter::Base
register_for 'highlightjs', 'highlight.js'
diff --git a/lib/asciidoctor/syntax_highlighter/html_pipeline.rb b/lib/asciidoctor/syntax_highlighter/html_pipeline.rb
index f0342d43..d2679262 100644
--- a/lib/asciidoctor/syntax_highlighter/html_pipeline.rb
+++ b/lib/asciidoctor/syntax_highlighter/html_pipeline.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::HtmlPipelineAdapter < SyntaxHighlighter::Base
register_for 'html-pipeline'
diff --git a/lib/asciidoctor/syntax_highlighter/prettify.rb b/lib/asciidoctor/syntax_highlighter/prettify.rb
index b78ce55a..c3d06e95 100644
--- a/lib/asciidoctor/syntax_highlighter/prettify.rb
+++ b/lib/asciidoctor/syntax_highlighter/prettify.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::PrettifyAdapter < SyntaxHighlighter::Base
register_for 'prettify'
diff --git a/lib/asciidoctor/syntax_highlighter/pygments.rb b/lib/asciidoctor/syntax_highlighter/pygments.rb
index 2f4a614e..191acb31 100644
--- a/lib/asciidoctor/syntax_highlighter/pygments.rb
+++ b/lib/asciidoctor/syntax_highlighter/pygments.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::PygmentsAdapter < SyntaxHighlighter::Base
register_for 'pygments'
diff --git a/lib/asciidoctor/syntax_highlighter/rouge.rb b/lib/asciidoctor/syntax_highlighter/rouge.rb
index 95268a5b..cb60824e 100644
--- a/lib/asciidoctor/syntax_highlighter/rouge.rb
+++ b/lib/asciidoctor/syntax_highlighter/rouge.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class SyntaxHighlighter::RougeAdapter < SyntaxHighlighter::Base
register_for 'rouge'
diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb
index 62d4521f..8ed762c5 100644
--- a/lib/asciidoctor/table.rb
+++ b/lib/asciidoctor/table.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# Public: Methods and constants for managing AsciiDoc table content in a document.
# It supports all three of AsciiDoc's table formats: psv, dsv and csv.
diff --git a/lib/asciidoctor/timings.rb b/lib/asciidoctor/timings.rb
index 78b0b1ec..2be2024e 100644
--- a/lib/asciidoctor/timings.rb
+++ b/lib/asciidoctor/timings.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
class Timings
def initialize
diff --git a/lib/asciidoctor/version.rb b/lib/asciidoctor/version.rb
index 5ecd8ba7..93a066b4 100644
--- a/lib/asciidoctor/version.rb
+++ b/lib/asciidoctor/version.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
VERSION = '2.0.0.dev'
end
diff --git a/lib/asciidoctor/writer.rb b/lib/asciidoctor/writer.rb
index a77037de..abd3e865 100644
--- a/lib/asciidoctor/writer.rb
+++ b/lib/asciidoctor/writer.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
module Asciidoctor
# A module that can be used to mix the {#write} method into a {Converter} implementation to allow the converter to
# control how the output is written to disk.
diff --git a/test/api_test.rb b/test/api_test.rb
index ee454227..218e63f8 100644
--- a/test/api_test.rb
+++ b/test/api_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'API' do
diff --git a/test/attribute_list_test.rb b/test/attribute_list_test.rb
index d6958b8e..98b3916b 100644
--- a/test/attribute_list_test.rb
+++ b/test/attribute_list_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'AttributeList' do
diff --git a/test/attributes_test.rb b/test/attributes_test.rb
index 2e905b9a..acd2f050 100644
--- a/test/attributes_test.rb
+++ b/test/attributes_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Attributes' do
@@ -201,7 +202,7 @@ context 'Attributes' do
{name}
EOS
# see https://github.com/oracle/truffleruby/issues/1563
- input = input.force_encoding ::Encoding::UTF_8 if RUBY_ENGINE == 'truffleruby'
+ input = String.new input, encoding: ::Encoding::UTF_8 if RUBY_ENGINE == 'truffleruby'
result = convert_inline_string input, attributes: { 'max-attribute-value-size' => 6 }
assert_equal expected, result
@@ -216,7 +217,7 @@ context 'Attributes' do
{name}
EOS
# see https://github.com/oracle/truffleruby/issues/1563
- input = input.force_encoding ::Encoding::UTF_8 if RUBY_ENGINE == 'truffleruby'
+ input = String.new input, encoding: ::Encoding::UTF_8 if RUBY_ENGINE == 'truffleruby'
result = convert_inline_string input, attributes: { 'max-attribute-value-size' => 8 }
assert_equal expected, result
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index 54f6236d..8e76dc38 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Blocks' do
diff --git a/test/converter_test.rb b/test/converter_test.rb
index 35b81be9..b57216fe 100644
--- a/test/converter_test.rb
+++ b/test/converter_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
require 'tilt' unless defined? ::Tilt.new
diff --git a/test/document_test.rb b/test/document_test.rb
index 94f4d539..54fffb38 100644
--- a/test/document_test.rb
+++ b/test/document_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
BUILT_IN_ELEMENTS = %w(admonition audio colist dlist document embedded example floating_title image inline_anchor inline_break inline_button inline_callout inline_footnote inline_image inline_indexterm inline_kbd inline_menu inline_quoted listing literal stem olist open page_break paragraph pass preamble quote section sidebar table thematic_break toc ulist verse video)
diff --git a/test/extensions_test.rb b/test/extensions_test.rb
index 0b8dbeeb..2d6cda9e 100644
--- a/test/extensions_test.rb
+++ b/test/extensions_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
class ExtensionsInitTest < Minitest::Test
diff --git a/test/invoker_test.rb b/test/invoker_test.rb
index 1ad7580d..8e09f435 100644
--- a/test/invoker_test.rb
+++ b/test/invoker_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
require_relative 'test_helper'
require File.join Asciidoctor::LIB_DIR, 'asciidoctor/cli'
diff --git a/test/links_test.rb b/test/links_test.rb
index 5e744f48..9a2620df 100644
--- a/test/links_test.rb
+++ b/test/links_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Links' do
diff --git a/test/lists_test.rb b/test/lists_test.rb
index 4a0c9003..4eeb80be 100644
--- a/test/lists_test.rb
+++ b/test/lists_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context "Bulleted lists (:ulist)" do
diff --git a/test/logger_test.rb b/test/logger_test.rb
index 1b1d81fd..80870d7c 100644
--- a/test/logger_test.rb
+++ b/test/logger_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Logger' do
diff --git a/test/manpage_test.rb b/test/manpage_test.rb
index d0da15b7..ac8223c3 100644
--- a/test/manpage_test.rb
+++ b/test/manpage_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
SAMPLE_MANPAGE_HEADER = <<'EOS'.chomp
diff --git a/test/options_test.rb b/test/options_test.rb
index 843596fe..54e6980d 100644
--- a/test/options_test.rb
+++ b/test/options_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
require File.join Asciidoctor::LIB_DIR, 'asciidoctor/cli/options'
diff --git a/test/paragraphs_test.rb b/test/paragraphs_test.rb
index a58eb16c..f1a864bd 100644
--- a/test/paragraphs_test.rb
+++ b/test/paragraphs_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Paragraphs' do
diff --git a/test/parser_test.rb b/test/parser_test.rb
index d54d6d30..e5a1d30d 100644
--- a/test/parser_test.rb
+++ b/test/parser_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context "Parser" do
diff --git a/test/paths_test.rb b/test/paths_test.rb
index 292c3fb9..79e4c60a 100644
--- a/test/paths_test.rb
+++ b/test/paths_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Path Resolver' do
diff --git a/test/preamble_test.rb b/test/preamble_test.rb
index 691dc63a..ef7db9ef 100644
--- a/test/preamble_test.rb
+++ b/test/preamble_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Preamble' do
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 3b538d2e..45fc7686 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
class ReaderTest < Minitest::Test
@@ -23,7 +24,7 @@ third line
test 'should remove UTF-8 BOM from first line of String data' do
['UTF-8', 'ASCII-8BIT'].each do |start_encoding|
- data = "\xef\xbb\xbf#{SAMPLE_DATA.join ::Asciidoctor::LF}".force_encoding start_encoding
+ data = String.new %(\xef\xbb\xbf#{SAMPLE_DATA.join ::Asciidoctor::LF}), encoding: start_encoding
reader = Asciidoctor::Reader.new data, nil, normalize: true
assert_equal Encoding::UTF_8, reader.lines[0].encoding
assert_equal 'f', reader.lines[0].chr
@@ -34,7 +35,7 @@ third line
test 'should remove UTF-8 BOM from first line of Array data' do
['UTF-8', 'ASCII-8BIT'].each do |start_encoding|
data = SAMPLE_DATA.dup
- data[0] = "\xef\xbb\xbf#{data.first}".force_encoding start_encoding
+ data[0] = String.new %(\xef\xbb\xbf#{data.first}), encoding: start_encoding
reader = Asciidoctor::Reader.new data, nil, normalize: true
assert_equal Encoding::UTF_8, reader.lines[0].encoding
assert_equal 'f', reader.lines[0].chr
diff --git a/test/sections_test.rb b/test/sections_test.rb
index ddfabebe..2dca1c07 100644
--- a/test/sections_test.rb
+++ b/test/sections_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Sections' do
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index c1e0a86c..2c7ccd8d 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
# TODO
diff --git a/test/syntax_highlighter_test.rb b/test/syntax_highlighter_test.rb
index d2f920cd..9f01f7e1 100644
--- a/test/syntax_highlighter_test.rb
+++ b/test/syntax_highlighter_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Syntax Highlighter' do
diff --git a/test/tables_test.rb b/test/tables_test.rb
index 6bc39ddd..3f76b8d5 100644
--- a/test/tables_test.rb
+++ b/test/tables_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context 'Tables' do
diff --git a/test/test_helper.rb b/test/test_helper.rb
index fc978f82..a4c53ee0 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
ASCIIDOCTOR_TEST_DIR = File.absolute_path __dir__
ASCIIDOCTOR_LIB_DIR = ENV['ASCIIDOCTOR_LIB_DIR'] || (File.join ASCIIDOCTOR_TEST_DIR, '../lib')
diff --git a/test/text_test.rb b/test/text_test.rb
index daa4a172..882d6a51 100644
--- a/test/text_test.rb
+++ b/test/text_test.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require_relative 'test_helper'
context "Text" do