function htmltidy_string in HTML Tidy 7
Same name and namespace in other branches
- 5 htmltidy.module \htmltidy_string()
- 6 htmltidy.module \htmltidy_string()
Process whatever we are given and return the htmltidy response The output and warnings will be returned as arrays by reference.
Parameters
$text: HTML string to be tidied
$input: FALSE if text is for output; TRUE if text is for input
$settings: Filter settings for the string
$errors: An array to be filled with error info
$warnings: An array to be filled with warning info
Return value
The tidied string
1 call to htmltidy_string()
- htmltidy_fragment in ./
htmltidy.module - Tidies an incomplete fragment of HTML by passing it through htmltidy full, then stripping back down to the 'body'.
File
- ./
htmltidy.module, line 134 - The htmltidy module uses Tidy (http://tidy.sf.net) to properly format HTML for saving and display.
Code
function htmltidy_string($text, $input, $settings, &$errors, &$warnings) {
// Fill in any missing configuration with default settings.
$settings += htmltidy_default_settings();
// If the string is for input, and the option to process input is off, simply
// return the string unmolested.
if ($input && !$settings['format']['process_input']) {
return $text;
}
// Make sure that we can find the executable.
if (!file_exists($settings['paths']['app'])) {
$message = "Failed to find htmltidy executable at '%htmltidy_apppath', not using tidy.";
$strings = array(
'%htmltidy_apppath' => $settings['paths']['app'],
);
watchdog('htmltidy', $message, $strings, WATCHDOG_WARNING);
$errors[] = t($message, $strings);
return '';
}
/*
* Do not pass the parameters their default values as defined in the
* documentation for tidy (http://www.w3.org/People/Raggett/tidy/), or weird
* stuff starts to happen.
*/
if ($settings['format']['indent']) {
$args[] = '--indent auto';
}
if (!$settings['debug']['verbose']) {
$args[] = '-q';
}
if (!$settings['format']['wrapphp']) {
$args[] = '--wrap-php no';
}
if (!$settings['format']['tidymark']) {
$args[] = '--tidy-mark no';
}
if ($settings['format']['clean']) {
$args[] = '--clean yes';
}
if ($settings['format']['xhtml']) {
$args[] = '--output-xhtml yes';
}
if ($settings['format']['enclosetext']) {
$args[] = '--enclose-text yes';
}
if ($settings['format']['encloseblocktext']) {
$args[] = '--enclose-block-text yes';
}
if ($settings['format']['wordcleanup']) {
$args[] = '--bare yes';
$args[] = '--word-2000 yes';
$args[] = '--drop-proprietary-attributes yes';
}
if (htmltidy_empty($settings['format']['process_input'], FALSE) && !module_exists('htmltidy_output')) {
$args[] = '--show-body-only yes';
}
// user specified configuration file
$htmltidy_confpath = $settings['paths']['config'];
if (!empty($htmltidy_confpath) && file_exists($htmltidy_confpath)) {
$args[] = '-config ' . $htmltidy_confpath;
}
if (!empty($settings['format']['doctype'])) {
$args[] = '--doctype ' . $settings['format']['doctype'];
}
$args[] = '-wrap ' . intval($settings['format']['wordwrap']);
$args[] = '-utf8';
$args[] = '-modify';
// modify the input file instead of outputting to stdout.
$output = '';
htmltidy_run($text, $settings['paths']['app'], $args, $output, $errors, $warnings);
// Output debugging info.
if ($settings['debug']['warnings'] && user_access('use htmltidy debug mode')) {
$header = "<style type=\"text/css\"> .htmltidy { border: 1px dashed #aaa; background-color: #eee; padding: 1em;\n" . "margin: 1em; float: left; font-family: \"courier new\", sans-serif; font-size: 8pt; color: #050; } </style>";
drupal_set_html_head($header);
if (isset($warnings_filename)) {
$warnings = file_get_contents($warnings_filename);
drupal_set_message("<h3>HTMLTidy Debug</h3><kbd>{$apppath} {$cline} -wrap {$wordwrap} -utf8 -f {$warnings_filename} {$dirty_filename}</kbd>");
}
}
return $output;
}