summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-05-16 19:10:35 -0400
committerGitHub <noreply@github.com>2024-05-16 17:10:35 -0600
commitbd84a0cc736de344768f93cc0932cefb1dbbadc9 (patch)
tree2607b2bde6d55cd86127d3d174a611b8c16b10a2
parentad827b14e2ce3057a5c9e03d1dab50470d0d0eb1 (diff)
resolves #3583 preserve repeating spaces in verbatim content in manpage output (PR #4592)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/converter/manpage.rb2
-rw-r--r--test/manpage_test.rb33
3 files changed, 34 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index bb5dafd9..1ef4e1ff 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -75,6 +75,7 @@ Bug Fixes::
* Don't crash when parsing xref shorthand if target starts with URL protocol and text is offset by space (#4570)
* Only drop current row if colspan of last cell exceeds specified number of columns (#4587)
* Drop last row if colspan of last cell in table exceeds specified number of columns (#4587)
+ * Preserve repeating spaces in verbatim content in manpage output (#3583)
== 2.0.22 (2024-03-08) - @mojavelinux
diff --git a/lib/asciidoctor/converter/manpage.rb b/lib/asciidoctor/converter/manpage.rb
index 0d58550a..29966dd5 100644
--- a/lib/asciidoctor/converter/manpage.rb
+++ b/lib/asciidoctor/converter/manpage.rb
@@ -698,7 +698,7 @@ r lw(\n(.lu*75u/100u).'
def manify str, opts = {}
case opts.fetch :whitespace, :collapse
when :preserve
- str = str.gsub TAB, ET
+ str = (str.gsub TAB, ET).gsub(/(^)? +/) { $1 ? $& : %(#{ESC_BS}&#{$&}) }
when :normalize
str = str.gsub WrappedIndentRx, LF
else
diff --git a/test/manpage_test.rb b/test/manpage_test.rb
index 0feb1469..0eae0dfd 100644
--- a/test/manpage_test.rb
+++ b/test/manpage_test.rb
@@ -349,6 +349,37 @@ context 'Manpage' do
assert_includes output, %(Oh, here it goes again\nI should have known,\nshould have known,\nshould have known again)
end
+ test 'should escape repeated spaces in literal content' do
+ input = <<~EOS.chop
+ #{SAMPLE_MANPAGE_HEADER}
+
+ ....
+ ,---. ,-----.
+ |Bob| |Alice|
+ `-+-' `--+--'
+ | hello |
+ |-------------->|
+ ,-+-. ,--+--.
+ |Bob| |Alice|
+ `---' `-----'
+ ....
+ EOS
+
+ output = Asciidoctor.convert input, backend: :manpage
+ assert_includes output, <<~'EOS'
+ .fam C
+ ,\-\-\-.\& ,\-\-\-\-\-.
+ |Bob|\& |Alice|
+ `\-+\-\*(Aq\& `\-\-+\-\-\*(Aq
+ |\& hello\& |
+ |\-\-\-\-\-\-\-\-\-\-\-\-\-\->|
+ ,\-+\-.\& ,\-\-+\-\-.
+ |Bob|\& |Alice|
+ `\-\-\-\*(Aq\& `\-\-\-\-\-\*(Aq
+ .fam
+ EOS
+ end
+
test 'should preserve break between paragraphs in normal table cell' do
input = <<~EOS.chop
#{SAMPLE_MANPAGE_HEADER}
@@ -859,7 +890,7 @@ context 'Manpage' do
T}:T{
.nf
b
- c _d_
+ c\& _d_
\&.
.fi
T}