summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-03-02 03:10:14 -0700
committerGitHub <noreply@github.com>2019-03-02 03:10:14 -0700
commitab1addcaee8b3b2f0da64b92175bd98f99d02638 (patch)
treeba15824082e498d092d9720a6931e8b18fbdb8c5
parent9a6829dae5f330553760f83890a689be24a1485a (diff)
resolves #3123 rename hardbreaks document attribute to hardbreaks-option (PR #3124)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/document.rb3
-rw-r--r--lib/asciidoctor/parser.rb14
-rw-r--r--lib/asciidoctor/substitutors.rb4
-rw-r--r--test/paragraphs_test.rb18
5 files changed, 32 insertions, 8 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 6e56dbde..502180e6 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -96,6 +96,7 @@ Improvements::
* only map unparsed attrlist of inline macro to target when format is short
* add clearer exception message when source data is binary or has invalid encoding (#2884)
* rename context for table cell and table column to :table_cell and :table_column, respectively
+ * rename hardbreaks document attribute to hardbreaks-option; retain hardbreaks as a deprecated alias (#3123)
Bug Fixes::
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index 5b48cf77..cd8ad274 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -394,8 +394,9 @@ class Document < AbstractBlock
attr_overrides['user-home'] = USER_HOME
- # legacy support for numbered attribute
+ # remap legacy attribute names
attr_overrides['sectnums'] = attr_overrides.delete 'numbered' if attr_overrides.key? 'numbered'
+ attr_overrides['hardbreaks-option'] = attr_overrides.delete 'hardbreaks' if attr_overrides.key? 'hardbreaks'
# If the base_dir option is specified, it overrides docdir and is used as the root for relative
# paths. Otherwise, the base_dir is the directory of the source file (docdir), if set, otherwise
diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb
index 85a5881a..fa2febb1 100644
--- a/lib/asciidoctor/parser.rb
+++ b/lib/asciidoctor/parser.rb
@@ -2107,15 +2107,19 @@ class Parser
# TODO move processing of attribute value to utility method
if name.end_with? '!'
# a nil value signals the attribute should be deleted (unset)
- name, value = name.chop, nil
+ name = name.chop
+ value = nil
elsif name.start_with? '!'
# a nil value signals the attribute should be deleted (unset)
- name, value = (name.slice 1, name.length), nil
+ name = (name.slice 1, name.length)
+ value = nil
end
- name = sanitize_attribute_name name
- # alias numbered attribute to sectnums
- name = 'sectnums' if name == 'numbered'
+ if (name = sanitize_attribute_name name) == 'numbered'
+ name = 'sectnums'
+ elsif name == 'hardbreaks'
+ name = 'hardbreaks-option'
+ end
if doc
if value
diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb
index 2a45a79c..2f87dfaa 100644
--- a/lib/asciidoctor/substitutors.rb
+++ b/lib/asciidoctor/substitutors.rb
@@ -1053,8 +1053,8 @@ module Substitutors
#
# Returns the converted String text
def sub_post_replacements(text)
- #if attr? 'hardbreaks-option', nil, 'hardbreaks'
- if @attributes['hardbreaks-option'] || @document.attributes['hardbreaks']
+ #if attr? 'hardbreaks-option', nil, true
+ if @attributes['hardbreaks-option'] || @document.attributes['hardbreaks-option']
lines = text.split LF, -1
return text if lines.size < 2
last = lines.pop
diff --git a/test/paragraphs_test.rb b/test/paragraphs_test.rb
index 4f01443a..da06fa6f 100644
--- a/test/paragraphs_test.rb
+++ b/test/paragraphs_test.rb
@@ -218,6 +218,24 @@ context 'Paragraphs' do
assert_xpath '//p', output, 1
assert_includes output, "<p>read<br>\nmy<br>\nlips</p>"
end
+
+ test 'should be able to toggle hardbreaks by setting hardbreaks-option on document' do
+ input = <<~'EOS'
+ :hardbreaks-option:
+
+ make
+ it
+ so
+
+ :!hardbreaks:
+
+ roll it back
+ EOS
+
+ output = convert_string_to_embedded input
+ assert_xpath '(//p)[1]/br', output, 2
+ assert_xpath '(//p)[2]/br', output, 0
+ end
end
context 'Literal' do