summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@nokia.com>2010-09-20 12:40:42 (GMT)
committerMartin Smith <martin.smith@nokia.com>2010-09-20 12:40:42 (GMT)
commit839938e86dd22601b679c5f33606830850d6df81 (patch)
treeed7aa904f7b2a7ec6fc1e46ff8021413010f05d4
parented73f806928760ace1d4c7c2a6327875725bcb05 (diff)
downloadQt-839938e86dd22601b679c5f33606830850d6df81.zip
Qt-839938e86dd22601b679c5f33606830850d6df81.tar.gz
Qt-839938e86dd22601b679c5f33606830850d6df81.tar.bz2
qdoc: DITA XML generator now avoids escaping <xref> elements.
Still escapes <i> and <tt>, for example.
-rw-r--r--tools/qdoc3/ditaxmlgenerator.cpp191
-rw-r--r--tools/qdoc3/ditaxmlgenerator.h1
2 files changed, 84 insertions, 108 deletions
diff --git a/tools/qdoc3/ditaxmlgenerator.cpp b/tools/qdoc3/ditaxmlgenerator.cpp
index 9c70cb5..0170644 100644
--- a/tools/qdoc3/ditaxmlgenerator.cpp
+++ b/tools/qdoc3/ditaxmlgenerator.cpp
@@ -358,19 +358,21 @@ QString DitaXmlGenerator::sinceTitles[] =
static bool showBrokenLinks = false;
-static void addLink(const QString &linkTarget,
- const QStringRef &nestedStuff,
- QString *res)
+/*!
+ Appends an <xref> element to the current XML stream
+ with the \a href attribute and the \a text.
+ */
+void DitaXmlGenerator::addLink(const QString& href,
+ const QStringRef& text)
{
- if (!linkTarget.isEmpty()) {
- *res += "<xref href=\"";
- *res += linkTarget;
- *res += "\">";
- *res += nestedStuff;
- *res += "</xref>";
+ if (!href.isEmpty()) {
+ xmlWriter().writeStartElement("xref");
+ xmlWriter().writeAttribute("href", href);
+ xmlWriter().writeCharacters(text.toString());
+ xmlWriter().writeEndElement(); // </xref>
}
else {
- *res += nestedStuff;
+ xmlWriter().writeCharacters(text.toString());
}
}
@@ -2240,14 +2242,14 @@ QString DitaXmlGenerator::generateLowStatusMemberFile(const InnerNode* inner,
xmlWriter().writeAttribute("href","qt3support.html");
xmlWriter().writeCharacters("Qt 3 support layer");
xmlWriter().writeEndElement(); // </xref>
- xmlWriter().writeCharacters(".");
+ xmlWriter().writeCharacters(". ");
xmlWriter().writeEndElement(); // </b>
- xmlWriter().writeCharacters(" They are provided to help you port old code to Qt 4. "
+ xmlWriter().writeCharacters("They are provided to help you port old code to Qt 4. "
"We advise against using them in new code.");
}
else {
xmlWriter().writeStartElement("b");
- xmlWriter().writeCharacters("The following class members are obsolete.");
+ xmlWriter().writeCharacters("The following class members are obsolete. ");
xmlWriter().writeEndElement(); // </b>
xmlWriter().writeCharacters("They are provided to keep old source code working. "
"We strongly advise against using them in new code.");
@@ -3050,101 +3052,20 @@ void DitaXmlGenerator::writeText(const QString& markedCode,
const QChar charLangle = '<';
const QChar charAt = '@';
- // replace all <@link> tags: "(<@link node=\"([^\"]+)\">).*(</@link>)"
- static const QString linkTag("link");
- bool done = false;
- for (int i = 0, n = src.size(); i < n;) {
- if (src.at(i) == charLangle && src.at(i + 1).unicode() == '@') {
- if (nameAlignment && !done) {// && (i != 0)) Why was this here?
- if (!html.isEmpty()) {
- xmlWriter().writeCharacters(html);
- html.clear();
- }
- xmlWriter().writeEndElement(); // </<entry>
- xmlWriter().writeStartElement("entry");
- xmlWriter().writeAttribute("outputclass=","memItemRight bottomAlign");
- done = true;
- }
- i += 2;
- if (parseArg(src, linkTag, &i, n, &arg, &par1)) {
- html += "<b>";
- QString link = linkForNode(
- CodeMarker::nodeForString(par1.toString()), relative);
- addLink(link, arg, &html);
- html += "</b>";
- }
- else {
- html += charLangle;
- html += charAt;
- }
- }
- else {
- html += src.at(i++);
- }
- }
-
- // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)(</@\\2>)" tags
- src = html;
- html = QString();
- static const QString typeTags[] = { "type", "headerfile", "func" };
- for (int i = 0, n = src.size(); i < n;) {
- if (src.at(i) == charLangle && src.at(i + 1) == charAt) {
- i += 2;
- bool handled = false;
- for (int k = 0; k != 3; ++k) {
- if (parseArg(src, typeTags[k], &i, n, &arg, &par1)) {
- par1 = QStringRef();
- QString link = linkForNode(
- marker->resolveTarget(arg.toString(), myTree, relative),
- relative);
- addLink(link, arg, &html);
- handled = true;
- break;
- }
- }
- if (!handled) {
- html += charLangle;
- html += charAt;
- }
- }
- else {
- html += src.at(i++);
- }
- }
-
- // replace all
- // "<@comment>" -> "<span class=\"comment\">";
- // "<@preprocessor>" -> "<span class=\"preprocessor\">";
- // "<@string>" -> "<span class=\"string\">";
- // "<@char>" -> "<span class=\"char\">";
- // "</@(?:comment|preprocessor|string|char)>" -> "</span>"
- src = html;
- html = QString();
+ /*
+ First strip out all the extraneous markup. The table
+ below contains the markup we want to keep. Everything
+ else that begins with "<@" or "</@" is stripped out.
+ */
static const QString spanTags[] = {
- "<@comment>", "<span class=\"comment\">",
- "<@preprocessor>", "<span class=\"preprocessor\">",
- "<@string>", "<span class=\"string\">",
- "<@char>", "<span class=\"char\">",
- "</@comment>", "</span>",
- "</@preprocessor>","</span>",
- "</@string>", "</span>",
- "</@char>", "</span>"
- // "<@char>", "<font color=blue>",
- // "</@char>", "</font>",
- // "<@func>", "<font color=green>",
- // "</@func>", "</font>",
- // "<@id>", "<i>",
- // "</@id>", "</i>",
- // "<@keyword>", "<b>",
- // "</@keyword>", "</b>",
- // "<@number>", "<font color=yellow>",
- // "</@number>", "</font>",
- // "<@op>", "<b>",
- // "</@op>", "</b>",
- // "<@param>", "<i>",
- // "</@param>", "</i>",
- // "<@string>", "<font color=green>",
- // "</@string>", "</font>",
+ "<@link ", "<@link ",
+ "<@type>", "<@type>",
+ "<@headerfile>", "<@headerfile>",
+ "<@func>", "<@func>",
+ "</@link>", "</@link>",
+ "</@type>", "</@type>",
+ "</@headerfile>", "</@headerfile>",
+ "</@func>", "</@func>"
};
for (int i = 0, n = src.size(); i < n;) {
if (src.at(i) == charLangle) {
@@ -3178,8 +3099,62 @@ void DitaXmlGenerator::writeText(const QString& markedCode,
++i;
}
}
- if (!html.isEmpty())
+
+ // replace all <@link> tags: "(<@link node=\"([^\"]+)\">).*(</@link>)"
+ // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)(</@\\2>)" tags
+ src = html;
+ html = QString();
+ static const QString markTags[] = { "link", "type", "headerfile", "func" };
+ bool done = false;
+ for (int i = 0, n = src.size(); i < n;) {
+ if (src.at(i) == charLangle && src.at(i + 1) == charAt) {
+ if (nameAlignment && !done) {
+ if (!html.isEmpty()) {
+ xmlWriter().writeCharacters(html);
+ html.clear();
+ }
+ xmlWriter().writeEndElement(); // </<entry>
+ xmlWriter().writeStartElement("entry");
+ xmlWriter().writeAttribute("outputclass=","memItemRight bottomAlign");
+ done = true;
+ }
+ i += 2;
+ bool handled = false;
+ for (int k = 0; k != 4; ++k) {
+ if (parseArg(src, markTags[k], &i, n, &arg, &par1)) {
+ const Node* n = 0;
+ if (k == 0) {
+ if (!html.isEmpty()) {
+ xmlWriter().writeCharacters(html);
+ html.clear();
+ }
+ n = CodeMarker::nodeForString(par1.toString());
+ QString link = linkForNode(n, relative);
+ addLink(link, arg);
+ }
+ else {
+ if (!html.isEmpty()) {
+ xmlWriter().writeCharacters(html);
+ html.clear();
+ }
+ par1 = QStringRef();
+ marker->resolveTarget(arg.toString(), myTree, relative);
+ QString link = linkForNode(n,relative);
+ addLink(link, arg);
+ }
+ handled = true;
+ break;
+ }
+ }
+ }
+ else {
+ html += src.at(i++);
+ }
+ }
+
+ if (!html.isEmpty()) {
xmlWriter().writeCharacters(html);
+ }
}
void DitaXmlGenerator::generateLink(const Atom* atom,
diff --git a/tools/qdoc3/ditaxmlgenerator.h b/tools/qdoc3/ditaxmlgenerator.h
index 35c49ae..a5346a5 100644
--- a/tools/qdoc3/ditaxmlgenerator.h
+++ b/tools/qdoc3/ditaxmlgenerator.h
@@ -267,6 +267,7 @@ class DitaXmlGenerator : public PageGenerator
CodeMarker* marker,
bool apiDesc,
const QString& title);
+ void addLink(const QString& href, const QStringRef& text);
private:
QMap<QString, QString> refMap;