Ich habe so ein xhtml editor gemacht mit tabellen bilder href link ecc..
kannst ja mal anschauen ...
http://svn.sourceforge.net/viewvc/qtexc ... ditor_cms/
Am ende putze ich alles raus .. so dass ich es mit separatem css formattieren kann.... und libtidy macht den rest....
Code: Alles auswählen
/* remove all style qt html style and bring to xhtml on tidy */
QString CleanTagQt4( QString body , QString class_name )
{
/*qDebug() << "### start clean tag ";*/
QString finale, finale4;
QString newbody = body;
newbody.replace(QRegExp("<div[^>]*>([^<]*)</div>",Qt::CaseInsensitive), "\\1 <!-- QRegExp -->");
newbody.replace("-qt-paragraph-type","devnull-type");
newbody.replace("margin-top","devnull-top");
newbody.replace("margin-bottom","devnull-bottom");
newbody.replace("margin-left","devnull-left");
newbody.replace("margin-right","devnull-right");
newbody.replace("text-indent","devnull-indent");
newbody.replace("font-size","devnull-size");
newbody.replace("#target=_blank\"","\" target=\"_blank\"");
newbody.replace("#target=_top\"","\" target=\"_top\"");
newbody.replace("#target=_self\"","\" target=\"_self\"");
newbody.replace("#target=_main\"","\" target=\"_main\"");
newbody.replace("#target=_menu\"","\" target=\"_menu\"");
newbody.replace("\n"," ");
QString wbody = newbody.trimmed();
QDateTime dt = QDateTime::currentDateTime();
QDate timecute;
QString day_en = timecute.shortDayName(timecute.day());
QString month_en = timecute.shortMonthName (timecute.month());
QString last = dt.toString("yyyy hh:mm:ss");
QString tname = QString( "%1, %2 %3 %4 +0200" ).arg( day_en , QString::number(timecute.day()), month_en , last );
finale = TidyCleanhtml(QString("<div class=\"####CLASSNAME####\" title=\"Programm powered by PPK-Webprogramm www.ciz.ch document from %2 \">%1</div>").arg(wbody).arg(tname));
finale.replace("\n"," ");
finale.replace("####CLASSNAME####",class_name);
finale4 = finale.trimmed();
return finale4;
}
Und wenn ich nur den reinen text brauche ... um zum beispiel sql suche zu machen ... dann nehme ich mir nur den text ....
Der "div" tag geht bei einem nochmaligen editieren verloren bei qtextedit
ist auch gut .... ich denke diese loesung ist besser als die 3/4 html regeln von qt4 zu umscreiben ... ... QT html is nur ideal um pdf zu machen....
Code: Alles auswählen
/* remove all html tag and return as text */
QString InternalTagClean( QString body )
{
body.replace(" "," ");
body.replace(QRegExp("<script(.)[^>]",Qt::CaseInsensitive), "�###cdatastart###� script-tag-attribute ");
body.replace(QRegExp("<style(.)[^>]",Qt::CaseInsensitive), "�###cdatastart###� style-tag-attribute ");
body.replace("//<![CDATA[","�###cdatastart###� cdata ");
body.replace("//]]>","�###cdataend###�");
body.replace("<!--","�###cdatastart###� comment ");
body.replace("<noscript>","�###cdatastart###� nosript-tag ");
body.replace("</noscript>","�###cdataend###�");
body.replace("<NOSCRIPT>","�###cdatastart###� nosript-tag");
body.replace("</NOSCRIPT>","�###cdataend###�");
body.replace("<SCRIPT>","�###cdatastart###� script-tag");
body.replace("</SCRIPT>","�###cdataend###�");
body.replace("<script>","�###cdatastart###� script-tag");
body.replace("</script>","�###cdataend###�");
body.replace("<style>","�###cdatastart###� style-tag");
body.replace("</style>","�###cdataend###�");
body.replace("<STYLE>","�###cdatastart###� style-tag");
body.replace("</STYLE>","�###cdataend###�");
body.replace("-->","�###cdataend###�");
body.replace("<!---","�###cdatastart###� comment ");
body.replace("--->","�###cdataend###�");
/* body.replace(QRegExp("<p[^>]*>([^<]*)</p>",Qt::CaseInsensitive), "\\1");*/
body.replace("<br>","##break##");
body.replace("</br>","##break##");
body.replace("</p>","##break##");
body.replace("</td>","##break##");
body.remove(QRegExp("<head>(.*)</head>",Qt::CaseInsensitive));
body.remove(QRegExp("�###cdatastart###�(.)[^�]*�###cdataend###�",Qt::CaseInsensitive));
body.remove(QRegExp("<script(.)[^>]*</script>",Qt::CaseInsensitive));
body.remove(QRegExp("�###cdatastart###�(.)[^�]*�###cdataend###�",Qt::CaseInsensitive));
body.remove(QRegExp("<form(.)[^>]*</form>",Qt::CaseInsensitive));
body.remove(QRegExp("<FORM(.)[^>]*</FORM>",Qt::CaseInsensitive));
body.remove(QRegExp("<script(.)[^>]*</script>",Qt::CaseInsensitive));
body.remove(QRegExp("<SCRIPT(.)[^>]*</SCRIPT>",Qt::CaseInsensitive));
body.remove(QRegExp("<style(.)[^>]*</style>",Qt::CaseInsensitive));
body.remove(QRegExp("<STYLE(.)[^>]*</STYLE>",Qt::CaseInsensitive));
body.remove(QRegExp("<(.)[^>]*>"));
return body;
}
erwischt fast alle html xhtml tag