|
|
|
@ -69,9 +69,9 @@ TQString Tools::textToHTML(const TQString &text)
|
|
|
|
|
if (/*text.isEmpty() ||*/ text == " " || text == " ")
|
|
|
|
|
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);
|
|
|
|
|
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)
|
|
|
|
@ -88,7 +88,7 @@ TQString Tools::htmlToParagraph(const TQString &html)
|
|
|
|
|
|
|
|
|
|
// Remove the <html> start tag, all the <head> and the <body> start
|
|
|
|
|
// Because <body> can contain style="..." parameter, we transform it to <span>
|
|
|
|
|
int pos = result.tqfind("<body");
|
|
|
|
|
int pos = result.find("<body");
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
result = "<span" + result.mid(pos + 5);
|
|
|
|
|
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)
|
|
|
|
|
// "</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)
|
|
|
|
|
result = result.left(pos);
|
|
|
|
|
|
|
|
|
|
if (startedBySpan)
|
|
|
|
|
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
|
|
|
|
@ -125,7 +125,7 @@ TQString Tools::tagURLs(const TQString &text)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TQString anchor = "<a href=\"" + href + "\">" + href + "</a>";
|
|
|
|
|
richText.tqreplace(urlPos, urlLen, anchor);
|
|
|
|
|
richText.replace(urlPos, urlLen, anchor);
|
|
|
|
|
urlPos += anchor.length();
|
|
|
|
|
}
|
|
|
|
|
return richText;
|
|
|
|
@ -135,24 +135,24 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
|
{
|
|
|
|
|
TQString text = htmlToParagraph(html);
|
|
|
|
|
text.remove("\n");
|
|
|
|
|
text.tqreplace("</h1>", "\n");
|
|
|
|
|
text.tqreplace("</h2>", "\n");
|
|
|
|
|
text.tqreplace("</h3>", "\n");
|
|
|
|
|
text.tqreplace("</h4>", "\n");
|
|
|
|
|
text.tqreplace("</h5>", "\n");
|
|
|
|
|
text.tqreplace("</h6>", "\n");
|
|
|
|
|
text.tqreplace("</li>", "\n");
|
|
|
|
|
text.tqreplace("</dt>", "\n");
|
|
|
|
|
text.tqreplace("</dd>", "\n");
|
|
|
|
|
text.tqreplace("<dd>", " ");
|
|
|
|
|
text.tqreplace("</div>","\n");
|
|
|
|
|
text.tqreplace("</blockquote>","\n");
|
|
|
|
|
text.tqreplace("</caption>","\n");
|
|
|
|
|
text.tqreplace("</tr>", "\n");
|
|
|
|
|
text.tqreplace("</th>", " ");
|
|
|
|
|
text.tqreplace("</td>", " ");
|
|
|
|
|
text.tqreplace("<br>", "\n");
|
|
|
|
|
text.tqreplace("<br />","\n");
|
|
|
|
|
text.replace("</h1>", "\n");
|
|
|
|
|
text.replace("</h2>", "\n");
|
|
|
|
|
text.replace("</h3>", "\n");
|
|
|
|
|
text.replace("</h4>", "\n");
|
|
|
|
|
text.replace("</h5>", "\n");
|
|
|
|
|
text.replace("</h6>", "\n");
|
|
|
|
|
text.replace("</li>", "\n");
|
|
|
|
|
text.replace("</dt>", "\n");
|
|
|
|
|
text.replace("</dd>", "\n");
|
|
|
|
|
text.replace("<dd>", " ");
|
|
|
|
|
text.replace("</div>","\n");
|
|
|
|
|
text.replace("</blockquote>","\n");
|
|
|
|
|
text.replace("</caption>","\n");
|
|
|
|
|
text.replace("</tr>", "\n");
|
|
|
|
|
text.replace("</th>", " ");
|
|
|
|
|
text.replace("</td>", " ");
|
|
|
|
|
text.replace("<br>", "\n");
|
|
|
|
|
text.replace("<br />","\n");
|
|
|
|
|
// FIXME: Format <table> tags better, if possible
|
|
|
|
|
// 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<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:
|
|
|
|
|
while ( (pos = text.tqfind("<"), pos) != -1 ) {
|
|
|
|
|
while ( (pos = text.find("<"), pos) != -1 ) {
|
|
|
|
|
// What is the current tag?
|
|
|
|
|
tag = text.mid(pos + 1, 2);
|
|
|
|
|
tag3 = text.mid(pos + 1, 3);
|
|
|
|
@ -184,7 +184,7 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
|
lines.pop();
|
|
|
|
|
}
|
|
|
|
|
// Where the tag closes?
|
|
|
|
|
pos2 = text.tqfind(">");
|
|
|
|
|
pos2 = text.find(">");
|
|
|
|
|
if (pos2 != -1) {
|
|
|
|
|
// Remove the tag:
|
|
|
|
|
text.remove(pos, pos2 - pos + 1);
|
|
|
|
@ -209,11 +209,11 @@ TQString Tools::htmlToText(const TQString &html)
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text.tqreplace(">", ">");
|
|
|
|
|
text.tqreplace("<", "<");
|
|
|
|
|
text.tqreplace(""", "\"");
|
|
|
|
|
text.tqreplace(" ", " ");
|
|
|
|
|
text.tqreplace("&", "&"); // CONVERT IN LAST!!
|
|
|
|
|
text.replace(">", ">");
|
|
|
|
|
text.replace("<", "<");
|
|
|
|
|
text.replace(""", "\"");
|
|
|
|
|
text.replace(" ", " ");
|
|
|
|
|
text.replace("&", "&"); // CONVERT IN LAST!!
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
TQString genericFont = "";
|
|
|
|
|
if (definition.tqcontains("serif", false) || definition.tqcontains("roman", false))
|
|
|
|
|
if (definition.contains("serif", false) || definition.contains("roman", false))
|
|
|
|
|
genericFont = "serif";
|
|
|
|
|
// 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";
|
|
|
|
|
if (definition.tqcontains("mono", false) || definition.tqcontains("courier", false) ||
|
|
|
|
|
definition.tqcontains("typewriter", false) || definition.tqcontains("console", false) ||
|
|
|
|
|
definition.tqcontains("terminal", false) || definition.tqcontains("news", false))
|
|
|
|
|
if (definition.contains("mono", false) || definition.contains("courier", false) ||
|
|
|
|
|
definition.contains("typewriter", false) || definition.contains("console", false) ||
|
|
|
|
|
definition.contains("terminal", false) || definition.contains("news", false))
|
|
|
|
|
genericFont = "monospace";
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// 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 '.' !
|
|
|
|
|
extension = fileName.mid(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
|
|
|
|
|
// 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 '-' !
|
|
|
|
|
bool isANumber;
|
|
|
|
|
int theNumber = fileName.mid(extNumber + 1).toInt(&isANumber);
|
|
|
|
|