) {
#print STDERR "$encoded_html_result_path_name: while $line";
if ($line =~ /$range_separator/) {
$separators_count++;
if (defined($text)) {
$got_count++;
my $element_command
= $languages{$language}->{'commands'}->[$got_count-1];
my $element = $element_command->[0];
my $cmdname = $element_command->[1];
$commands{$cmdname}->{'results'}->{$element} = $text;
$commands{$cmdname}->{'retrieved_languages_counters'}->{$language}++;
$text = undef;
}
#print STDERR "$language $got_count $language_fragments_nr \n";
if ($got_count < $language_fragments_nr) {
$text = '';
}
} else {
if (defined($text)) {
$text .= $line;
}
}
}
if ($separators_count != $language_fragments_nr +1) {
$self->document_warn($self, sprintf(__(
"highlight_syntax.pm: %s: %d separators; expected %d, the number of fragments +1"),
$language, $separators_count, $language_fragments_nr+1));
}
if (defined($text) and $text ne '') {
my $element_command = $languages{$language}->{'commands'}->[$got_count-1];
my $element = $element_command->[0];
my $cmdname = $element_command->[1];
$self->document_warn($self, sprintf(__(
"highlight_syntax.pm: %s: end of \@%s item %d not found"),
$language, $cmdname, $got_count));
}
# note that this check is not the most detailed that could be done, a check
# by command could also be done. Since for now there is only @example
# it is useless, and even if there were other commands, the failure is
# for a language, not a command, so it should not be needed either.
if ($got_count != $languages{$language}->{'counter'}) {
$self->document_warn($self, sprintf(__(
"highlight_syntax.pm: %s: retrieved %d items in HTML; expected %d"),
$language, $got_count, $language_fragments_nr));
}
if (!close (HIGHLIGHT_LANG_OUT)) {
$self->document_warn($self,
sprintf(__("highlight_syntax.pm: error on closing %s: %s"),
$html_result_path_name, $!));
}
}
return 0;
}
sub highlight_open_inline_container_type($$$)
{
my $self = shift;
my $cmdname = shift;
my $command = shift;
if (!scalar(keys(%highlighted_languages_list))) {
my $default_open = $self->default_command_open($cmdname);
if (defined($default_open)) {
return &{$default_open}($self, $cmdname, $command);
} else {
return '';
}
}
my $pending_formatted = $self->get_pending_formatted_inline_content();
if (defined($pending_formatted)) {
$self->associate_pending_formatted_inline_content($command,
$pending_formatted);
}
return '';
}
sub highlight_preformatted_command($$$$$)
{
my $self = shift;
my $cmdname = shift;;
my $command = shift;
my $args = shift;
my $content = shift;
# if no commands were registered nor converted, do not
# warn if the language is known. It means that there was
# no highlighting or some error.
if (exists ($commands{$cmdname})
and exists ($commands{$cmdname}->{'results'})) {
my ($language, $converted_language)
= _get_language($self, $cmdname, $command);
if (exists ($commands{$cmdname}->{'results'}->{$command})
and defined($commands{$cmdname}->{'results'}->{$command})) {
if (not defined($language)) {
$self->document_warn($self, sprintf(__(
"highlight_syntax.pm: output has HTML item for \@%s but no language %s"),
$cmdname, $command));
} else {
$commands{$cmdname}->{'output_languages_counters'}->{$language}++;
if ($self->in_string()) {
return $content;
}
# need to do all the formatting done for content inside
# of @example as it is discarded. So need to do the preformatted
# type formatting, from _convert_preformatted_type() and
# _preformatted_class().
# Since we are formatting @example itself, it is not in the preformatted
# context anymore, so we readd.
my @pre_classes = $self->preformatted_classes_stack();
# NOTE $pre_class_format is setup below to correspond to
# $pre_class_commands{$cmdname}, which cannot be used directly,
# as it is private.
my $pre_class_format = $cmdname;
my $main_cmdname = $cmdname;
if (defined($Texinfo::Common::small_block_associated_command{$cmdname})) {
$pre_class_format
= $Texinfo::Common::small_block_associated_command{$cmdname};
$main_cmdname
= $Texinfo::Common::small_block_associated_command{$cmdname};
}
push @pre_classes, $pre_class_format;
my $pre_class;
foreach my $class (@pre_classes) {
# FIXME maybe add or $pre_class eq 'menu' to override
# 'menu' with 'menu-comment'?
$pre_class = $class unless ($pre_class
and $Texinfo::Commands::preformatted_code_commands{$pre_class}
and !($Texinfo::Commands::preformatted_code_commands{$class}
or $class eq 'menu'));
}
$pre_class = $pre_class.'-preformatted';
# Add classes as done in the default conversion function.
# TODO is it correct? What should be done with @example arguments?
my @classes;
if ($cmdname eq 'example') {
if ($command->{'args'}) {
for my $example_arg (@{$command->{'args'}}) {
# convert or remove all @-commands, using simple ascii and unicode
# characters
my $converted_arg
= Texinfo::Convert::NodeNameNormalization::convert_to_normalized(
$example_arg);
if ($converted_arg ne '') {
push @classes, 'user-' . $converted_arg;
}
}
}
} elsif ($main_cmdname eq 'lisp') {
push @classes, $main_cmdname;
$main_cmdname = 'example';
}
unshift @classes, $main_cmdname;
my $result_content = $commands{$cmdname}->{'results'}->{$command};
# do it here, what was done in preformatted is discarded.
# It should have been correctly registered
# through highlight_open_inline_container_type.
$result_content = $self->get_associated_formatted_inline_content($command)
. $result_content;
$result_content =~ s/^\n/\n\n/; # a newline immediately after a is ignored.
my $preformatted_result_content = $self->html_attribute_class('pre',
[$pre_class]).">".$result_content."
";
return $self->html_attribute_class('div', \@classes).">\n"
.$preformatted_result_content.''."\n";
}
# no error nor verbose message if there was no retrieved information
# for that language
} elsif (defined($language)
and $commands{$cmdname}->{'retrieved_languages_counters'}->{$language}) {
my $cmd_language_input_count
= $commands{$cmdname}->{'input_languages_counters'}->{$language};
my $cmd_language_retrieved_count
= $commands{$cmdname}->{'retrieved_languages_counters'}->{$language};
# Output an message only if the counters are equal, meaning language
# was processed without failure.
# If they are not equal there should have been a message already.
if ($cmd_language_input_count == $cmd_language_retrieved_count) {
$self->document_warn($self, sprintf(__(
"highlight_syntax.pm: output has no HTML item for \@%s %s %s"),
$cmdname, $language, $command));
} elsif ($self->get_conf('VERBOSE') or $self->get_conf('DEBUG')) {
warn "highlight_syntax.pm: output has no HTML item for \@$cmdname $language $command\n";
}
}
}
return &{$self->default_command_conversion($cmdname)}($self, $cmdname,
$command, $args, $content);
}
1;