10.6 Conversion in Preformatted Context

Conversion and formatting functions should test if in preformatted context to convert accordingly. See Init File Expansion Contexts: Normal, Preformatted, Code, String, Math.

To determine if in preformatted context, the functions is in_preformatted:

Function: $in_preformatted = $converter->in_preformatted ()

Return true if in preformatted context.

If in preformatted context, it is possible to get preformatted @-commands and preformatted types nesting with preformatted_classes_stack:

Function: @preformatted_nesting = $converter->preformatted_classes_stack ()

Returns an array containing the block preformatted @-commands such as @example, @display or @menu names without the leading @ and the HTML attribute class preformatted container names, in order of appearance.

The %Texinfo::Commands::preformatted_code_commands hash can be used to determine if a preformatted command is to be formatted as code (see (texi2any_internals)Texinfo::Commands %preformatted_code_commands).

my @pre_classes = $converter->preformatted_classes_stack();
foreach my $pre_class (@pre_classes) {
  if ($Texinfo::Commands::preformatted_code_commands{$pre_class}) {
    $result = '<code>' .$result. '</code>';
    last;
  }
}

See Simple Customization of Containers on customizing containers preformatted class.