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_context:
$in_preformatted = $converter->in_preformatted_context () ¶Return true if in preformatted context.
Another function tells if within a preformatted command:
$inside_preformatted = $converter->inside_preformatted () ¶Return true if within a preformatted block command such as
@preformatted, @format.
It is not exactly the same as preformatted context, for instance menu comments are in preformatted context even if not in a preformatted block command.
If in preformatted context, it is possible to get preformatted @-commands and
preformatted types nesting with preformatted_classes_stack:
\@preformatted_nesting = $converter->preformatted_classes_stack () ¶Returns an reference on 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 = '<var>' .$result. '</var>';
last;
}
}
See Simple Customization of Containers on customizing containers preformatted class.