0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +00:00

Massive augmentation of ConfigDoc.

- Generate name to expanded name for types
- Change XML format so that constraints are grouped together
- Table-ize constraints
- Enable HTML output in descriptions
- Run output through Tidy to make it easier to read
- Load stylesheet

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@403 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-09-10 22:17:22 +00:00
parent 2299f0c831
commit 9e6953e619
4 changed files with 71 additions and 18 deletions

View File

@ -28,6 +28,20 @@ $definition = HTMLPurifier_ConfigDef::instance();
$purifier = new HTMLPurifier(); $purifier = new HTMLPurifier();
// generate type XML document
$types_document = new DOMDocument('1.0', 'UTF-8');
$types_root = $types_document->createElement('types');
$types_document->appendChild($types_root);
$types_document->formatOutput = true;
foreach ($definition->types as $name => $expanded_name) {
$types_type = $types_document->createElement('type', $expanded_name);
$types_type->setAttribute('id', $name);
$types_root->appendChild($types_type);
}
$types_document->save('types.xml');
// generate directive XML document
$dom_document = new DOMDocument('1.0', 'UTF-8'); $dom_document = new DOMDocument('1.0', 'UTF-8');
$dom_root = $dom_document->createElement('configdoc'); $dom_root = $dom_document->createElement('configdoc');
$dom_document->appendChild($dom_root); $dom_document->appendChild($dom_root);
@ -63,7 +77,10 @@ foreach($definition->info as $namespace_name => $namespace_info) {
$dom_directive->appendChild( $dom_directive->appendChild(
$dom_document->createElement('name', $name) $dom_document->createElement('name', $name)
); );
$dom_directive->appendChild(
$dom_constraints = $dom_document->createElement('constraints');
$dom_directive->appendChild($dom_constraints);
$dom_constraints->appendChild(
$dom_document->createElement('type', $info->type) $dom_document->createElement('type', $info->type)
); );
@ -113,6 +130,20 @@ $html_output = $xsl_processor->transformToXML($dom_document);
// some slight fudges to preserve backwards compatibility // some slight fudges to preserve backwards compatibility
$html_output = str_replace('/>', ' />', $html_output); // <br /> not <br> $html_output = str_replace('/>', ' />', $html_output); // <br /> not <br>
$html_output = str_replace(' xmlns=""', '', $html_output); // rm unnecessary xmlns
if (class_exists('Tidy')) {
// cleanup output
$config = array(
'indent' => true,
'output-xhtml' => true,
'wrap' => 80
);
$tidy = new Tidy;
$tidy->parseString($html_output, $config, 'utf8');
$tidy->cleanRepair();
$html_output = (string) $tidy;
}
// write it to a file (todo: parse into seperate pages) // write it to a file (todo: parse into seperate pages)
file_put_contents("$xsl_stylesheet_name.html", $html_output); file_put_contents("$xsl_stylesheet_name.html", $html_output);

View File

@ -0,0 +1,6 @@
table {border-collapse:collapse;}
table td, table th {padding:0.2em;}
table.constraints {margin:0 0 1em;}
table.constraints th {text-align:left;padding-left:0.4em;}
table.constraints td {padding-right:0.4em;}

View File

@ -9,21 +9,18 @@
encoding = "UTF-8" encoding = "UTF-8"
doctype-public = "-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-public = "-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent = "yes" indent = "no"
media-type = "text/html" media-type = "text/html"
/> />
<!-- <xsl:variable name="typeLookup" select="document('../types.xml')" />
TODO:
o Table-ize types
o Include CSS
-->
<xsl:template match="/"> <xsl:template match="/">
<html lang="en" xml:lang="en"> <html lang="en" xml:lang="en">
<head> <head>
<title><xsl:value-of select="/configdoc/title" /> Configuration Documentation</title> <title><xsl:value-of select="/configdoc/title" /> Configuration Documentation</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="styles/plain.css" />
</head> </head>
<body> <body>
<xsl:apply-templates /> <xsl:apply-templates />
@ -51,8 +48,26 @@
<xsl:template match="directive/name"> <xsl:template match="directive/name">
<h3 id="{../@id}"><xsl:value-of select="text()" /></h3> <h3 id="{../@id}"><xsl:value-of select="text()" /></h3>
</xsl:template> </xsl:template>
<xsl:template match="directive/type"> <xsl:template match="directive/constraints">
<div class="type"><xsl:value-of select="text()" /></div> <table class="constraints">
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="directive//description">
<div class="description">
<xsl:copy-of select="div/node()" />
</div>
</xsl:template>
<xsl:template match="constraints/type">
<tr>
<th>Type:</th>
<td>
<xsl:variable name="type" select="text()" />
<xsl:attribute name="class">type type-<xsl:value-of select="$type" /></xsl:attribute>
<xsl:value-of select="$typeLookup/types/type[@id=$type]/text()" />
</td>
</tr>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -39,17 +39,18 @@ class HTMLPurifier_ConfigDef {
/** /**
* Lookup table of allowed types. * Lookup table of allowed types.
* @todo Add descriptions
*/ */
var $types = array( var $types = array(
'string' => true, 'string' => 'String',
'istring' => true, 'istring' => 'Case-insensitive string',
'int' => true, 'int' => 'Integer',
'float' => true, 'float' => 'Float',
'bool' => true, 'bool' => 'Boolean',
'lookup' => true, 'lookup' => 'Lookup array',
'list' => true, 'list' => 'Array list',
'hash' => true, 'hash' => 'Associative array',
'mixed' => true 'mixed' => 'Mixed'
); );
/** /**