html32.pm 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # -*-perl-*-
  2. #+##############################################################################
  3. #
  4. # html32.pm: output HTML 3.2
  5. #
  6. # Copyright (C) 2003, 2004, 2007, 2009, 2011, 2013 Free Software
  7. # Foundation, Inc.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 3 of the License,
  12. # or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Originally written by Patrice Dumas.
  23. #
  24. #-##############################################################################
  25. use strict;
  26. use Texinfo::Convert::Converter qw(xml_protect_text);
  27. use vars qw(%commands_formatting %style_commands_formatting);
  28. set_from_init_file('COMPLEX_FORMAT_IN_TABLE', 1);
  29. set_from_init_file('DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN" "http://www.w3.org/TR/html32/loose.dtd">');
  30. set_from_init_file('FRAMESET_DOCTYPE', get_conf('DOCTYPE'));
  31. set_from_init_file('BODYTEXT', 'bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"');
  32. set_from_init_file('BEFORE_OVERVIEW', '');
  33. set_from_init_file('AFTER_OVERVIEW', '');
  34. set_from_init_file('BEFORE_TOC_LINES', '');
  35. set_from_init_file('AFTER_TOC_LINES', '');
  36. # html version for latex2html
  37. set_from_init_file('L2H_HTML_VERSION', '3.2');
  38. # no css, no class
  39. set_from_init_file('NO_CSS', 1);
  40. # no accesskey in html 3.2
  41. set_from_init_file('USE_ACCESSKEY', 0);
  42. set_from_init_file('MENU_SYMBOL', '*');
  43. set_from_init_file('OPEN_QUOTE_SYMBOL', '`');
  44. set_from_init_file('CLOSE_QUOTE_SYMBOL', "'");
  45. foreach my $command ('euro', 'geq', 'leq',
  46. 'bullet', 'equiv', 'expansion', 'point', 'result', 'arrow',
  47. 'quotedblleft', 'quotedblright',
  48. 'quoteleft', 'quoteright',
  49. 'quotedblbase', 'quotesinglbase', 'guillemetleft', 'guillemetright',
  50. 'guillemotleft', 'guillemotright', 'guilsinglleft', 'guilsinglright') {
  51. $commands_formatting{'normal'}->{$command}
  52. = xml_protect_text(undef,
  53. $Texinfo::Convert::Text::text_brace_no_arg_commands{$command});
  54. }
  55. $commands_formatting{'normal'}->{'oe'} = '&#156;';
  56. $commands_formatting{'normal'}->{'OE'} = '&#140;';
  57. foreach my $dots ('dots', 'enddots') {
  58. $commands_formatting{'normal'}->{$dots} = '<small>...</small>';
  59. $commands_formatting{'preformatted'}->{$dots} = '...';
  60. }
  61. foreach my $context ('preformatted', 'normal') {
  62. foreach my $command('sansserif', 'r') {
  63. $style_commands_formatting{$context}->{$command} = {};
  64. }
  65. }
  66. # &quot; is not in html 3.2
  67. sub html32_protect_text($$)
  68. {
  69. my $converter = shift;
  70. my $text = shift;
  71. $text =~ s/&/&amp;/g;
  72. $text =~ s/</&lt;/g;
  73. $text =~ s/>/&gt;/g;
  74. $text =~ s/\"/&#34;/g;
  75. $text =~ s/\f/&#12;/g;
  76. return $text;
  77. }
  78. texinfo_register_formatting_function('protect_text', \&html32_protect_text);
  79. sub html32_convert_text($$$$)
  80. {
  81. my $self = shift;
  82. my $type = shift;
  83. my $command = shift;
  84. my $text = shift;
  85. # do that first because in verb and verbatim, type is 'raw'
  86. if ($self->in_verbatim()) {
  87. return $self->protect_text($text);
  88. }
  89. return $text if ($self->in_raw());
  90. $text = uc($text) if ($self->in_upper_case());
  91. $text = $self->protect_text($text);
  92. if (!$self->in_code() and !$self->in_math()) {
  93. $text =~ s/``/&#34;/g;
  94. $text =~ s/''/&#34;/g;
  95. $text =~ s/---/\x{1F}/g;
  96. $text =~ s/--/-/g;
  97. $text =~ s/\x{1F}/--/g;
  98. }
  99. if (!$self->in_preformatted() and $self->in_space_protected()) {
  100. $text .= '&nbsp;' if (chomp($text));
  101. $text =~ s/ /&nbsp;/g;
  102. }
  103. return $text;
  104. }
  105. texinfo_register_type_formatting('text', \&html32_convert_text);
  106. sub html32_convert_explained_command($$$$)
  107. {
  108. my $self = shift;
  109. my $cmdname = shift;
  110. my $command = shift;
  111. my $args = shift;
  112. my $with_explanation;
  113. return '' if (!$args->[0] or !defined($args->[0]->{'normal'})
  114. or $args->[0]->{'normal'} !~ /\S/);
  115. if ($args->[1] and defined($args->[1]->{'string'})
  116. and $args->[1]->{'string'} =~ /\S/) {
  117. $with_explanation = 1;
  118. }
  119. my $result;
  120. if ($with_explanation) {
  121. $result = $self->convert_tree ($self->gdt('{explained_string} ({explanation})',
  122. {'explained_string' => $args->[0]->{'tree'},
  123. 'explanation' => $args->[1]->{'tree'} }));
  124. } else {
  125. $result = $args->[0]->{'normal'};
  126. }
  127. return $result;
  128. }
  129. foreach my $explained_command (keys(%Texinfo::Common::explained_commands)) {
  130. texinfo_register_command_formatting($explained_command,
  131. \&html32_convert_explained_command);
  132. }
  133. # row in multitable. no thead in html 3.2
  134. sub html32_convert_row_type($$$$) {
  135. my $self = shift;
  136. my $type = shift;
  137. my $command = shift;
  138. my $content = shift;
  139. return $content if ($self->in_string());
  140. if ($content =~ /\S/) {
  141. return '<tr>' . $content . '</tr>' . "\n";
  142. } else {
  143. return '';
  144. }
  145. }
  146. texinfo_register_type_formatting('row', \&html32_convert_row_type);
  147. sub html32_convert_tab_command ($$$$)
  148. {
  149. my $self = shift;
  150. my $cmdname = shift;
  151. my $command = shift;
  152. my $content = shift;
  153. my $row = $command->{'parent'};
  154. my $row_cmdname = $row->{'contents'}->[0]->{'cmdname'};
  155. # FIXME is it right?
  156. $content =~ s/^\s*//;
  157. $content =~ s/\s*$//;
  158. if ($self->in_string()) {
  159. return $content;
  160. }
  161. if ($row_cmdname eq 'headitem') {
  162. return "<th>" . $content . '</th>';
  163. } else {
  164. return "<td>" . $content . '</td>';
  165. }
  166. }
  167. texinfo_register_command_formatting('tab',
  168. \&html32_convert_tab_command);
  169. sub html32_convert_item_command($$$$)
  170. {
  171. my $self = shift;
  172. my $cmdname = shift;
  173. my $command = shift;
  174. my $content = shift;
  175. if ($self->in_string()) {
  176. return $content;
  177. } elsif ($command->{'parent'}->{'type'}
  178. and $command->{'parent'}->{'type'} eq 'row') {
  179. return html32_convert_tab_command ($self, $cmdname, $command, $content);
  180. } else {
  181. return &{$self->default_commands_conversion($cmdname)}($self, $cmdname, $command, $content);
  182. }
  183. }
  184. texinfo_register_command_formatting('item',
  185. \&html32_convert_item_command);
  186. texinfo_register_command_formatting('headitem',
  187. \&html32_convert_item_command);
  188. 1;