function htmltidy_fragment in HTML Tidy 6
Same name and namespace in other branches
- 5 htmltidy.module \htmltidy_fragment()
- 7 htmltidy.module \htmltidy_fragment()
Tidies an incomplete fragment of HTML by passing it through htmltidy full, then stripping back down to the 'body'.
Parameters
$input: html string to be tidied
$errors: an array to be filled with error info
$warnings: an array to be filled with warning info
Return value
the tidied string
2 calls to htmltidy_fragment()
- htmltidy_filter in ./
htmltidy.module - Implementation of hook_filter().
- htmltidy_nodeapi in ./
htmltidy.module
File
- ./
htmltidy.module, line 208 - The theme system, which controls the output of Drupal. The htmltidy module uses Tidy (http://tidy.sf.net) to properly format HTML for saving and display.
Code
function htmltidy_fragment($input, $format, &$errors, &$warnings) {
if ($input) {
// Pretend it's a full document. This declaration just suppresses one of
// the warnings.
if (!strstr($input, '<html') && !strstr($input, '<HTML')) {
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
// Put a new line after the fake headers so our content starts at the
// begining of a line. this way we can get correct line/column info by just
// subtracting one from the line number
$html .= "<html><head><title></title></head><body>\n";
$html .= $input;
$html .= '</body></html>';
}
else {
$html = $input;
}
$output = htmltidy_string($html, $format, $errors, $warnings);
// Remove the html wrapper
if (preg_match('|<body[^>]*>([\\s\\S]*)</body>|', $output, $matches)) {
$output = $matches[1];
}
// fix the line numbers on both errors and warnings arrays (subtract 1 from each)
htmltidy_fix_linenums($errors, -1);
htmltidy_fix_linenums($warnings, -1);
return $output;
}
}