[PATCH] Ruby 1.8.4 RDoc HTML Cleanups and HTML Language Support
From:
Paul Duncan <pabs@...>
Date:
2005-12-30 00:07:38 UTC
List:
ruby-core #7028
Hi, Attached is a patch against Ruby 1.8.4 which cleans up the HTML output of RDoc. Here's a list of the changes: * properly quote bare element attributes * terminates dangling elements (e.g. <img>, <br>, <link>, etc) * adds an --html-language command-line option and corresponding 'html_lang' to specify HTML language (e.g. the lang and xml:lang attributes) * makes image filename suffix recognition case-insensitive * converts "CVS" to the more HTML-friendly "<acronym title='Concurrent Versioning System'>CVS</acronym>" * adds missing type attributes to style elements * allows UTF-8 as a valid charset option, and switches HTML template to use %charset% and %html_lang% instead of hard- coded 'utf-8' and 'en', respectively * miscellaneous small changes (> => >, lower-case a few element names for consistency, etc) -- Paul Duncan <pabs@pablotron.org> OpenPGP Key ID: 0x82C29562 http://www.pablotron.org/ http://www.paulduncan.org/
Attachments (2)
ruby-1.8.4-rdoc_html_cleanup.diff
(20.1 KB, text/x-diff)
Only in ruby-1.8.4/lib/rdoc: .foo2.html.swp
diff -ur ruby-1.8.4-orig/lib/rdoc/README ruby-1.8.4/lib/rdoc/README
--- ruby-1.8.4-orig/lib/rdoc/README 2004-12-04 00:38:15.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/README 2005-12-29 18:45:37.000000000 -0500
@@ -146,6 +146,11 @@
[<tt>--help-output</tt>]
explain the various output options.
+[<tt>--html-language</tt> _language_]
+ Set the language (the lang and xml:lang attributes) for the
+ generated HTML. Can be any valid RFC 1766-style language
+ string. Defaults to 'en-US' if unspecified.
+
[<tt>--image-format</tt> <i>gif/png/jpg/jpeg</i>]
sets output image format for diagrams. Can be png, gif, jpeg,
jpg. If this option is omitted, png is used. Requires --diagram.
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/html_generator.rb ruby-1.8.4/lib/rdoc/generators/html_generator.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/html_generator.rb 2005-02-12 05:57:20.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/html_generator.rb 2005-12-29 18:14:46.000000000 -0500
@@ -151,9 +151,9 @@
end
if (type == "http" || type == "link") &&
- url =~ /\.(gif|png|jpg|jpeg|bmp)$/
+ url =~ /\.(gif|png|jpg|jpeg|bmp)$/i
- "<img src=\"#{url}\">"
+ "<img src=\"#{url}\"/>"
else
"<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
end
@@ -636,6 +636,7 @@
add_table_of_sections
@values["charset"] = @options.charset
+ @values['html_lang'] = @options.html_lang
@values["style_url"] = style_url(path, @options.css)
d = markup(@context.comment)
@@ -804,6 +805,7 @@
add_table_of_sections
@values["charset"] = @options.charset
+ @values["html_lang"] = @options.html_lang
@values["href"] = path
@values["style_url"] = style_url(path, @options.css)
@@ -1027,7 +1029,8 @@
'title' => CGI.escapeHTML(index_name),
'code' => code_body,
'style_url' => style_url(file_path, @options.css),
- 'charset' => @options.charset
+ 'charset' => @options.charset,
+ 'html_lang' => @options.html_lang
}
template.write_html_on(f, values)
end
@@ -1322,6 +1325,7 @@
'list_title' => CGI.escapeHTML(title),
'index_url' => main_url,
'charset' => @options.charset,
+ 'html_lang' => @options.html_lang,
'style_url' => style_url('', @options.css),
}
@@ -1341,7 +1345,8 @@
values = {
"initial_page" => main_url,
'title' => CGI.escapeHTML(@options.title),
- 'charset' => @options.charset
+ 'charset' => @options.charset,
+ 'html_lang' => @options.html_lang,
}
if @options.inline_source
values['inline_source'] = true
@@ -1444,6 +1449,7 @@
def generate_xml
values = {
'charset' => @options.charset,
+ 'html_lang' => @options.html_lang,
'files' => gen_into(@files),
'classes' => gen_into(@classes),
'title' => CGI.escapeHTML(@options.title),
Only in ruby-1.8.4/lib/rdoc/generators/template/html: .html.rb.swp
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/template/html/hefss.rb ruby-1.8.4/lib/rdoc/generators/template/html/hefss.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/template/html/hefss.rb 2003-12-01 02:12:48.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/template/html/hefss.rb 2005-12-29 18:00:35.000000000 -0500
@@ -111,10 +111,10 @@
BODY = %{
-<html><head>
+<html lang='%html_lang%' xml:lang="%html_lang%'><head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
- <link rel=StyleSheet href="%style_url%" type="text/css" media=screen>
+ <link rel='stylesheet' href="%style_url%" type="text/css" media='screen' />
<script type="text/javascript" language="JavaScript">
<!--
function popCode(url) {
@@ -138,9 +138,9 @@
ENDIF:description
IF:requires
-<table cellpadding=5 width="100%">
+<table cellpadding='5' width="100%">
<tr><td class="tablesubtitle">Required files</td></tr>
-</table><br>
+</table><br />
<div class="name-list">
START:requires
HREF:aref:name:
@@ -149,9 +149,9 @@
</div>
IF:methods
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Subroutines and Functions</td></tr>
-</table><br>
+</table><br />
<div class="name-list">
START:methods
HREF:aref:name:,
@@ -160,10 +160,10 @@
ENDIF:methods
IF:attributes
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Arguments</td></tr>
-</table><br>
-<table cellspacing=5>
+</table><br />
+<table cellspacing="5">
START:attributes
<tr valign="top">
IF:rw
@@ -180,10 +180,10 @@
ENDIF:attributes
IF:classlist
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Modules</td></tr>
-</table><br>
-%classlist%<br>
+</table><br />
+%classlist%<br />
ENDIF:classlist
!INCLUDE! <!-- method descriptions -->
@@ -198,8 +198,8 @@
<table width="100%">
<tr class="title-row">
<td><table width="100%"><tr>
- <td class="big-title-font" colspan=2><font size=-3><B>File</B><BR></font>%short_name%</td>
- <td align="right"><table cellspacing=0 cellpadding=2>
+ <td class="big-title-font" colspan="2"><font size="-3"><b>File</b><br /></font>%short_name%</td>
+ <td align="right"><table cellspacing='0' cellpadding='2'>
<tr>
<td class="small-title-font">Path:</td>
<td class="small-title-font">%full_path%
@@ -221,20 +221,20 @@
###################################################################
CLASS_PAGE = %{
-<table width="100%" border=0 cellspacing=0>
+<table width="100%" border='0' cellspacing='0'>
<tr class="title-row">
<td class="big-title-font">
- <font size=-3><B>%classmod%</B><BR></font>%full_name%
+ <font size='-3'><b>%classmod%</b><br /></font>%full_name%
</td>
<td align="right">
- <table cellspacing=0 cellpadding=2>
+ <table cellspacing="0" cellpadding="2">
<tr valign="top">
<td class="small-title-font">In:</td>
<td class="small-title-font">
START:infiles
HREF:full_path_url:full_path:
IF:cvsurl
- (<a href="%cvsurl%">CVS</a>)
+ (<a href="%cvsurl%"><acronym title='Concurrent Versioning System'>CVS</acronym></a>)
ENDIF:cvsurl
END:infiles
</td>
@@ -256,14 +256,14 @@
</table>
</td>
</tr>
-</table><br>
+</table><br />
}
###################################################################
METHOD_LIST = %{
IF:includes
-<div class="tablesubsubtitle">Uses</div><br>
+<div class="tablesubsubtitle">Uses</div><br />
<div class="name-list">
START:includes
<span class="method-name">HREF:aref:name:</span>
@@ -278,7 +278,7 @@
<tr><td class="tablesubtitle">%type% %category% methods</td></tr>
</table>
START:methods
-<table width="100%" cellspacing = 0 cellpadding=5 border=0>
+<table width="100%" cellspacing='0' cellpadding='5' border='0'>
<tr><td class="methodtitle">
<a name="%aref%">
<b>%name%</b>%params%
@@ -304,10 +304,12 @@
########################## Source code ##########################
SRC_PAGE = %{
-<html>
+<html lang='%html_lang%' xml:lang='%html_lang%'>
<head><title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
-<style>
+<style type='text/css'>
+<!--
+body { background-color: #bbb; }
.kw { color: #3333FF; font-weight: bold }
.cmt { color: green; font-style: italic }
.str { color: #662222; font-style: italic }
@@ -321,9 +323,10 @@
.ruby-operator { color: #111111; }
.ruby-regexp { color: #662222; }
.ruby-value { color: #662222; font-style: italic }
+-->
</style>
</head>
-<body bgcolor="#BBBBBB">
+<body>
<pre>%code%</pre>
</body>
</html>
@@ -336,10 +339,10 @@
}
FILE_INDEX = %{
-<html>
+<html lang='%html_lang%' xml:lang='%html_lang%'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
-<style>
+<style type='text/css'>
<!--
body {
background-color: #bbbbbb;
@@ -368,7 +371,7 @@
<body>
<div class="banner">%list_title%</div>
START:entries
-<a href="%href%">%name%</a><br>
+<a href="%href%">%name%</a><br />
END:entries
</body></html>
}
@@ -377,7 +380,7 @@
METHOD_INDEX = FILE_INDEX
INDEX = %{
-<html>
+<html lang='%html_lang%' xml:lang='%html_lang%'>
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/template/html/html.rb ruby-1.8.4/lib/rdoc/generators/template/html/html.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/template/html/html.rb 2004-12-11 20:37:24.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/template/html/html.rb 2005-12-29 18:02:15.000000000 -0500
@@ -246,7 +246,7 @@
}
HEADER = XHTML_PREAMBLE + %{
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%html_lang%" lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
@@ -358,7 +358,7 @@
</a>
ENDIF:full_path_url
IF:cvsurl
- (<a href="%cvsurl%">CVS</a>)
+ (<a href="%cvsurl%"><acronym title='Concurrent Versioning System'>CVS</acronym></a>)
ENDIF:cvsurl
<br />
END:infiles
@@ -504,7 +504,7 @@
START:aliases
<tr class="top-aligned-row context-row">
<td class="context-item-name">%old_name%</td>
- <td>-></td>
+ <td>-></td>
<td class="context-item-value">%new_name%</td>
</tr>
IF:desc
@@ -627,7 +627,7 @@
#####################################################################
SRC_PAGE = XHTML_PREAMBLE + %{
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
@@ -654,7 +654,7 @@
%list_title%
-->
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%list_title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
@@ -687,7 +687,7 @@
%title%
-->
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/template/html/kilmer.rb ruby-1.8.4/lib/rdoc/generators/template/html/kilmer.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/template/html/kilmer.rb 2004-12-28 21:15:52.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/template/html/kilmer.rb 2005-12-29 18:02:57.000000000 -0500
@@ -91,10 +91,10 @@
BODY = %{
-<html><head>
+<html lang="%html_lang%" xml:lang="%html_lang%"><head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
- <link rel=StyleSheet href="%style_url%" type="text/css" media=screen>
+ <link rel='stylesheet' href="%style_url%" type="text/css" media='screen' />
<script type="text/javascript" language="JavaScript">
<!--
function popCode(url) {
@@ -118,9 +118,9 @@
ENDIF:description
IF:requires
-<table cellpadding=5 width="100%">
+<table cellpadding='5' width="100%">
<tr><td class="tablesubtitle">Required files</td></tr>
-</table><br>
+</table><br />
<div class="name-list">
START:requires
HREF:aref:name:
@@ -129,7 +129,7 @@
</div>
IF:methods
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Methods</td></tr>
</table><br>
<div class="name-list">
@@ -152,10 +152,10 @@
ENDIF:sectitle
IF:attributes
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Attributes</td></tr>
-</table><br>
-<table cellspacing=5>
+</table><br />
+<table cellspacing="5">
START:attributes
<tr valign="top">
IF:rw
@@ -172,10 +172,10 @@
ENDIF:attributes
IF:classlist
-<table cellpadding=5 width="100%">
+<table cellpadding="5" width="100%">
<tr><td class="tablesubtitle">Classes and Modules</td></tr>
-</table><br>
-%classlist%<br>
+</table><br />
+%classlist%<br />
ENDIF:classlist
!INCLUDE! <!-- method descriptions -->
@@ -192,13 +192,13 @@
<table width="100%">
<tr class="title-row">
<td><table width="100%"><tr>
- <td class="big-title-font" colspan=2><font size=-3><B>File</B><BR></font>%short_name%</td>
- <td align="right"><table cellspacing=0 cellpadding=2>
+ <td class="big-title-font" colspan='2'><font size=-3><b>File</b><br /></font>%short_name%</td>
+ <td align="right"><table cellspacing="0" cellpadding="2">
<tr>
<td class="small-title-font">Path:</td>
<td class="small-title-font">%full_path%
IF:cvsurl
- (<a href="%cvsurl%">CVS</a>)
+ (<a href="%cvsurl%"><acronym title='Concurrent Versioning System'>CVS</acronym></a>)
ENDIF:cvsurl
</td>
</tr>
@@ -209,26 +209,26 @@
</table>
</td></tr></table></td>
</tr>
-</table><br>
+</table><br />
_FILE_PAGE_
###################################################################
CLASS_PAGE = %{
-<table width="100%" border=0 cellspacing=0>
+<table width="100%" border="0" cellspacing="0">
<tr class="title-row">
<td class="big-title-font">
- <font size=-3><B>%classmod%</B><BR></font>%full_name%
+ <font size="-3"><b>%classmod%</b><br /></font>%full_name%
</td>
<td align="right">
- <table cellspacing=0 cellpadding=2>
+ <table cellspacing="0" cellpadding="2">
<tr valign="top">
<td class="small-title-font">In:</td>
<td class="small-title-font">
START:infiles
HREF:full_path_url:full_path:
IF:cvsurl
- (<a href="%cvsurl%">CVS</a>)
+ (<a href="%cvsurl%"><acronym title='Concurrent Versioning System'>CVS</acronym></a>)
ENDIF:cvsurl
END:infiles
</td>
@@ -250,14 +250,14 @@
</table>
</td>
</tr>
-</table><br>
+</table><br />
}
###################################################################
METHOD_LIST = %{
IF:includes
-<div class="tablesubsubtitle">Included modules</div><br>
+<div class="tablesubsubtitle">Included modules</div><br />
<div class="name-list">
START:includes
<span class="method-name">HREF:aref:name:</span>
@@ -272,7 +272,7 @@
<tr><td class="tablesubtitle">%type% %category% methods</td></tr>
</table>
START:methods
-<table width="100%" cellspacing = 0 cellpadding=5 border=0>
+<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr><td class="methodtitle">
<a name="%aref%">
IF:callseq
@@ -316,10 +316,11 @@
########################## Source code ##########################
SRC_PAGE = %{
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head><title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
-<style>
+<style type='text/css'>
+body { background-color: #fff; }
.ruby-comment { color: green; font-style: italic }
.ruby-constant { color: #4433aa; font-weight: bold; }
.ruby-identifier { color: #222222; }
@@ -335,7 +336,7 @@
.re { color: #662222; }
</style>
</head>
-<body bgcolor="white">
+<body>
<pre>%code%</pre>
</body>
</html>
@@ -348,7 +349,7 @@
}
FILE_INDEX = %{
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
<style>
@@ -389,7 +390,7 @@
METHOD_INDEX = FILE_INDEX
INDEX = %{
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/template/html/old_html.rb ruby-1.8.4/lib/rdoc/generators/template/html/old_html.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/template/html/old_html.rb 2004-05-23 21:48:37.000000000 -0400
+++ ruby-1.8.4/lib/rdoc/generators/template/html/old_html.rb 2005-12-29 18:04:28.000000000 -0500
@@ -297,10 +297,10 @@
HEADER = %{
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="%charset%"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
@@ -566,7 +566,7 @@
SRC_PAGE = %{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
<title>%title%</title>
@@ -586,7 +586,7 @@
FILE_INDEX = %{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
<title>%list_title%</title>
@@ -630,7 +630,7 @@
INDEX = %{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
<title>%title%</title></head>
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/template/html/one_page_html.rb ruby-1.8.4/lib/rdoc/generators/template/html/one_page_html.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/template/html/one_page_html.rb 2004-03-24 12:01:11.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/template/html/one_page_html.rb 2005-12-29 18:04:34.000000000 -0500
@@ -79,7 +79,7 @@
ONE_PAGE = %{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
+<html lang="%html_lang%" xml:lang="%html_lang%">
<head>
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
diff -ur ruby-1.8.4-orig/lib/rdoc/generators/xml_generator.rb ruby-1.8.4/lib/rdoc/generators/xml_generator.rb
--- ruby-1.8.4-orig/lib/rdoc/generators/xml_generator.rb 2003-12-01 02:12:48.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/generators/xml_generator.rb 2005-12-29 18:05:09.000000000 -0500
@@ -71,9 +71,10 @@
#
def generate_xml
values = {
- 'charset' => @options.charset,
- 'files' => gen_into(@files),
- 'classes' => gen_into(@classes)
+ 'charset' => @options.charset,
+ 'html_lang' => @options.html_lang,
+ 'files' => gen_into(@files),
+ 'classes' => gen_into(@classes)
}
# this method is defined in the template file
diff -ur ruby-1.8.4-orig/lib/rdoc/options.rb ruby-1.8.4/lib/rdoc/options.rb
--- ruby-1.8.4-orig/lib/rdoc/options.rb 2004-11-20 10:02:56.000000000 -0500
+++ ruby-1.8.4/lib/rdoc/options.rb 2005-12-29 18:47:19.000000000 -0500
@@ -65,6 +65,9 @@
# character-set
attr_reader :charset
+ # html language
+ attr_reader :html_lang
+
# should source code be included inline, or displayed in a popup
attr_reader :inline_source
@@ -157,6 +160,11 @@
"Show method source code inline, rather\n" +
"than via a popup link" ],
+ [ "--html-language", "-L", 'lang',
+ "Set the HTML language. Can be any RFC 1766\n" +
+ "format string. Defaults to 'en-US' if\n" +
+ "unspecified." ],
+
[ "--line-numbers", "-N", nil,
"Include line numbers in the source code" ],
@@ -363,6 +371,7 @@
@include_line_numbers = false
@extra_accessor_flags = {}
@promiscuous = false
+ @html_lang = 'en-US'
@css = nil
@webcvs = nil
@@ -372,6 +381,8 @@
'Shift_JIS'
when /^E/i
'EUC-JP'
+ when /^UTF/i
+ 'UTF-8'
else
'iso-8859-1'
end
@@ -387,6 +398,7 @@
when "--charset" then @charset = arg
when "--debug" then $DEBUG = true
when "--exclude" then @exclude << Regexp.new(arg)
+ when "--html-language" then @html_lang = arg
when "--inline-source" then @inline_source = true
when "--line-numbers" then @include_line_numbers = true
when "--main" then @main_page = arg
signature.asc
(189 Bytes, application/pgp-signature)