MCPcopy Create free account
hub / github.com/KDE/kdevelop / cleanupDescription

Function cleanupDescription

plugins/qthelp/qthelpdocumentation.cpp:71–130  ·  view source on GitHub ↗

remove HTML cruft to produce a clean description

Source from the content-addressed store, hash-verified

69namespace {
70/// remove HTML cruft to produce a clean description
71QString 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

Callers 3

Calls 4

hasMatchMethod · 0.80
matchMethod · 0.45
removeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected