summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2017-07-13 01:55:32 -0600
committerDan Allen <dan.j.allen@gmail.com>2017-07-13 02:05:04 -0600
commit2f81b4e4be7dbd52f6e2df91c6403061bfb539ec (patch)
tree763d5187fe45455d72b763fa8803d422dba894b9
parent6c6e35dc20f0f0ad88279365cba7bd0a9c67d1e0 (diff)
allow the subs argument of apply_subs to be nil
- allow subs argument to be nil - fix API doc - split check for nil and empty subs
-rw-r--r--lib/asciidoctor/substitutors.rb10
-rw-r--r--test/substitutions_test.rb6
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 367b9cbc..39776305 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -77,12 +77,12 @@ module Substitutors
# Public: Apply the specified substitutions to the source.
#
# source - The String or String Array of text to process; must not be nil.
- # subs - The substitutions to perform; can be a Symbol or Symbol Array; must not be nil (default: :normal).
- # expand - A Boolean to control whether substitution aliases are expanded (default: false).
+ # subs - The substitutions to perform; can be a Symbol, Symbol Array or nil (default: NORMAL_SUBS).
+ # expand - A Boolean (or nil) to control whether substitution aliases are expanded (default: nil).
#
# Returns a String or String Array with substitutions applied, matching the type of source argument.
- def apply_subs source, subs = NORMAL_SUBS, expand = false
- if source.empty? || subs.empty?
+ def apply_subs source, subs = NORMAL_SUBS, expand = nil
+ if source.empty? || !subs
return source
elsif expand
if ::Symbol === subs
@@ -101,6 +101,8 @@ module Substitutors
return source
end
end
+ elsif subs.empty?
+ return source
end
text = (multiline = ::Array === source) ? source * LF : source
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index 3f5e6a75..d10d52fd 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -38,6 +38,12 @@ context 'Substitutions' do
result = para.apply_subs para.lines, [:normal], true
assert_equal ['Asciidoctor', '<strong>bold</strong>', '2 &gt; 1'], result
end
+
+ test 'apply_subs should allow the subs argument to be nil' do
+ block = block_from_string %([pass]\n*raw*)
+ result = block.apply_subs block.source, nil
+ assert_equal '*raw*', result
+ end
end
context 'Quotes' do