xhtml.pm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. # -*-perl-*-
  2. #+##############################################################################
  3. #
  4. # xhtml.pm: convert to well-formed xhtml transitional
  5. # !!!!!!! This is very out of date!!!!
  6. #
  7. # Copyright (C) 2003 Free Software 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. # FIXME this is out of date. There are still the T2H_ prefixes!
  26. # APA: Add SystemLiteral to identify the canonical DTD.
  27. # [Definition:] The SystemLiteral is called the entity's system
  28. # identifier. It is a URI, which may be used to retrieve the entity.
  29. # See http://www.xml.com/axml/target.html#NT-ExternalID
  30. set_default('DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/xhtml1-transitional.dtd">');
  31. set_default('FRAMESET_DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/xhtml1-frameset.dtd">');
  32. # -iso
  33. # if set, ISO8859 characters are used for special symbols (like copyright, etc)
  34. # FIXME certainly obsoleted by t2h_default_set_iso_symbols which should
  35. # certainly ba called indirectly through html_default_load
  36. set_default('USE_ISO', 1);
  37. # horizontal rules
  38. $SMALL_RULE = '<hr size="1"/>';
  39. $DEFAULT_RULE = '<hr/>';
  40. $MIDDLE_RULE = '<hr size="2"/>';
  41. $BIG_RULE = '<hr size="6"/>';
  42. # this is added inside <head></head> after <title> and some <meta name>
  43. # stuff, it can be used for eg. <style>, <script>, <meta> etc. tags.
  44. $EXTRA_HEAD = '';
  45. $print_page_head = \&T2H_XHTML_print_page_head;
  46. $print_page_foot = \&T2H_XHTML_print_page_foot;
  47. $print_frame = \&T2H_XHTML_print_frame;
  48. $button_icon_img = \&T2H_XHTML_button_icon_img;
  49. #FIXME update once it is more stabilized in texi2html.pm
  50. sub T2H_XHTML_print_page_head
  51. {
  52. my $fh = shift;
  53. my $longtitle = "$Texi2HTML::THISDOC{'title_no_texi'}";
  54. $longtitle .= ": $Texi2HTML::NO_TEXI{'This'}" if exists $T2H_NO_TEXI{'This'};
  55. my $doctype = get_conf('doctype');
  56. my $bodytext = get_conf('BODYTEXT');
  57. print $fh <<EOT;
  58. <?xml version="1.0" encoding="iso-8859-1"?>
  59. $doctype
  60. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$T2H_LANG" lang="$T2H_LANG">
  61. $T2H_THISDOC{'copying'}<!-- Created on $Texi2HTML::THISDOC{today} by $Texi2HTML::THISDOC{program} -->
  62. <!--
  63. $Texi2HTML::THISDOC{program_authors}
  64. -->
  65. <head>
  66. <title>$longtitle</title>
  67. <meta name="description" content="$longtitle"/>
  68. <meta name="keywords" content="$longtitle"/>
  69. <meta name="resource-type" content="document"/>
  70. <meta name="distribution" content="global"/>
  71. <meta name="Generator" content="$T2H_THISDOC{program}"/>
  72. $EXTRA_HEAD
  73. </head>
  74. <body $bodytext>
  75. $AFTER_BODY_OPEN
  76. EOT
  77. }
  78. # <span> instead of <font>
  79. sub T2H_XHTML_print_page_foot
  80. {
  81. my $fh = shift;
  82. print $fh <<EOT;
  83. <p>
  84. <span style="font-size: smaller">
  85. This document was generated $ADDRESS
  86. using <a href="$T2H_THISDOC{program_homepage}"><i>$Texi2HTML::THISDOC{program}</i></a>.
  87. </span>
  88. <br/>
  89. $PRE_BODY_CLOSE
  90. </p>
  91. </body>
  92. </html>
  93. EOT
  94. }
  95. sub T2H_XHTML_print_frame
  96. {
  97. my $fh = shift;
  98. my $toc_file = shift;
  99. my $main_file = shift;
  100. my $doctype = get_conf('FRAMESET_DOCTYPE');
  101. print $fh <<EOT;
  102. $doctype
  103. <html>
  104. <head><title>$Texi2HTML::THISDOC{title}</title></head>
  105. <frameset cols="140,*">
  106. <frame name="toc" src="$toc_file"/>
  107. <frame name="main" src="$main_file"/>
  108. </frameset>
  109. </html>
  110. EOT
  111. }
  112. # / in <img>
  113. sub T2H_XHTML_button_icon_img
  114. {
  115. my $button = shift;
  116. my $icon = shift;
  117. my $name = shift;
  118. return '' if (!defined($icon));
  119. if (defined($name) && $name)
  120. {
  121. $name = ": $name";
  122. }
  123. else
  124. {
  125. $name = '';
  126. }
  127. $button = "" if (!defined ($button));
  128. return qq{<img src="$icon" border="0" alt="$button$name" align="middle"/>};
  129. }
  130. $simple_map{'*'} = '<br/>';
  131. # formatting functions
  132. $def_line = \&t2h_xhtml_def_line;
  133. $index_summary = \&t2h_xhtml_index_summary;
  134. $image = \&t2h_xhtml_image;
  135. # need / in <img>
  136. sub t2h_xhtml_image($$$)
  137. {
  138. my $file = shift;
  139. my $base = shift;
  140. my $preformatted = shift;
  141. return "[ $base ]" if ($preformatted);
  142. return "<img src=\"$file\" alt=\"$base\"/>";
  143. }
  144. # process definition commands line @deffn for example
  145. # <u> replaced by <span>
  146. sub t2h_xhtml_def_line($$$$$)
  147. {
  148. my $category = shift;
  149. my $name = shift;
  150. my $type = shift;
  151. my $arguments = shift;
  152. my $index_label = shift;
  153. $index_label = '' if (!defined($index_label));
  154. $name = '' if (!defined($name) or ($name =~ /^\s*$/));
  155. $type = '' if (!defined($type) or $type =~ /^\s*$/);
  156. if (!defined($arguments) or $arguments =~ /^\s*$/)
  157. {
  158. $arguments = '';
  159. }
  160. else
  161. {
  162. $arguments = '<i>' . $arguments . '</i>';
  163. }
  164. my $type_name = '';
  165. $type_name = " $type" if ($type ne '');
  166. $type_name .= ' <b>' . $name . '</b>' if ($name ne '');
  167. $type_name .= $arguments . "\n";
  168. if (! get_conf('DEF_TABLE'))
  169. {
  170. return '<dt>'. '<span style="text-decoration: underline">' . $category . ':</span>' . $type_name . $index_label . "</dt>\n";
  171. }
  172. else
  173. {
  174. return "<tr>\n<td align=\"left\">" . $type_name .
  175. "</td>\n<td align=\"right\">" . $category . $index_label . "</td>\n" . "</tr>\n";
  176. }
  177. }
  178. # There is a br which needs /
  179. sub t2h_xhtml_index_summary($$)
  180. {
  181. my $alpha = shift;
  182. my $nonalpha = shift;
  183. my $join = '';
  184. my $nonalpha_text = '';
  185. my $alpha_text = '';
  186. $join = " &nbsp; \n<br/>\n" if (@$nonalpha and @$alpha);
  187. if (@$nonalpha)
  188. {
  189. $nonalpha_text = join("\n &nbsp; \n", @$nonalpha) . "\n";
  190. }
  191. if (@$alpha)
  192. {
  193. $alpha_text = join("\n &nbsp; \n", @$alpha) . "\n &nbsp; \n";
  194. }
  195. #I18n
  196. return "<table><tr><th valign=\"top\">Jump to: &nbsp; </th><td>" .
  197. $nonalpha_text . $join . $alpha_text . '</td></tr></table>';
  198. }