remove HTML cruft to produce a clean description
| 69 | namespace { |
| 70 | /// remove HTML cruft to produce a clean description |
| 71 | QString cleanupDescription(QString thisFragment) |
| 72 | { |
| 73 | { |
| 74 | //Completely remove the first large header found, since we don't need a header |
| 75 | const auto headerRegExp = QStringLiteral("<h\\d[^>]*>.*?</h\\d *>"); |
| 76 | static const auto findHeader = QRegularExpression(headerRegExp); |
| 77 | const auto match = findHeader.match(thisFragment); |
| 78 | if (match.hasMatch()) { |
| 79 | thisFragment.remove(match.capturedStart(), match.capturedLength()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | { |
| 84 | //Replace all gigantic header-font sizes with <big> |
| 85 | { |
| 86 | const auto sizeRegExp = QStringLiteral("<h\\d[^>]*>"); |
| 87 | static const auto findSize = QRegularExpression(sizeRegExp); |
| 88 | thisFragment.replace(findSize, QStringLiteral("<big>")); |
| 89 | } |
| 90 | { |
| 91 | const auto sizeCloseRegExp = QStringLiteral("</h\\d *>"); |
| 92 | static const auto closeSize = QRegularExpression(sizeCloseRegExp); |
| 93 | thisFragment.replace(closeSize, QStringLiteral("</big><br />")); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | { |
| 98 | //Replace paragraphs by newlines |
| 99 | const auto begin = QStringLiteral("<p *>"); |
| 100 | static const auto findBegin = QRegularExpression(begin); |
| 101 | thisFragment.replace(findBegin, {}); |
| 102 | |
| 103 | const auto end = QStringLiteral("</p *>"); |
| 104 | static const auto findEnd = QRegularExpression(end); |
| 105 | thisFragment.replace(findEnd, QStringLiteral("<br />")); |
| 106 | } |
| 107 | |
| 108 | { |
| 109 | //Remove links, because they won't work |
| 110 | const auto link = QStringLiteral("<a[^>]+>"); |
| 111 | static const auto exp = QRegularExpression(link, QRegularExpression::CaseInsensitiveOption); |
| 112 | thisFragment.replace(exp, QStringLiteral("<a>")); |
| 113 | } |
| 114 | |
| 115 | { |
| 116 | //Remove the unhelpful "more..." link |
| 117 | const auto moreLink = QStringLiteral("<a>More...</a *>"); |
| 118 | static const auto exp = QRegularExpression(moreLink, QRegularExpression::CaseInsensitiveOption); |
| 119 | thisFragment.remove(exp); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | //Remove trailing whitespace |
| 124 | const auto trailingSpace = QStringLiteral("(?:<br */?>|\\s+)+$"); |
| 125 | static const auto exp = QRegularExpression(trailingSpace, QRegularExpression::CaseInsensitiveOption); |
| 126 | thisFragment.remove(exp); |
| 127 | } |
| 128 |
no test coverage detected