bool HTMLFilter::filter(const QString &in, QString &out) { if (! in.contains(QLatin1Char('<'))) { out = in.simplified(); } else { QXmlStreamReader qxsr(QString::fromLatin1("<document>%1</document>").arg(in)); QString qs; while (! qxsr.atEnd()) { switch (qxsr.readNext()) { case QXmlStreamReader::Invalid: return false; case QXmlStreamReader::Characters: qs += qxsr.text(); break; case QXmlStreamReader::EndElement: if ((qxsr.name() == QLatin1String("br")) || (qxsr.name() == QLatin1String("p"))) qs += QLatin1Char('\n'); break; default: break; } } out = escapeTags(qs.simplified()); } return true; }
void RichTextEditor::on_qteRichText_textChanged() { bModified = true; bChanged = true; updateActions(); if (! g.uiMessageLength) return; richToPlain(); const QString &text = qptePlainText->toPlainText(); bool over = true; unsigned int imagelength = text.length(); if (g.uiMessageLength && imagelength <= g.uiMessageLength) { over = false; } else if (g.uiImageLength && imagelength > g.uiImageLength) { over = true; } else { QString qsOut; QXmlStreamReader qxsr(QString::fromLatin1("<document>%1</document>").arg(text)); QXmlStreamWriter qxsw(&qsOut); while (! qxsr.atEnd()) { switch (qxsr.readNext()) { case QXmlStreamReader::Invalid: return; case QXmlStreamReader::StartElement: { if (qxsr.name() == QLatin1String("img")) { QXmlStreamAttributes attr = qxsr.attributes(); qxsw.writeStartElement(qxsr.namespaceUri().toString(), qxsr.name().toString()); foreach(const QXmlStreamAttribute &a, qxsr.attributes()) if (a.name() != QLatin1String("src")) qxsw.writeAttribute(a); } else { qxsw.writeCurrentToken(qxsr); } } break; default: qxsw.writeCurrentToken(qxsr); break; } }