Skip to content

Commit

Permalink
Add option to bypass HTML Tidy completely.
Browse files Browse the repository at this point in the history
  • Loading branch information
baumgarr committed Jul 24, 2017
1 parent e97dac6 commit b7a865b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
12 changes: 9 additions & 3 deletions dialog/preferences/debugpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ DebugPreferences::DebugPreferences(QWidget *parent) :
mainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
setLayout(mainLayout);

strictDTD = new QCheckBox(tr("Strict note checking."),this);
strictDTD->setChecked(global.strictDTD);
strictDTD = new QCheckBox(tr("Bypass strict note checking. *"),this);
strictDTD->setChecked(!global.strictDTD);
bypassTidy = new QCheckBox(tr("Bypass HTML Tidy. *"), this);
bypassTidy->setChecked(global.bypassTidy);
disableUploads = new QCheckBox(tr("Disable uploads to server."),this);
disableImageHighlight = new QCheckBox(tr("Disable image search highlighting."), this);
showLidColumn = new QCheckBox(tr("Show LID column (requires restart)."));
Expand All @@ -53,6 +55,7 @@ DebugPreferences::DebugPreferences(QWidget *parent) :
mainLayout->addWidget(nonAsciiSortBug,row++,1);
mainLayout->addWidget(disableImageHighlight,row++,1);
mainLayout->addWidget(strictDTD,row++,1);
mainLayout->addWidget(bypassTidy, row++, 1);
mainLayout->addWidget(forceUTF8, row++, 1);

#ifndef _WIN32
Expand Down Expand Up @@ -93,6 +96,8 @@ DebugPreferences::DebugPreferences(QWidget *parent) :
debugLevel->setCurrentIndex(index);
mainLayout->addWidget(debugLevelLabel,row,0);
mainLayout->addWidget(debugLevel,row++,1);
mainLayout->addWidget(new QLabel(" "), row++, 0);
mainLayout->addWidget(new QLabel(tr("* Note: Enabling can cause sync issues.")), row++, 0);
this->setFont(global.getGuiFont(font()));

}
Expand Down Expand Up @@ -129,7 +134,8 @@ void DebugPreferences::saveValues() {
global.settings->endGroup();
global.setAutoSaveInterval(autoSaveInterval->value());
global.disableUploads = disableUploads->isChecked();
global.setStrictDTD(strictDTD->isChecked());
global.setStrictDTD(!strictDTD->isChecked());
global.setBypassTidy(bypassTidy->isChecked());

#ifndef _WIN32
global.setInterceptSigHup(interceptSigHup->isChecked());
Expand Down
1 change: 1 addition & 0 deletions dialog/preferences/debugpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DebugPreferences : public QWidget
QCheckBox *nonAsciiSortBug;
QCheckBox *disableImageHighlight;
QCheckBox *strictDTD;
QCheckBox *bypassTidy;
QCheckBox *forceUTF8;
QCheckBox *interceptSigHup;
QCheckBox *multiThreadSave;
Expand Down
21 changes: 21 additions & 0 deletions global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void Global::setup(StartupConfig startupConfig, bool guiAvailable) {
indexPDFLocally=getIndexPDFLocally();
forceSearchLowerCase=getForceSearchLowerCase();
strictDTD = getStrictDTD();
bypassTidy = getBypassTidy();
forceUTF8 = getForceUTF8();


Expand Down Expand Up @@ -579,6 +580,26 @@ bool Global::getStrictDTD() {




void Global::setBypassTidy(bool value) {
settings->beginGroup("Debugging");
settings->setValue("bypassTidy",value);
settings->endGroup();
bypassTidy=value;
}


bool Global::getBypassTidy() {
settings->beginGroup("Debugging");
bool value = settings->value("bypassTidy",true).toBool();
settings->endGroup();
bypassTidy = value;
return value;
}




bool Global::getForceUTF8() {
settings->beginGroup("Debugging");
bool value = settings->value("forceUTF8",true).toBool();
Expand Down
3 changes: 3 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ class Global
bool strictDTD; // Should we do strict enml checking?
bool getStrictDTD(); // Should we do strict enml checking? (read from settings)
void setStrictDTD(bool value); // save strict enml checking
bool bypassTidy; // Bypass HTML Tidy
bool getBypassTidy(); // should we bypass HTML tidy?
void setBypassTidy(bool value); // Set if we should bypass HTML tidy.
QString getEditorStyle(bool colorOnly); // Get note editor style overrides
QString getEditorFontColor(); // Get the editor font color from the theme
QString getEditorBackgroundColor(); // Get the editor background color from the theme
Expand Down
6 changes: 4 additions & 2 deletions html/enmlformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ QByteArray EnmlFormatter::rebuildNoteEnml() {
// wouldn't be needed, but WebKit doesn't always give back good HTML.
bool useLegacyTidy = false;

if (global.useLibTidy) {
if (global.useLibTidy && !global.bypassTidy) {
TidyBuffer output = {0};
TidyBuffer errout = {0};

Expand Down Expand Up @@ -313,7 +313,7 @@ QByteArray EnmlFormatter::rebuildNoteEnml() {


// IF the new tidy had an error, or we choose to use the old method
if (useLegacyTidy || !global.useLibTidy) {
if ((useLegacyTidy || !global.useLibTidy) && !global.bypassTidy) {
QLOG_DEBUG() << "Calling tidy";
QProcess tidyProcess;
tidyProcess.start("tidy -raw -asxhtml -q -m -u -utf8 ", QIODevice::ReadWrite|QIODevice::Unbuffered);
Expand Down Expand Up @@ -595,6 +595,8 @@ bool EnmlFormatter::isAttributeValid(QString attribute) {


bool EnmlFormatter::isElementValid(QWebElement e) {
if (global.bypassTidy)
return true;
QString element = e.tagName().toLower();
//QLOG_DEBUG() << "Checking tag " << element;
if (element == "a") {
Expand Down

0 comments on commit b7a865b

Please sign in to comment.