diff options
author | Norbert Preining <norbert@preining.info> | 2022-11-09 03:02:50 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-11-09 03:02:50 +0000 |
commit | 5de83ec843cdc88e6adc42b1fe3f0ec48c52b7f3 (patch) | |
tree | b49f7c180396c8ef389c8fd519370b6d03f4e100 /macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm | |
parent | 118cb5bbc5236bf86ca1088b9b3bae04c7b09beb (diff) |
CTAN sync 202211090302
Diffstat (limited to 'macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm')
-rw-r--r-- | macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm | 133 |
1 files changed, 78 insertions, 55 deletions
diff --git a/macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm b/macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm index 9bac7fd4d5..32ff10084f 100644 --- a/macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm +++ b/macros/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm @@ -22,13 +22,21 @@ package Texinfo::Convert::TextContent; use 5.00405; use strict; -use Texinfo::Convert::Converter; -use Texinfo::Convert::Text; +# To check if there is no erroneous autovivification +#no autovivification qw(fetch delete exists store strict); + +use Texinfo::Commands; use Texinfo::Common; +use Texinfo::Convert::Utils; +use Texinfo::Convert::Text; +use Texinfo::Convert::Converter; use vars qw($VERSION @ISA); @ISA = qw(Texinfo::Convert::Converter); +$VERSION = '7.0'; + + my %ignored_brace_commands; # Handle better @errormsg? foreach my $ignored_brace_command ('hyphenation', 'errormsg') { @@ -41,15 +49,15 @@ foreach my $ignored_command ( } my %ignored_types; -foreach my $type ('empty_line_after_command', 'preamble', - 'empty_spaces_after_command', - 'empty_spaces_before_paragraph', - 'empty_spaces_after_close_brace') { +foreach my $type ('ignorable_spaces_after_command', 'preamble_before_beginning', + 'spaces_before_paragraph', + 'spaces_after_close_brace') { $ignored_types{$type} = 1; } my %defaults = ( 'FORMAT_MENU' => 'menu', + # different from the default, which is undef 'OUTFILE' => '-', ); @@ -62,12 +70,11 @@ sub converter_initialize($) { my $self = shift; - %{$self->{'formatting_misc_commands'}} - = %Texinfo::Convert::Text::formatting_misc_commands; - + %{$self->{'formatted_line_commands'}} + = %Texinfo::Common::formatted_line_commands; if ($self->get_conf('TEXTCONTENT_COMMENT')) { - $self->{'formatting_misc_commands'}->{'c'} = 1; - $self->{'formatting_misc_commands'}->{'comment'} = 1; + $self->{'formatted_line_commands'}->{'c'} = 1; + $self->{'formatted_line_commands'}->{'comment'} = 1; } } @@ -92,72 +99,88 @@ sub _convert($$); sub _convert($$) { my $self = shift; - my $root = shift; + my $element = shift; - return '' if (!($root->{'type'} and $root->{'type'} eq 'def_line') - and (($root->{'type'} and $ignored_types{$root->{'type'}}) - or ($root->{'cmdname'} - and ($ignored_brace_commands{$root->{'cmdname'}} - or ($ignored_block_commands{$root->{'cmdname'}} + return '' if (!($element->{'type'} and $element->{'type'} eq 'def_line') + and (($element->{'type'} and $ignored_types{$element->{'type'}}) + or ($element->{'cmdname'} + and ($ignored_brace_commands{$element->{'cmdname'}} + or ($ignored_block_commands{$element->{'cmdname'}} and !(defined($self->{'expanded_formats_hash'}) - and $self->{'expanded_formats_hash'}->{$root->{'cmdname'}})) - or ($Texinfo::Common::inline_format_commands{$root->{'cmdname'}} - and (!$root->{'extra'}->{'format'} - or !$self->{'expanded_formats_hash'}->{$root->{'extra'}->{'format'}})) - or ($root->{'cmdname'} eq 'menu' and $self->get_conf('FORMAT_MENU') eq 'nomenu') - # here ignore most of the misc commands - or ($root->{'args'} and $root->{'args'}->[0] - and $root->{'args'}->[0]->{'type'} - and ($root->{'args'}->[0]->{'type'} eq 'line_arg' - or $root->{'args'}->[0]->{'type'} eq 'misc_arg') - and !$self->{'formatting_misc_commands'}->{$root->{'cmdname'}}))))); - if (defined($root->{'text'})) { - return $root->{'text'}; + and $self->{'expanded_formats_hash'}->{$element->{'cmdname'}})) + or ($Texinfo::Common::inline_format_commands{$element->{'cmdname'}} + and (!$element->{'extra'}->{'format'} + or !$self->{'expanded_formats_hash'}->{$element->{'extra'}->{'format'}})) + or ($element->{'cmdname'} eq 'menu' and $self->get_conf('FORMAT_MENU') eq 'nomenu') + # here ignore most of the line commands + or ($element->{'args'} and $element->{'args'}->[0] + and $element->{'args'}->[0]->{'type'} + and ($element->{'args'}->[0]->{'type'} eq 'line_arg' + or $element->{'args'}->[0]->{'type'} eq 'misc_arg') + and !$self->{'formatted_line_commands'}->{$element->{'cmdname'}}))))); + if (defined($element->{'text'})) { + return $element->{'text'}; } - if (defined($root->{'cmdname'})) { - if (exists($Texinfo::Common::no_brace_commands{$root->{'cmdname'}})) { - return $Texinfo::Common::no_brace_commands{$root->{'cmdname'}}; - } elsif ($root->{'cmdname'} eq 'today') { + if (defined($element->{'cmdname'})) { + if (exists($Texinfo::Common::nobrace_symbol_text{$element->{'cmdname'}})) { + return $Texinfo::Common::nobrace_symbol_text{$element->{'cmdname'}}; + } elsif ($element->{'cmdname'} eq 'today') { + if ($self->get_conf('TEST')) { + return 'a sunny day'; + } my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); $year += ($year < 70) ? 2000 : 1900; - return "$Texinfo::Common::MONTH_NAMES[$mon] $mday, $year"; - } elsif (defined($Texinfo::Convert::Text::text_brace_no_arg_commands{$root->{'cmdname'}})) { - return Texinfo::Convert::Text::brace_no_arg_command($root, undef); - } elsif ($Texinfo::Common::accent_commands{$root->{'cmdname'}}) { - my %options = Texinfo::Common::_convert_text_options($self); - my $result = Texinfo::Convert::Text::text_accents ($root, + return "$Texinfo::Convert::Utils::MONTH_NAMES[$mon] $mday, $year"; + } elsif (defined($Texinfo::Convert::Text::text_brace_no_arg_commands{$element->{'cmdname'}})) { + return Texinfo::Convert::Text::brace_no_arg_command($element, undef); + } elsif ($Texinfo::Commands::accent_commands{$element->{'cmdname'}}) { + my %options = Texinfo::Convert::Text::copy_options_for_convert_text($self); + my $result = Texinfo::Convert::Text::text_accents($element, $options{'enabled_encoding'}); return $result; } } my $result = ''; - if ($root->{'args'} - and (!$root->{'cmdname'} - or !$Texinfo::Common::block_item_commands{$root->{'cmdname'}})) { + if ($element->{'args'} + and (!$element->{'cmdname'} + or !$Texinfo::Commands::blockitem_commands{$element->{'cmdname'}})) { my $args; - if ($root->{'cmdname'} - and $Texinfo::Common::inline_format_commands{$root->{'cmdname'}}) { - my @args = @{$root->{'args'}}; + if ($element->{'cmdname'} + and $Texinfo::Common::inline_format_commands{$element->{'cmdname'}}) { + my @args = @{$element->{'args'}}; shift @args; $args = \@args; } else { - $args = $root->{'args'}; + $args = $element->{'args'}; } foreach my $arg (@{$args}) { - $result .= _convert ($self, $arg); + $result .= _convert($self, $arg); + if ($arg->{'type'} + and $arg->{'type'} eq 'block_line_arg' + and $arg->{'extra'} and $arg->{'extra'}->{'spaces_after_argument'} + and $result =~ /\S/) { + $result .= $arg->{'extra'}->{'spaces_after_argument'}; + } } } - if ($root->{'contents'}) { - foreach my $content (@{$root->{'contents'}}) { - $result .= _convert ($self, $content); + if ($element->{'contents'}) { + foreach my $content (@{$element->{'contents'}}) { + $result .= _convert($self, $content); } } $result = '{'.$result.'}' - if ($root->{'type'} and $root->{'type'} eq 'bracketed' - and (!$root->{'parent'}->{'type'} or - ($root->{'parent'}->{'type'} ne 'block_line_arg' - and $root->{'parent'}->{'type'} ne 'line_arg'))); + if ($element->{'type'} and $element->{'type'} eq 'bracketed' + and (!$element->{'parent'}->{'type'} or + ($element->{'parent'}->{'type'} ne 'block_line_arg' + and $element->{'parent'}->{'type'} ne 'line_arg'))); + + if ($element->{'type'} and $element->{'type'} eq 'line_arg' + # in that case there is already a 'spaces_at_end' + and not ($element->{'parent'}->{'type'} + and $element->{'parent'}->{'type'} eq 'def_line')) { + $result .= "\n"; + } return $result; } |