forked from qt-creator/qt-creator
C++ tooltip: Changes in formatting extracted html.
This commit is contained in:
@@ -266,6 +266,7 @@ void HtmlDocExtractor::formatContents(QString *html) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_formatContents) {
|
if (m_formatContents) {
|
||||||
|
stripBold(html);
|
||||||
replaceNonStyledHeadingsForBold(html);
|
replaceNonStyledHeadingsForBold(html);
|
||||||
replaceTablesForSimpleLines(html);
|
replaceTablesForSimpleLines(html);
|
||||||
replaceListsForSimpleLines(html);
|
replaceListsForSimpleLines(html);
|
||||||
@@ -274,6 +275,7 @@ void HtmlDocExtractor::formatContents(QString *html) const
|
|||||||
stripDivs(html);
|
stripDivs(html);
|
||||||
stripTagsStyles(html);
|
stripTagsStyles(html);
|
||||||
stripHeadings(html);
|
stripHeadings(html);
|
||||||
|
stripImagens(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_lengthReference > -1 && html->length() > m_lengthReference) {
|
if (m_lengthReference > -1 && html->length() > m_lengthReference) {
|
||||||
@@ -288,9 +290,11 @@ void HtmlDocExtractor::formatContents(QString *html) const
|
|||||||
} else {
|
} else {
|
||||||
html->truncate(m_lengthReference);
|
html->truncate(m_lengthReference);
|
||||||
}
|
}
|
||||||
html->append(QLatin1String("..."));
|
if (m_formatContents) {
|
||||||
if (m_formatContents)
|
if (html->endsWith(QLatin1String("<br />")))
|
||||||
html->append(QLatin1String("<br />"));
|
html->chop(6);
|
||||||
|
html->append(QLatin1String("<p>...</p>"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +331,19 @@ void HtmlDocExtractor::stripTagsStyles(QString *html)
|
|||||||
|
|
||||||
void HtmlDocExtractor::stripTeletypes(QString *html)
|
void HtmlDocExtractor::stripTeletypes(QString *html)
|
||||||
{
|
{
|
||||||
html->remove(createMinimalExp(QLatin1String("<tt>|</tt>")));
|
html->remove(QLatin1String("<tt>"));
|
||||||
|
html->remove(QLatin1String("</tt>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HtmlDocExtractor::stripImagens(QString *html)
|
||||||
|
{
|
||||||
|
html->remove(createMinimalExp(QLatin1String("<img.*>")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HtmlDocExtractor::stripBold(QString *html)
|
||||||
|
{
|
||||||
|
html->remove(QLatin1String("<b>"));
|
||||||
|
html->remove(QLatin1String("</b>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HtmlDocExtractor::replaceNonStyledHeadingsForBold(QString *html)
|
void HtmlDocExtractor::replaceNonStyledHeadingsForBold(QString *html)
|
||||||
@@ -340,13 +356,19 @@ void HtmlDocExtractor::replaceNonStyledHeadingsForBold(QString *html)
|
|||||||
|
|
||||||
void HtmlDocExtractor::replaceTablesForSimpleLines(QString *html)
|
void HtmlDocExtractor::replaceTablesForSimpleLines(QString *html)
|
||||||
{
|
{
|
||||||
html->remove(createMinimalExp(QLatin1String("<table.*>")));
|
html->replace(createMinimalExp(QLatin1String("(?:<p>)?<table.*>")), QLatin1String("<p>"));
|
||||||
html->remove(QLatin1String("</table>"));
|
html->replace(QLatin1String("</table>"), QLatin1String("</p>"));
|
||||||
|
html->remove(createMinimalExp(QLatin1String("<thead.*>")));
|
||||||
|
html->remove(QLatin1String("</thead>"));
|
||||||
|
html->remove(createMinimalExp(QLatin1String("<tfoot.*>")));
|
||||||
|
html->remove(QLatin1String("</tfoot>"));
|
||||||
html->remove(createMinimalExp(QLatin1String("<tr.*><th.*>.*</th></tr>")));
|
html->remove(createMinimalExp(QLatin1String("<tr.*><th.*>.*</th></tr>")));
|
||||||
html->replace(QLatin1String("</td><td"), QLatin1String("</td> <td"));
|
html->replace(QLatin1String("</td><td"), QLatin1String("</td> <td"));
|
||||||
|
html->remove(createMinimalExp(QLatin1String("<td.*><p>")));
|
||||||
html->remove(createMinimalExp(QLatin1String("<td.*>")));
|
html->remove(createMinimalExp(QLatin1String("<td.*>")));
|
||||||
html->remove(QLatin1String("</td>"));
|
html->remove(createMinimalExp(QLatin1String("(?:</p>)?</td>")));
|
||||||
html->replace(QLatin1String("<tr>"), QLatin1String(" - "));
|
html->replace(createMinimalExp(QLatin1String("<tr.*>")),
|
||||||
|
QLatin1String(" "));
|
||||||
html->replace(QLatin1String("</tr>"), QLatin1String("<br />"));
|
html->replace(QLatin1String("</tr>"), QLatin1String("<br />"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +376,7 @@ void HtmlDocExtractor::replaceListsForSimpleLines(QString *html)
|
|||||||
{
|
{
|
||||||
html->remove(createMinimalExp(QLatin1String("<(?:ul|ol).*>")));
|
html->remove(createMinimalExp(QLatin1String("<(?:ul|ol).*>")));
|
||||||
html->remove(createMinimalExp(QLatin1String("</(?:ul|ol)>")));
|
html->remove(createMinimalExp(QLatin1String("</(?:ul|ol)>")));
|
||||||
html->replace(QLatin1String("<li>"), QLatin1String(" - "));
|
html->replace(QLatin1String("<li>"), QLatin1String(" "));
|
||||||
html->replace(QLatin1String("</li>"), QLatin1String("<br />"));
|
html->replace(QLatin1String("</li>"), QLatin1String("<br />"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ private:
|
|||||||
static void stripDivs(QString *html);
|
static void stripDivs(QString *html);
|
||||||
static void stripTagsStyles(QString *html);
|
static void stripTagsStyles(QString *html);
|
||||||
static void stripTeletypes(QString *html);
|
static void stripTeletypes(QString *html);
|
||||||
|
static void stripImagens(QString *html);
|
||||||
|
static void stripBold(QString *html);
|
||||||
static void replaceNonStyledHeadingsForBold(QString *html);
|
static void replaceNonStyledHeadingsForBold(QString *html);
|
||||||
static void replaceTablesForSimpleLines(QString *html);
|
static void replaceTablesForSimpleLines(QString *html);
|
||||||
static void replaceListsForSimpleLines(QString *html);
|
static void replaceListsForSimpleLines(QString *html);
|
||||||
|
|||||||
@@ -70,20 +70,15 @@ namespace {
|
|||||||
return name.right(name.length() - index - 1);
|
return name.right(name.length() - index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveCursorToEndOfQualifiedName(QTextCursor *tc) {
|
void moveCursorToEndOfName(QTextCursor *tc) {
|
||||||
QTextDocument *doc = tc->document();
|
QTextDocument *doc = tc->document();
|
||||||
if (!doc)
|
if (!doc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (true) {
|
QChar ch = doc->characterAt(tc->position());
|
||||||
const QChar &ch = doc->characterAt(tc->position());
|
while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
|
||||||
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
tc->movePosition(QTextCursor::NextCharacter);
|
||||||
tc->movePosition(QTextCursor::NextCharacter);
|
ch = doc->characterAt(tc->position());
|
||||||
else if (ch == QLatin1Char(':') &&
|
|
||||||
doc->characterAt(tc->position() + 1) == QLatin1Char(':'))
|
|
||||||
tc->movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 2);
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +206,7 @@ void CppHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
|||||||
|
|
||||||
QTextCursor tc(baseEditor->document());
|
QTextCursor tc(baseEditor->document());
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
moveCursorToEndOfQualifiedName(&tc);
|
moveCursorToEndOfName(&tc);
|
||||||
|
|
||||||
// Fetch the expression's code
|
// Fetch the expression's code
|
||||||
ExpressionUnderCursor expressionUnderCursor;
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
|
|||||||
Reference in New Issue
Block a user