function htmltidy_string in HTML Tidy 5
Same name and namespace in other branches
- 6 htmltidy.module \htmltidy_string()
- 7 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
$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
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 147
Code
function htmltidy_string($input, &$errors, &$warnings) {
$apppath = variable_get('htmltidy_apppath', '/usr/bin/tidy');
if (!file_exists($apppath)) {
$message = t("Failed to find htmltidy executable at '%htmltidy_apppath', not using tidy.", array(
'%htmltidy_apppath' => $apppath,
));
watchdog('htmltidy', $emssage, WATCHDOG_WARNING);
$errors[] = $message;
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 (variable_get('htmltidy_indent', 1)) {
$args[] = '--indent auto';
}
if (!variable_get('htmltidy_verbose', 0)) {
$args[] = '-q';
}
if (!variable_get('htmltidy_wrapphp', 1)) {
$args[] = '--wrap-php no';
}
if (!variable_get('htmltidy_tidymark', 1)) {
$args[] = '--tidy-mark no';
}
if (variable_get('htmltidy_clean', 1)) {
$args[] = '--clean yes';
}
if (variable_get('htmltidy_xhtml', 0)) {
$args[] = '--output-xhtml yes';
}
if (variable_get('htmltidy_enclosetext', 0)) {
$args[] = '--enclose-text yes';
}
if (variable_get('htmltidy_encloseblocktext', 0)) {
$args[] = '--enclose-block-text yes';
}
if (variable_get('htmltidy_wordcleanup', 0)) {
$args[] = '--bare yes';
$args[] = '--word-2000 yes';
$args[] = '--drop-proprietary-attributes yes';
}
if (variable_get('htmltidy_process_input', FALSE) && !module_exists('htmltidy_output')) {
$args[] = '--show-body-only yes';
}
// user specified configuration file
$htmltidy_confpath = variable_get('htmltidy_confpath', '');
if (file_exists($htmltidy_confpath)) {
$args[] = '--config ' . $htmltidy_confpath;
}
$args[] = '--doctype ' . variable_get('htmltidy_doctype', 'auto');
$args[] = '-wrap ' . variable_get('htmltidy_wordwrap', 0);
$args[] = '-utf8';
$args[] = '-modify';
// modify the input file instead of outputting to stdout.
htmltidy_run($input, $args, $output, $errors, $warnings);
/*
// Output debugging info.
if (variable_get('htmltidy_warnings', 0) && 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);
// Run Tidy a second time to get line numbers right.
if (variable_get('htmltidy_runtwice', 0)) {
system("$apppath $cline -wrap $wordwrap -utf8 -f $warningsFilename $dirtyFilename");
}
$warnings = file_get_contents($warningsFilename);
drupal_set_message("<h3>HTMLTidy Debug</h3><kbd>$apppath $cline -wrap $wordwrap -utf8 -f $warningsFilename $dirtyFilename</kbd>");
}
*/
return $output;
}