mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-23 14:41:04 -04:00
Fixed line duplication bug again
This commit is contained in:
parent
1dd0a2acd1
commit
0aa82c852b
1 changed files with 45 additions and 51 deletions
|
@ -569,7 +569,6 @@ static void optimizeHtml(QDomDocument& doc
|
|||
, QHash<QString, QStringList*> &stylesList
|
||||
, QHash<QString, QString> &knownStyle)
|
||||
{
|
||||
bool bFirstP=true;
|
||||
if (doc.documentElement().namedItem("style").toElement().attributeNode("RSOptimized").isAttr()) {
|
||||
//Already optimized only get StyleList
|
||||
QDomElement styleElem = doc.documentElement().namedItem("style").toElement();
|
||||
|
@ -611,9 +610,70 @@ static void optimizeHtml(QDomDocument& doc
|
|||
QDomNodeList children = currentElement.childNodes();
|
||||
for (uint index = 0; index < children.length(); ) {
|
||||
QDomNode node = children.item(index);
|
||||
|
||||
// Compress style attribute
|
||||
if (node.isElement()) {
|
||||
QDomElement element = node.toElement();
|
||||
styleNode = node.attributes().namedItem("style");
|
||||
|
||||
// not <p>
|
||||
if (addBR && element.tagName().toLower() != "p") {
|
||||
// add <br> after a removed <p> but not before a <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
addBR = false;
|
||||
++index;
|
||||
}
|
||||
|
||||
// <body>
|
||||
if (element.tagName().toLower() == "body") {
|
||||
if (element.attributes().length() == 0) {
|
||||
// remove <body> without attributes
|
||||
removeElement(currentElement, element);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
// change <body> to <span>
|
||||
element.setTagName("span");
|
||||
}
|
||||
|
||||
// <head>
|
||||
if (element.tagName().toLower() == "head") {
|
||||
// remove <head>
|
||||
currentElement.removeChild(node);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// iterate children
|
||||
optimizeHtml(doc, element, stylesList, knownStyle);
|
||||
|
||||
// <p>
|
||||
if (element.tagName().toLower() == "p") {
|
||||
// <p style="...">
|
||||
if (styleNode.isAttr()) {
|
||||
QString style = styleNode.toAttr().value().simplified().trimmed();
|
||||
style.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0px 0px 0px 0px;");
|
||||
style.replace("; ", ";");
|
||||
if (style == "margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;"
|
||||
|| style.startsWith("-qt-paragraph-type:empty;margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;")) {
|
||||
|
||||
if (addBR) {
|
||||
// add <br> after a removed <p> but not before a removed <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
++index;
|
||||
}
|
||||
// remove Qt standard <p> or empty <p>
|
||||
index += element.childNodes().length();
|
||||
removeElement(currentElement, element);
|
||||
// do not add extra <br> after empty paragraph, the paragraph already contains one
|
||||
addBR = ! style.startsWith("-qt-paragraph-type:empty");
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
addBR = false;
|
||||
}
|
||||
// Compress style attribute
|
||||
if (styleNode.isAttr()) {
|
||||
QDomAttr styleAttr = styleNode.toAttr();
|
||||
QString style = styleAttr.value().simplified().trimmed();
|
||||
|
@ -653,72 +713,6 @@ static void optimizeHtml(QDomDocument& doc
|
|||
node.attributes().setNamedItem(classNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isElement()) {
|
||||
QDomElement element = node.toElement();
|
||||
|
||||
// not <p>
|
||||
if (addBR && element.tagName().toLower() != "p") {
|
||||
// add <br> after a removed <p> but not before a <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
addBR = false;
|
||||
++index;
|
||||
}
|
||||
|
||||
// <body>
|
||||
if (element.tagName().toLower() == "body") {
|
||||
if (element.attributes().length() == 0) {
|
||||
// remove <body> without attributes
|
||||
removeElement(currentElement, element);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
// change <body> to <span>
|
||||
element.setTagName("span");
|
||||
}
|
||||
|
||||
// <head>
|
||||
if (element.tagName().toLower() == "head") {
|
||||
// remove <head>
|
||||
currentElement.removeChild(node);
|
||||
// no ++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// iterate children
|
||||
optimizeHtml(doc, element, stylesList, knownStyle);
|
||||
|
||||
// <p>
|
||||
if (element.tagName().toLower() == "p") {
|
||||
//If it's the first <p>, replace it as <span> otherwise make "\n" before first line
|
||||
if (bFirstP) {
|
||||
element.setTagName("span");
|
||||
bFirstP = false;
|
||||
}
|
||||
// <p style="...">
|
||||
if (element.attributes().size() == 1 && styleNode.isAttr()) {
|
||||
QString style = styleNode.toAttr().value().simplified();
|
||||
if (style == "margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;"
|
||||
|| style.startsWith("-qt-paragraph-type:empty;margin:0px 0px 0px 0px;-qt-block-indent:0;text-indent:0px;")) {
|
||||
|
||||
if (addBR) {
|
||||
// add <br> after a removed <p> but not before a removed <p>
|
||||
QDomElement elementBr = doc.createElement("br");
|
||||
currentElement.insertBefore(elementBr, element);
|
||||
++index;
|
||||
}
|
||||
// remove Qt standard <p> or empty <p>
|
||||
index += element.childNodes().length();
|
||||
removeElement(currentElement, element);
|
||||
// do not add extra <br> after empty paragraph, the paragraph already contains one
|
||||
addBR = ! style.startsWith("-qt-paragraph-type:empty");
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
addBR = false;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue