diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-11-17 09:56:15 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-12-12 16:17:22 +0000 |
commit | 796a5e005fa1ae2bfe6f9278fc482723eb89f429 (patch) | |
tree | a4ff3c271db57f6804505828a7fe1ac00bb2995d | |
parent | a28de1b8b1848df489298b34b8330bf41a70ce40 (diff) | |
download | qttools-796a5e005fa1ae2bfe6f9278fc482723eb89f429.tar.gz |
Assistant: Fix search results for content in .txt files
The search index writer would treat all input files as html. This led
to .txt files being stored with empty titles (no <title> tag would be
found). That again led to unusable search results in Assistant,
showing only the snippet, but no clickable title link.
Fix by special casing for .txt files, using the file name as title,
just as QHelpGenerator does.
Task-number: QTBUG-62250
Change-Id: Id82a780dadc2d4ff5866a565337f86c798b952a5
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
-rw-r--r-- | src/assistant/help/qhelpsearchindexwriter_default.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/assistant/help/qhelpsearchindexwriter_default.cpp b/src/assistant/help/qhelpsearchindexwriter_default.cpp index 2dbbb30d2..72e92ecab 100644 --- a/src/assistant/help/qhelpsearchindexwriter_default.cpp +++ b/src/assistant/help/qhelpsearchindexwriter_default.cpp @@ -501,11 +501,18 @@ void QHelpSearchIndexWriter::run() if (text.isEmpty()) continue; - QTextDocument doc; - doc.setHtml(text); - - const QString &title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped(); - const QString &contents = doc.toPlainText().toHtmlEscaped(); + QString title; + QString contents; + if (url.endsWith(QLatin1String(".txt"))) { + title = url.mid(url.lastIndexOf(QLatin1Char('/')) + 1); + contents = text.toHtmlEscaped(); + } else { + QTextDocument doc; + doc.setHtml(text); + + title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped(); + contents = doc.toPlainText().toHtmlEscaped(); + } writer.insertDoc(namespaceName, attributesString, url, title, contents); } |