diff --git a/NEWS b/NEWS index 151cc645..23252e07 100644 --- a/NEWS +++ b/NEWS @@ -85,6 +85,10 @@ Status of the documentation translation: * 1 language >= 33%: ca (42%). * 4 starting languages: eo (3%), hr (0%), hu (0%), nb (4%). +Asciidoc: + * Support a cleanspaces option to remove extra spaces in wrapped lines + (GitHub's #464). Thanks Jean-Noël Avila for the pull request. + ======================================================================= ___ _____ ___ __ __/ _ \|___ / _ \ diff --git a/lib/Locale/Po4a/AsciiDoc.pm b/lib/Locale/Po4a/AsciiDoc.pm index 166d7381..6fe1cd19 100644 --- a/lib/Locale/Po4a/AsciiDoc.pm +++ b/lib/Locale/Po4a/AsciiDoc.pm @@ -111,6 +111,11 @@ equality of length of opening and closing block fences. Disable linting messages. When the source code cannot be fixed for clearer document structure, these messages are useless. +=item B + +Remove extra spaces from the source segments in no-wrap mode. This is useful when the +translation tools are sensitive to the number of spaces. + =item B Comma-separated list of keys to process for translation in the YAML Front Matter @@ -221,6 +226,7 @@ sub initialize { $self->{options}{'yfm_skip_array'} = 0; $self->{options}{'yfm_paths'} = ''; $self->{options}{'nolinting'} = 0; + $self->{options}{'cleanspaces'} = 0; foreach my $opt ( keys %options ) { die wrap_mod( "po4a::asciidoc", dgettext( "po4a", "Unknown option: %s" ), $opt ) @@ -395,13 +401,20 @@ BEGIN { sub translate { my ( $self, $str, $ref, $type ) = @_; my (%options) = @_; - if ( ($options{'wrap'}==1) && ($str =~ / \+\n/) ) { - $options{'wrap'} = 0; - $str =~ s/([^+])\n/$1 /g; - $str =~ s/ \+\n/\n/g; - $str = $self->SUPER::translate( $str, $ref, $type, %options); - $str =~ s/\n/ +\n/g; - $options{'wrap'} = 1; + if ( $options{'wrap'} == 1 ) { + if ($str =~ / \+\n/) { + $options{'wrap'} = 0; + $str =~ s/([^+])\n/$1 /g; + $str =~ s/ \+\n/\n/g; + $str = $self->SUPER::translate( $str, $ref, $type, %options); + $str =~ s/\n/ +\n/g; + $options{'wrap'} = 1; + } else { + if ( $self->{options}{'cleanspaces'} == 1 ) { + $str =~ s/[ \n]+/ /g; + } + $str = $self->SUPER::translate( $str, $ref, $type, %options); + } } else { $str = $self->SUPER::translate( $str, $ref, $type, %options ); } @@ -1167,8 +1180,8 @@ sub do_paragraph { my $end = ""; if ($wrap) { - $paragraph =~ s/^(.*?)(\n*)$/$1/s; - $end = $2 || ""; + $paragraph =~ s/(\n*)$//s; + $end = $1 || ""; } if ( defined $self->{bullet} ) { my $bullet = $self->{bullet}; @@ -1189,7 +1202,7 @@ sub do_paragraph { my $unwrap_result = !$self->{options}{'forcewrap'} && $wrap && (! ($t =~ /\+\n/) ) ; if ($unwrap_result) { - $t =~ s/(\n| )+/ /g; + $t =~ s/[\n ]+/ /g; } @comments = (); diff --git a/t/fmt-asciidoc.t b/t/fmt-asciidoc.t index ccd7221a..74aac073 100644 --- a/t/fmt-asciidoc.t +++ b/t/fmt-asciidoc.t @@ -42,6 +42,11 @@ push @tests, 'options' => '-o nolinting=1', 'input' => "fmt/asciidoc/LineBreak.adoc", }, + { + 'format' => 'asciidoc', + 'options' => '-o cleanspaces=1', + 'input' => "fmt/asciidoc/CleanSpaces.adoc", + }, { 'format' => 'asciidoc', 'input' => "fmt/asciidoc/YamlFrontMatter.adoc", diff --git a/t/fmt/asciidoc/CleanSpaces.adoc b/t/fmt/asciidoc/CleanSpaces.adoc new file mode 100644 index 00000000..99283bf4 --- /dev/null +++ b/t/fmt/asciidoc/CleanSpaces.adoc @@ -0,0 +1,20 @@ +Test Clean Spaces +================= + +************************** +This is a Sidebar block. +This is a Sidebar block. + + This is a Sidebar block. + This is a Sidebar block. + + - This is a Sidebar block. + This is a Sidebar block. +************************** + +...:: + Files to add content from. Fileglobs (e.g. `*.c`) can + be given to add all matching files. + +Some paragraph text. Some paragraph text. Some paragraph text. +Some paragraph text. Some paragraph text. Some paragraph text. diff --git a/t/fmt/asciidoc/CleanSpaces.norm b/t/fmt/asciidoc/CleanSpaces.norm new file mode 100644 index 00000000..c8a25f36 --- /dev/null +++ b/t/fmt/asciidoc/CleanSpaces.norm @@ -0,0 +1,16 @@ +Test Clean Spaces +================= + +************************** +This is a Sidebar block. This is a Sidebar block. + + This is a Sidebar block. + This is a Sidebar block. + + - This is a Sidebar block. This is a Sidebar block. +************************** + +...:: + Files to add content from. Fileglobs (e.g. `*.c`) can be given to add all matching files. + +Some paragraph text. Some paragraph text. Some paragraph text. Some paragraph text. Some paragraph text. Some paragraph text. diff --git a/t/fmt/asciidoc/CleanSpaces.po b/t/fmt/asciidoc/CleanSpaces.po new file mode 100644 index 00000000..b7e163e2 --- /dev/null +++ b/t/fmt/asciidoc/CleanSpaces.po @@ -0,0 +1,61 @@ +# SOME DESCRIPTIVE TITLE +# Copyright (C) YEAR Free Software Foundation, Inc. +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2024-02-28 21:46+0100\n" +"PO-Revision-Date: 2024-02-28 21:47+0100\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. type: Title = +#: CleanSpaces.adoc:2 +#, no-wrap +msgid "Test Clean Spaces" +msgstr "TEST CLEAN SPACES" + +#. type: delimited block * +#: CleanSpaces.adoc:7 CleanSpaces.adoc:13 +msgid "This is a Sidebar block. This is a Sidebar block." +msgstr "THIS IS A SIDEBAR BLOCK. THIS IS A SIDEBAR BLOCK." + +#. type: delimited block * +#: CleanSpaces.adoc:10 +#, no-wrap +msgid "" +" This is a Sidebar block.\n" +" This is a Sidebar block.\n" +msgstr "" +" THIS IS A SIDEBAR BLOCK.\n" +" THIS IS A SIDEBAR BLOCK.\n" + +#. type: Labeled list +#: CleanSpaces.adoc:15 +#, no-wrap +msgid "..." +msgstr "..." + +#. type: Plain text +#: CleanSpaces.adoc:18 +msgid "" +"Files to add content from. Fileglobs (e.g. `*.c`) can be given to add all " +"matching files." +msgstr "" +"FILES TO ADD CONTENT FROM. FILEGLOBS (E.G. `*.C`) CAN BE GIVEN TO ADD ALL " +"MATCHING FILES." + +#. type: Plain text +#: CleanSpaces.adoc:20 +msgid "" +"Some paragraph text. Some paragraph text. Some paragraph text. Some " +"paragraph text. Some paragraph text. Some paragraph text." +msgstr "" +"SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME " +"PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT." diff --git a/t/fmt/asciidoc/CleanSpaces.pot b/t/fmt/asciidoc/CleanSpaces.pot new file mode 100644 index 00000000..2646feca --- /dev/null +++ b/t/fmt/asciidoc/CleanSpaces.pot @@ -0,0 +1,56 @@ +# SOME DESCRIPTIVE TITLE +# Copyright (C) YEAR Free Software Foundation, Inc. +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2024-02-28 21:46+0100\n" +"PO-Revision-Date: 2024-02-28 21:48+0100\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. type: Title = +#: CleanSpaces.adoc:2 +#, no-wrap +msgid "Test Clean Spaces" +msgstr "" + +#. type: delimited block * +#: CleanSpaces.adoc:7 CleanSpaces.adoc:13 +msgid "This is a Sidebar block. This is a Sidebar block." +msgstr "" + +#. type: delimited block * +#: CleanSpaces.adoc:10 +#, no-wrap +msgid "" +" This is a Sidebar block.\n" +" This is a Sidebar block.\n" +msgstr "" + +#. type: Labeled list +#: CleanSpaces.adoc:15 +#, no-wrap +msgid "..." +msgstr "" + +#. type: Plain text +#: CleanSpaces.adoc:18 +msgid "" +"Files to add content from. Fileglobs (e.g. `*.c`) can be given to add all " +"matching files." +msgstr "" + +#. type: Plain text +#: CleanSpaces.adoc:20 +msgid "" +"Some paragraph text. Some paragraph text. Some paragraph text. Some " +"paragraph text. Some paragraph text. Some paragraph text." +msgstr "" diff --git a/t/fmt/asciidoc/CleanSpaces.trans b/t/fmt/asciidoc/CleanSpaces.trans new file mode 100644 index 00000000..00687483 --- /dev/null +++ b/t/fmt/asciidoc/CleanSpaces.trans @@ -0,0 +1,16 @@ +TEST CLEAN SPACES +================= + +************************** +THIS IS A SIDEBAR BLOCK. THIS IS A SIDEBAR BLOCK. + + THIS IS A SIDEBAR BLOCK. + THIS IS A SIDEBAR BLOCK. + + - THIS IS A SIDEBAR BLOCK. THIS IS A SIDEBAR BLOCK. +************************** + +...:: + FILES TO ADD CONTENT FROM. FILEGLOBS (E.G. `*.C`) CAN BE GIVEN TO ADD ALL MATCHING FILES. + +SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT. SOME PARAGRAPH TEXT.