|
|
@ -69,9 +69,9 @@ TQString Tools::textToHTML(const TQString &text)
|
|
|
|
if (/*text.isEmpty() ||*/ text == " " || text == " ")
|
|
|
|
if (/*text.isEmpty() ||*/ text == " " || text == " ")
|
|
|
|
return "<p> </p>";
|
|
|
|
return "<p> </p>";
|
|
|
|
|
|
|
|
|
|
|
|
// convertFromPlainText() tqreplace "\n\n" by "</p>\n<p>": we don't want that
|
|
|
|
// convertFromPlainText() replace "\n\n" by "</p>\n<p>": we don't want that
|
|
|
|
TQString htmlString = TQStyleSheet::convertFromPlainText(text, TQStyleSheetItem::WhiteSpaceNormal);
|
|
|
|
TQString htmlString = TQStyleSheet::convertFromPlainText(text, TQStyleSheetItem::WhiteSpaceNormal);
|
|
|
|
return htmlString.tqreplace("</p>\n", "<br>\n<br>\n").tqreplace("\n<p>", "\n"); // Don't replace first and last tags
|
|
|
|
return htmlString.replace("</p>\n", "<br>\n<br>\n").replace("\n<p>", "\n"); // Don't replace first and last tags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TQString Tools::textToHTMLWithoutP(const TQString &text)
|
|
|
|
TQString Tools::textToHTMLWithoutP(const TQString &text)
|
|
|
@ -88,7 +88,7 @@ TQString Tools::htmlToParagraph(const TQString &html)
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the <html> start tag, all the <head> and the <body> start
|
|
|
|
// Remove the <html> start tag, all the <head> and the <body> start
|
|
|
|
// Because <body> can contain style="..." parameter, we transform it to <span>
|
|
|
|
// Because <body> can contain style="..." parameter, we transform it to <span>
|
|
|
|
int pos = result.tqfind("<body");
|
|
|
|
int pos = result.find("<body");
|
|
|
|
if (pos != -1) {
|
|
|
|
if (pos != -1) {
|
|
|
|
result = "<span" + result.mid(pos + 5);
|
|
|
|
result = "<span" + result.mid(pos + 5);
|
|
|
|
startedBySpan = true;
|
|
|
|
startedBySpan = true;
|
|
|
@ -96,14 +96,14 @@ TQString Tools::htmlToParagraph(const TQString &html)
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the ending "</p>\n</body></html>", each tag can be separated by space characters (%s)
|
|
|
|
// Remove the ending "</p>\n</body></html>", each tag can be separated by space characters (%s)
|
|
|
|
// "</p>" can be omitted (eg. if the HTML doesn't contain paragraph but tables), as well as "</body>" (optinal)
|
|
|
|
// "</p>" can be omitted (eg. if the HTML doesn't contain paragraph but tables), as well as "</body>" (optinal)
|
|
|
|
pos = result.tqfind(TQRegExp("(?:(?:</p>[\\s\\n\\r\\t]*)*</body>[\\s\\n\\r\\t]*)*</html>", false)); // Case unsensitive
|
|
|
|
pos = result.find(TQRegExp("(?:(?:</p>[\\s\\n\\r\\t]*)*</body>[\\s\\n\\r\\t]*)*</html>", false)); // Case unsensitive
|
|
|
|
if (pos != -1)
|
|
|
|
if (pos != -1)
|
|
|
|
result = result.left(pos);
|
|
|
|
result = result.left(pos);
|
|
|
|
|
|
|
|
|
|
|
|
if (startedBySpan)
|
|
|
|
if (startedBySpan)
|
|
|
|
result += "</span>";
|
|
|
|
result += "</span>";
|
|
|
|
|
|
|
|
|
|
|
|
return result.tqreplace("</p>", "<br><br>").tqreplace("<p>", "");
|
|
|
|
return result.replace("</p>", "<br><br>").replace("<p>", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The following is adapted from KStringHanlder::tagURLs
|
|
|
|
// The following is adapted from KStringHanlder::tagURLs
|
|
|
@ -125,7 +125,7 @@ TQString Tools::tagURLs(const TQString &text)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TQString anchor = "<a href=\"" + href + "\">" + href + "</a>";
|
|
|
|
TQString anchor = "<a href=\"" + href + "\">" + href + "</a>";
|
|
|
|
richText.tqreplace(urlPos, urlLen, anchor);
|
|
|
|
richText.replace(urlPos, urlLen, anchor);
|
|
|
|
urlPos += anchor.length();
|
|
|
|
urlPos += anchor.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return richText;
|
|
|
|
return richText;
|
|
|
@ -135,24 +135,24 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TQString text = htmlToParagraph(html);
|
|
|
|
TQString text = htmlToParagraph(html);
|
|
|
|
text.remove("\n");
|
|
|
|
text.remove("\n");
|
|
|
|
text.tqreplace("</h1>", "\n");
|
|
|
|
text.replace("</h1>", "\n");
|
|
|
|
text.tqreplace("</h2>", "\n");
|
|
|
|
text.replace("</h2>", "\n");
|
|
|
|
text.tqreplace("</h3>", "\n");
|
|
|
|
text.replace("</h3>", "\n");
|
|
|
|
text.tqreplace("</h4>", "\n");
|
|
|
|
text.replace("</h4>", "\n");
|
|
|
|
text.tqreplace("</h5>", "\n");
|
|
|
|
text.replace("</h5>", "\n");
|
|
|
|
text.tqreplace("</h6>", "\n");
|
|
|
|
text.replace("</h6>", "\n");
|
|
|
|
text.tqreplace("</li>", "\n");
|
|
|
|
text.replace("</li>", "\n");
|
|
|
|
text.tqreplace("</dt>", "\n");
|
|
|
|
text.replace("</dt>", "\n");
|
|
|
|
text.tqreplace("</dd>", "\n");
|
|
|
|
text.replace("</dd>", "\n");
|
|
|
|
text.tqreplace("<dd>", " ");
|
|
|
|
text.replace("<dd>", " ");
|
|
|
|
text.tqreplace("</div>","\n");
|
|
|
|
text.replace("</div>","\n");
|
|
|
|
text.tqreplace("</blockquote>","\n");
|
|
|
|
text.replace("</blockquote>","\n");
|
|
|
|
text.tqreplace("</caption>","\n");
|
|
|
|
text.replace("</caption>","\n");
|
|
|
|
text.tqreplace("</tr>", "\n");
|
|
|
|
text.replace("</tr>", "\n");
|
|
|
|
text.tqreplace("</th>", " ");
|
|
|
|
text.replace("</th>", " ");
|
|
|
|
text.tqreplace("</td>", " ");
|
|
|
|
text.replace("</td>", " ");
|
|
|
|
text.tqreplace("<br>", "\n");
|
|
|
|
text.replace("<br>", "\n");
|
|
|
|
text.tqreplace("<br />","\n");
|
|
|
|
text.replace("<br />","\n");
|
|
|
|
// FIXME: Format <table> tags better, if possible
|
|
|
|
// FIXME: Format <table> tags better, if possible
|
|
|
|
// TODO: Replace é and co. by theire equivalent!
|
|
|
|
// TODO: Replace é and co. by theire equivalent!
|
|
|
|
|
|
|
|
|
|
|
@ -165,7 +165,7 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
TQValueStack<bool> ul; // true if current list is a <ul> one, false if it's an <ol> one
|
|
|
|
TQValueStack<bool> ul; // true if current list is a <ul> one, false if it's an <ol> one
|
|
|
|
TQValueStack<int> lines; // The line number if it is an <ol> list
|
|
|
|
TQValueStack<int> lines; // The line number if it is an <ol> list
|
|
|
|
// We're removing every other tags, or replace them in the case of li:
|
|
|
|
// We're removing every other tags, or replace them in the case of li:
|
|
|
|
while ( (pos = text.tqfind("<"), pos) != -1 ) {
|
|
|
|
while ( (pos = text.find("<"), pos) != -1 ) {
|
|
|
|
// What is the current tag?
|
|
|
|
// What is the current tag?
|
|
|
|
tag = text.mid(pos + 1, 2);
|
|
|
|
tag = text.mid(pos + 1, 2);
|
|
|
|
tag3 = text.mid(pos + 1, 3);
|
|
|
|
tag3 = text.mid(pos + 1, 3);
|
|
|
@ -184,7 +184,7 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
lines.pop();
|
|
|
|
lines.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Where the tag closes?
|
|
|
|
// Where the tag closes?
|
|
|
|
pos2 = text.tqfind(">");
|
|
|
|
pos2 = text.find(">");
|
|
|
|
if (pos2 != -1) {
|
|
|
|
if (pos2 != -1) {
|
|
|
|
// Remove the tag:
|
|
|
|
// Remove the tag:
|
|
|
|
text.remove(pos, pos2 - pos + 1);
|
|
|
|
text.remove(pos, pos2 - pos + 1);
|
|
|
@ -209,11 +209,11 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
++pos;
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
text.tqreplace(">", ">");
|
|
|
|
text.replace(">", ">");
|
|
|
|
text.tqreplace("<", "<");
|
|
|
|
text.replace("<", "<");
|
|
|
|
text.tqreplace(""", "\"");
|
|
|
|
text.replace(""", "\"");
|
|
|
|
text.tqreplace(" ", " ");
|
|
|
|
text.replace(" ", " ");
|
|
|
|
text.tqreplace("&", "&"); // CONVERT IN LAST!!
|
|
|
|
text.replace("&", "&"); // CONVERT IN LAST!!
|
|
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -227,14 +227,14 @@ TQString Tools::cssFontDefinition(const TQFont &font, bool onlyFontFamily)
|
|
|
|
|
|
|
|
|
|
|
|
// Then, try to match the font name with a standard CSS font family:
|
|
|
|
// Then, try to match the font name with a standard CSS font family:
|
|
|
|
TQString genericFont = "";
|
|
|
|
TQString genericFont = "";
|
|
|
|
if (definition.tqcontains("serif", false) || definition.tqcontains("roman", false))
|
|
|
|
if (definition.contains("serif", false) || definition.contains("roman", false))
|
|
|
|
genericFont = "serif";
|
|
|
|
genericFont = "serif";
|
|
|
|
// No "else if" because "sans serif" must be counted as "sans". So, the order between "serif" and "sans" is important
|
|
|
|
// No "else if" because "sans serif" must be counted as "sans". So, the order between "serif" and "sans" is important
|
|
|
|
if (definition.tqcontains("sans", false) || definition.tqcontains("arial", false) || definition.tqcontains("helvetica", false))
|
|
|
|
if (definition.contains("sans", false) || definition.contains("arial", false) || definition.contains("helvetica", false))
|
|
|
|
genericFont = "sans-serif";
|
|
|
|
genericFont = "sans-serif";
|
|
|
|
if (definition.tqcontains("mono", false) || definition.tqcontains("courier", false) ||
|
|
|
|
if (definition.contains("mono", false) || definition.contains("courier", false) ||
|
|
|
|
definition.tqcontains("typewriter", false) || definition.tqcontains("console", false) ||
|
|
|
|
definition.contains("typewriter", false) || definition.contains("console", false) ||
|
|
|
|
definition.tqcontains("terminal", false) || definition.tqcontains("news", false))
|
|
|
|
definition.contains("terminal", false) || definition.contains("news", false))
|
|
|
|
genericFont = "monospace";
|
|
|
|
genericFont = "monospace";
|
|
|
|
|
|
|
|
|
|
|
|
// Eventually add the generic font family to the definition:
|
|
|
|
// Eventually add the generic font family to the definition:
|
|
|
@ -384,7 +384,7 @@ TQString Tools::fileNameForNewFile(const TQString &wantedName, const TQString &d
|
|
|
|
|
|
|
|
|
|
|
|
// Find the file extension, if it exists : Split fileName in fileName and extension
|
|
|
|
// Find the file extension, if it exists : Split fileName in fileName and extension
|
|
|
|
// Example : fileName == "note5-3.txt" => fileName = "note5-3" and extension = ".txt"
|
|
|
|
// Example : fileName == "note5-3.txt" => fileName = "note5-3" and extension = ".txt"
|
|
|
|
int extIndex = fileName.tqfindRev('.');
|
|
|
|
int extIndex = fileName.findRev('.');
|
|
|
|
if (extIndex != -1 && extIndex != int(fileName.length()-1)) { // Extension found and fileName do not ends with '.' !
|
|
|
|
if (extIndex != -1 && extIndex != int(fileName.length()-1)) { // Extension found and fileName do not ends with '.' !
|
|
|
|
extension = fileName.mid(extIndex);
|
|
|
|
extension = fileName.mid(extIndex);
|
|
|
|
fileName.truncate(extIndex);
|
|
|
|
fileName.truncate(extIndex);
|
|
|
@ -392,7 +392,7 @@ TQString Tools::fileNameForNewFile(const TQString &wantedName, const TQString &d
|
|
|
|
|
|
|
|
|
|
|
|
// Find the file number, if it exists : Split fileName in fileName and number
|
|
|
|
// Find the file number, if it exists : Split fileName in fileName and number
|
|
|
|
// Example : fileName == "note5-3" => fileName = "note5" and number = 3
|
|
|
|
// Example : fileName == "note5-3" => fileName = "note5" and number = 3
|
|
|
|
int extNumber = fileName.tqfindRev('-');
|
|
|
|
int extNumber = fileName.findRev('-');
|
|
|
|
if (extNumber != -1 && extNumber != int(fileName.length()-1)) { // Number found and fileName do not ends with '-' !
|
|
|
|
if (extNumber != -1 && extNumber != int(fileName.length()-1)) { // Number found and fileName do not ends with '-' !
|
|
|
|
bool isANumber;
|
|
|
|
bool isANumber;
|
|
|
|
int theNumber = fileName.mid(extNumber + 1).toInt(&isANumber);
|
|
|
|
int theNumber = fileName.mid(extNumber + 1).toInt(&isANumber);
|
|
|
|