私は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;
これよりも複雑であることに注意してください(したがって、2つの配列)。不要なコードを切り取ったところです。