mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-03 13:21:51 +00:00
[1.7.0] Update HTMLDefinition printer with some of the new attributes.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1192 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
008348db21
commit
996ccdbdda
1
NEWS
1
NEWS
@ -12,6 +12,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||
2.0.1, unknown release date
|
||||
- Clean up special case code for <script> tags
|
||||
. Rewire some test-cases to swallow errors rather than expect them
|
||||
. HTMLDefinition printer updated with some of the new attributes
|
||||
|
||||
2.0.0, released 2007-06-20
|
||||
# Completely refactored HTMLModuleManager, decentralizing safety
|
||||
|
@ -3,6 +3,8 @@
|
||||
/**
|
||||
* Represents a document type, contains information on which modules
|
||||
* need to be loaded.
|
||||
* @note This class is inspected by Printer_HTMLDefinition->renderDoctype.
|
||||
* If structure changes, please update that function.
|
||||
*/
|
||||
class HTMLPurifier_Doctype
|
||||
{
|
||||
|
@ -3,6 +3,8 @@
|
||||
/**
|
||||
* Structure that stores an HTML element definition. Used by
|
||||
* HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
|
||||
* @note This class is inspected by HTMLPurifier_Printer_HTMLDefinition.
|
||||
* Please update that class too.
|
||||
*/
|
||||
class HTMLPurifier_ElementDef
|
||||
{
|
||||
|
@ -145,8 +145,8 @@ HTMLPurifier_ConfigSchema::define(
|
||||
* Purifier internals. Many of them, however, are public, and may be
|
||||
* edited by userspace code to tweak the behavior of HTMLDefinition.
|
||||
*
|
||||
* HTMLPurifier_Printer_HTMLDefinition is a notable exception to this
|
||||
* rule: in the interest of comprehensiveness, it will sniff everything.
|
||||
* @note This class is inspected by Printer_HTMLDefinition; please
|
||||
* update that class if things here change.
|
||||
*/
|
||||
class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
{
|
||||
|
@ -15,9 +15,44 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$this->config =& $config;
|
||||
|
||||
$this->def = $config->getHTMLDefinition();
|
||||
$def =& $this->def;
|
||||
|
||||
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
|
||||
|
||||
$ret .= $this->renderDoctype();
|
||||
$ret .= $this->renderEnvironment();
|
||||
$ret .= $this->renderContentSets();
|
||||
$ret .= $this->renderInfo();
|
||||
|
||||
$ret .= $this->end('div');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Doctype table
|
||||
*/
|
||||
function renderDoctype() {
|
||||
$doctype = $this->def->doctype;
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Doctype');
|
||||
$ret .= $this->row('Name', $doctype->name);
|
||||
$ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No');
|
||||
$ret .= $this->row('Default Modules', implode($doctype->modules, ', '));
|
||||
$ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', '));
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders environment table, which is miscellaneous info
|
||||
*/
|
||||
function renderEnvironment() {
|
||||
$def = $this->def;
|
||||
|
||||
$ret = '';
|
||||
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Environment');
|
||||
|
||||
@ -51,13 +86,22 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
$ret .= $this->renderInfo();
|
||||
|
||||
|
||||
$ret .= $this->end('div');
|
||||
|
||||
/**
|
||||
* Renders the Content Sets table
|
||||
*/
|
||||
function renderContentSets() {
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Content Sets');
|
||||
foreach ($this->def->info_content_sets as $name => $lookup) {
|
||||
$ret .= $this->heavyHeader($name);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('td', $this->listifyTagLookup($lookup));
|
||||
$ret .= $this->end('tr');
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@ -69,15 +113,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Elements ($info)');
|
||||
ksort($this->def->info);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Allowed tags', array('colspan' => 2, 'class' => 'heavy'));
|
||||
$ret .= $this->end('tr');
|
||||
$ret .= $this->heavyHeader('Allowed tags', 2);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2));
|
||||
$ret .= $this->end('tr');
|
||||
foreach ($this->def->info as $name => $def) {
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
|
||||
$ret .= $this->element('th', "<$name>" . ($def->safe ? '' : ' (unsafe)'), array('class'=>'heavy' . ($def->safe ? '' : ' unsafe'), 'colspan' => 2));
|
||||
$ret .= $this->end('tr');
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Inline content');
|
||||
@ -109,9 +151,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
}
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Allowed attributes');
|
||||
$ret .= $this->element('td',$this->listifyAttr($def->attr),0,0);
|
||||
$ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
if (!empty($def->required_attr)) {
|
||||
$ret .= $this->row('Required attributes', $this->listify($def->required_attr));
|
||||
}
|
||||
|
||||
$ret .= $this->renderChildren($def->child);
|
||||
}
|
||||
$ret .= $this->end('table');
|
||||
@ -154,6 +200,11 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
'<em>Inline</em>: ' .
|
||||
$this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
|
||||
|
||||
} elseif ($def->type == 'custom') {
|
||||
|
||||
$ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
|
||||
$def->dtd_regex);
|
||||
|
||||
} else {
|
||||
$ret .= $this->element('td',
|
||||
'<em>'.ucfirst($def->type).'</em>: ' .
|
||||
@ -205,6 +256,17 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
return $this->listify($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a heavy header row
|
||||
*/
|
||||
function heavyHeader($text, $num = 1) {
|
||||
$ret = '';
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
|
||||
$ret .= $this->end('tr');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -13,17 +13,6 @@ if (file_exists('printDefinition.settings.php')) {
|
||||
include 'printDefinition.settings.php';
|
||||
}
|
||||
|
||||
/* // sample local definition, obviously needs to be less clunky
|
||||
$html_definition =& $config->getHTMLDefinition(true);
|
||||
$module = new HTMLPurifier_HTMLModule();
|
||||
$module->name = 'Marquee';
|
||||
$module->info['marquee'] = new HTMLPurifier_ElementDef();
|
||||
$module->info['marquee']->content_model = '#PCDATA | Inline';
|
||||
$module->info['marquee']->content_model_type = 'optional';
|
||||
$module->content_sets = array('Inline' => 'marquee');
|
||||
$html_definition->manager->addModule($module);
|
||||
*/
|
||||
|
||||
$printer_html_definition = new HTMLPurifier_Printer_HTMLDefinition();
|
||||
$printer_css_definition = new HTMLPurifier_Printer_CSSDefinition();
|
||||
|
||||
@ -51,6 +40,7 @@ echo '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
.HTMLPurifier_Printer caption {font-size:1.5em; font-weight:bold;
|
||||
width:100%;}
|
||||
.HTMLPurifier_Printer .heavy {background:#99C;text-align:center;}
|
||||
.HTMLPurifier_Printer .unsafe {background:#C99;}
|
||||
dt {font-weight:bold;}
|
||||
</style>
|
||||
<link rel="stylesheet" href="../library/HTMLPurifier/Printer/ConfigForm.css" type="text/css" />
|
||||
|
Loading…
Reference in New Issue
Block a user