feat(StringUtils): implement `plainText(htmlFragment)`
- converts an HTML fragment to plain text - move the impl to C++ so that it can be used directly from QML too
This commit is contained in:
parent
9662c974a0
commit
5d9c5d46fd
|
@ -19,6 +19,8 @@ public:
|
|||
|
||||
Q_INVOKABLE QString extractDomainFromLink(const QString& link) const;
|
||||
|
||||
Q_INVOKABLE QString plainText(const QString& htmlFragment) const;
|
||||
|
||||
private:
|
||||
QQmlEngine* m_engine{nullptr};
|
||||
};
|
||||
|
|
|
@ -16,4 +16,8 @@ QtObject {
|
|||
function extractDomainFromLink(link) {
|
||||
return Internal.StringUtils.extractDomainFromLink(link)
|
||||
}
|
||||
|
||||
function plainText(htmlFragment) {
|
||||
return Internal.StringUtils.plainText(htmlFragment)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QQmlEngine>
|
||||
#include <QQmlFileSelector>
|
||||
#include <QUrl>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
StringUtilsInternal::StringUtilsInternal(QQmlEngine* engine, QObject* parent)
|
||||
: m_engine(engine)
|
||||
|
@ -73,3 +74,8 @@ QString StringUtilsInternal::extractDomainFromLink(const QString& link) const
|
|||
}
|
||||
return url.host();
|
||||
}
|
||||
|
||||
QString StringUtilsInternal::plainText(const QString &htmlFragment) const
|
||||
{
|
||||
return QTextDocumentFragment::fromHtml(htmlFragment).toPlainText();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue