我正在使用 php 扩展 tidy-html 来清理 php 输出。我知道 tidy 删除了无效的标签,甚至无法处理 HTML5 doctype,但我使用<menu>
的是 HTML 规范中的标签。但是,<ul>
无论如何它都会改变。
奇怪的是,它以前没有这样做。我改变了整洁的配置,它已经坏了。现在我已经关闭了所有与标签混淆的选项,但它没有帮助。
我的脚本非常冗长:
$tidy_config = array(
'char-encoding' => 'utf8',
'output-encoding' => 'utf8',
'output-html' => true,
'numeric-entities' => false,
'ascii-chars' => false,
'doctype' => 'loose',
'clean' => false,
'bare' => false,
'fix-uri' => true,
'indent' => true,
'indent-spaces' => 2,
'tab-size' => 2,
'wrap-attributes' => true,
'wrap' => 0,
'indent-attributes' => true,
'join-classes' => false,
'join-styles' => false,
'fix-bad-comments' => true,
'fix-backslash' => true,
'replace-color' => false,
'wrap-asp' => false,
'wrap-jste' => false,
'wrap-php' => false,
'wrap-sections' => false,
'drop-proprietary-attributes' => false,
'hide-comments' => false,
'hide-endtags' => false,
'drop-empty-paras' => true,
'quote-ampersand' => true,
'quote-marks' => true,
'quote-nbsp' => true,
'vertical-space' => true,
'wrap-script-literals' => false,
'tidy-mark' => true,
'merge-divs' => false,
'repeated-attributes' => 'keep-last',
'break-before-br' => false
);
$tidy_config2 = array(
'tidy-mark' => false,
'vertical-space' => false,
'hide-comments' => true,
'indent-spaces' => 0,
'tab-size' => 1,
'wrap-attributes' => false,
'numeric-entities' => true,
'ascii-chars' => true,
'hide-endtags' => true,
'indent' => false
);
$tidy_config = array_merge($tidy_config, $tidy_config2);
$dtm = preg_match(self::doctypeMatch, $output, $dt);
$output = tidy_repair_string($output, $tidy_config, 'utf8');
// tidy screws up doctype --fixed
if($dtm)
$output = preg_replace(self::doctypeMatch, $dt[0], $output);
$output = preg_replace('!>[\n\r]+<!', '><', $output);
unset($tidy_config);
return $output;
请注意,它比这更复杂(因此有两个数组)。我刚刚切断了不必要的代码。