mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
Fixed line duplication bug again
This commit is contained in:
parent
1dd0a2acd1
commit
0aa82c852b
@ -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,51 +610,9 @@ static void optimizeHtml(QDomDocument& doc
|
||||
QDomNodeList children = currentElement.childNodes();
|
||||
for (uint index = 0; index < children.length(); ) {
|
||||
QDomNode node = children.item(index);
|
||||
|
||||
// Compress style attribute
|
||||
styleNode = node.attributes().namedItem("style");
|
||||
if (styleNode.isAttr()) {
|
||||
QDomAttr styleAttr = styleNode.toAttr();
|
||||
QString style = styleAttr.value().simplified().trimmed();
|
||||
style.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0px 0px 0px 0px;");
|
||||
style.replace("; ", ";");
|
||||
|
||||
QString className = knownStyle.value(style);
|
||||
if (className.isEmpty()) {
|
||||
// Create a new class
|
||||
className = QString("S%1").arg(knownStyle.count());
|
||||
knownStyle.insert(style, className);
|
||||
|
||||
// Now add this for each attribute values
|
||||
QStringList styles = style.split(';');
|
||||
foreach (QString pair, styles) {
|
||||
pair.replace(" ","");
|
||||
if (!pair.isEmpty()) {
|
||||
QStringList* stylesListItem = stylesList.value(pair);
|
||||
if(!stylesListItem){
|
||||
// If value doesn't exist create it
|
||||
stylesListItem = new QStringList();
|
||||
stylesList.insert(pair, stylesListItem);
|
||||
}
|
||||
//Add the new class to this value
|
||||
stylesListItem->push_back(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
style.clear();
|
||||
|
||||
node.attributes().removeNamedItem("style");
|
||||
styleNode.clear();
|
||||
|
||||
if (!className.isEmpty()) {
|
||||
QDomNode classNode = doc.createAttribute("class");
|
||||
classNode.setNodeValue(className);
|
||||
node.attributes().setNamedItem(classNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isElement()) {
|
||||
QDomElement element = node.toElement();
|
||||
styleNode = node.attributes().namedItem("style");
|
||||
|
||||
// not <p>
|
||||
if (addBR && element.tagName().toLower() != "p") {
|
||||
@ -691,14 +648,11 @@ static void optimizeHtml(QDomDocument& doc
|
||||
|
||||
// <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 (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;")) {
|
||||
|
||||
@ -719,6 +673,46 @@ static void optimizeHtml(QDomDocument& doc
|
||||
}
|
||||
addBR = false;
|
||||
}
|
||||
// Compress style attribute
|
||||
if (styleNode.isAttr()) {
|
||||
QDomAttr styleAttr = styleNode.toAttr();
|
||||
QString style = styleAttr.value().simplified().trimmed();
|
||||
style.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0px 0px 0px 0px;");
|
||||
style.replace("; ", ";");
|
||||
|
||||
QString className = knownStyle.value(style);
|
||||
if (className.isEmpty()) {
|
||||
// Create a new class
|
||||
className = QString("S%1").arg(knownStyle.count());
|
||||
knownStyle.insert(style, className);
|
||||
|
||||
// Now add this for each attribute values
|
||||
QStringList styles = style.split(';');
|
||||
foreach (QString pair, styles) {
|
||||
pair.replace(" ","");
|
||||
if (!pair.isEmpty()) {
|
||||
QStringList* stylesListItem = stylesList.value(pair);
|
||||
if(!stylesListItem){
|
||||
// If value doesn't exist create it
|
||||
stylesListItem = new QStringList();
|
||||
stylesList.insert(pair, stylesListItem);
|
||||
}
|
||||
//Add the new class to this value
|
||||
stylesListItem->push_back(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
style.clear();
|
||||
|
||||
node.attributes().removeNamedItem("style");
|
||||
styleNode.clear();
|
||||
|
||||
if (!className.isEmpty()) {
|
||||
QDomNode classNode = doc.createAttribute("class");
|
||||
classNode.setNodeValue(className);
|
||||
node.attributes().setNamedItem(classNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user