// Performs general cleaning (and improving) // of provided book XHTML source code QString CleanSource::Clean(const QString &source) { SettingsStore settings; SettingsStore::CleanLevel level = settings.cleanLevel(); QString newsource = PreprocessSpecialCases(source); switch (level) { case SettingsStore::CleanLevel_PrettyPrint: case SettingsStore::CleanLevel_PrettyPrintTidy: { newsource = level == SettingsStore::CleanLevel_PrettyPrint ? PrettyPrint(newsource) : PrettyPrintTidy(newsource); // Remove any empty comments left over from pretty printing. QStringList css_style_tags = CSSStyleTags(newsource); css_style_tags = RemoveEmptyComments(css_style_tags); return WriteNewCSSStyleTags(newsource, css_style_tags); } case SettingsStore::CleanLevel_Tidy: { // We store the number of CSS style tags before // running Tidy so CleanCSS can remove redundant classes // if tidy added a new style tag int old_num_styles = RobustCSSStyleTagCount(newsource); newsource = HTMLTidy(newsource, Tidy_Clean); newsource = CleanCSS(newsource, old_num_styles); return newsource; } default: // The only thing we will do for Clean when set to None is just prettify // the XML declaration at the top. Xerces puts the xml, DOCTYPE and opening // html tag all on the same line which is ugly to read. return PrettifyDOCTYPEHeader(source); } }
void CleanSourceWidget::readSettings() { SettingsStore settings; SettingsStore::CleanLevel level = settings.cleanLevel(); ui.CleanLevelPrettyPrintGumbo->setChecked(level == SettingsStore::CleanLevel_PrettyPrintGumbo); ui.CleanLevelGumbo->setChecked(level == SettingsStore::CleanLevel_Gumbo); int cleanOn = settings.cleanOn(); ui.CleanOnOpen->setChecked(cleanOn & CLEANON_OPEN); ui.CleanOnSave->setChecked(cleanOn & CLEANON_SAVE); }