use Texinfo::Convert::Text qw(convert_to_text text_accents); my $result = convert_to_text($tree); my $accents_text = text_accents($accents, 'utf-8'); # using text conversion options set in $converter derived from # Texinfo::Convert::Converter my $text_options = $converter->{'convert_text_options'}; set_options_code($text_options); my $result_with_converter = convert_to_text($tree, $text_options); reset_options_code($text_options);
The Texinfo Perl module main purpose is to be used in texi2any
to convert
Texinfo to other formats. There is no promise of API stability.
Texinfo::Convert::Text
is a simple backend that converts a Texinfo tree
to simple text. It is used in converters, especially for file names.
The conversion is very simple, and, in the default case, cannot handle
error handling nor some output strings translation.
Converters derived from Texinfo::Convert::Converter should have conversion
text options preset associated to the convert_text_options
key.
The main function is convert_to_text
. The text conversion options
can be modified with the set_*
functions before calling convert_to_text
,
and reset afterwards with the corresponding reset_*
functions.
Convert a Texinfo tree to simple text. $text_options is a hash reference of options. The converter is very simple, and has almost no internal state besides the options. It cannot handle as is output strings translation or error storing.
If the converter option is set in $text_options, some additional features may be available for the conversion of some @-commands, like output strings translation or error reporting.
The NUMBER_SECTIONS
, ASCII_GLYPH
and TEST
options corresponding to
customization variables may be set in $text_options. The following options
may also be set:
If set, the value is considered to be the encoding name texinfo accented
letters should be converted to. This option being set corresponds to the
--enable-encoding
option, or the ENABLE_ENCODING
customization
variable for Info and Plaintext and for some conversion to text in other
formats. For file names in HTML and LaTeX, and for DocBook or Texinfo XML,
this variable should in general be set unless the output encoding is US-ASCII.
If positive, the text is upper-cased, if negative, the text is lower-cased.
A somehow internal option to convert to text more suitable for alphabetical sorting rather than presentation.
If this converter object is passed to the function, some features of this object may be used during conversion. Mostly error reporting and strings translation. See also Texinfo::Convert::Converter.
A reference on a hash. The keys should be format names (like html
,
tex
), and if the corresponding value is set, the format is expanded.
$text is the text appearing within an accent command. $accent_command should be a Texinfo tree element corresponding to an accent command taking an argument. The function returns a transliteration of the accented character. The $converter argument is ignored, but needed for this function to be in argument of functions that need a fallback for accents conversion.
set_options_code
sets $text_options to be in code style.
(mostly --
, ---
, ''
and ``
are kept as is). reset_options_code
undo the effect of set_options_code
.
reset_options_code
should always be called after set_options_code
.
set_options_encoding
sets enabled_encoding
in $text_options
to $encoding. set_options_encoding_if_not_ascii
sets enabled_encoding
in $text_options based on customization options associated to
$customization_information. In that case, enabled_encoding
is set unless
the output encoding is US-ASCII even if ENABLE_ENCODING
is not set.
reset_options_encoding
undo the effect of set_options_encoding
and
set_options_encoding_if_not_ascii
and should always be called after these
functions.
$accents is an accent command that may contain other nested accent commands. The function will format the whole stack of nested accent commands and the innermost text. If $encoding is set, the formatted text is converted to this encoding as much as possible instead of being converted as simple ASCII. If $set_case is positive, the result is meant to be upper-cased, if it is negative, the result is to be lower-cased.
Copyright 2010- Free Software Foundation, Inc. See the source file for all copyright years.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.