summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm')
-rw-r--r--Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm32
1 files changed, 28 insertions, 4 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm
index 1850a83c90d..7f3d026a4e6 100644
--- a/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm
+++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Wrap.pm
@@ -249,12 +249,36 @@ sub text_wrap {
# initiate the trailing comments storage
my $trailingComments = q();
- # grab all *internal* trailing comments from the block
- while ( $textWrapBlockStorageValue =~ m|$trailingCommentRegExp| ) {
- $textWrapBlockStorageValue =~ s|(\h*$trailingCommentRegExp)||s;
- $trailingComments .= $1;
+ # about trailing comments
+ #
+ # - trailing comments that do *not* have leading space instruct the text
+ # wrap routine to connect the lines *without* space
+ #
+ # - multiple trailing comments will be connected at the end of the text wrap block
+ #
+ # - the number of spaces between the end of the text wrap block and
+ # the (possibly combined) trailing comments is determined by the
+ # spaces (if any) at the end of the text wrap block
+
+ # for trailing comments that
+ #
+ # do *NOT* have a leading space
+ # do have a trailing line break
+ #
+ # then we *remove* the trailing line break
+ while ( $textWrapBlockStorageValue =~ m|\H$trailingCommentRegExp\h*\R|s ) {
+ $textWrapBlockStorageValue =~ s|(\H)($trailingCommentRegExp)\h*\R|$1$2|s;
+ }
+
+ # now we put all of the trailing comments together
+ while ( $textWrapBlockStorageValue =~ m|$trailingCommentRegExp|s ) {
+ $textWrapBlockStorageValue =~ s|($trailingCommentRegExp)||s;
+ $trailingComments = $trailingComments . $1;
}
+ $trailingComments =~ s/\h{2,}/ /sg
+ if ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{multipleSpacesToSingle};
+
# determine if text wrapping will remove paragraph line breaks
my $removeBlockLineBreaks = ${ $mainSettings{modifyLineBreaks}{textWrapOptions} }{removeBlockLineBreaks};