From 839938e86dd22601b679c5f33606830850d6df81 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Mon, 20 Sep 2010 14:40:42 +0200 Subject: qdoc: DITA XML generator now avoids escaping elements. Still escapes and , for example. --- tools/qdoc3/ditaxmlgenerator.cpp | 191 +++++++++++++++++---------------------- tools/qdoc3/ditaxmlgenerator.h | 1 + 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 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 += ""; - *res += nestedStuff; - *res += ""; + if (!href.isEmpty()) { + xmlWriter().writeStartElement("xref"); + xmlWriter().writeAttribute("href", href); + xmlWriter().writeCharacters(text.toString()); + xmlWriter().writeEndElement(); // } 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(); // - xmlWriter().writeCharacters("."); + xmlWriter().writeCharacters(". "); xmlWriter().writeEndElement(); // - 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(); // 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=\"([^\"]+)\">).*()" - 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(); // - xmlWriter().writeStartElement("entry"); - xmlWriter().writeAttribute("outputclass=","memItemRight bottomAlign"); - done = true; - } - i += 2; - if (parseArg(src, linkTag, &i, n, &arg, &par1)) { - html += ""; - QString link = linkForNode( - CodeMarker::nodeForString(par1.toString()), relative); - addLink(link, arg, &html); - html += ""; - } - else { - html += charLangle; - html += charAt; - } - } - else { - html += src.at(i++); - } - } - - // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)()" 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>" -> ""; - // "<@preprocessor>" -> ""; - // "<@string>" -> ""; - // "<@char>" -> ""; - // "" -> "" - 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 "", "", - "<@preprocessor>", "", - "<@string>", "", - "<@char>", "", - "", "", - "","", - "", "", - "", "" - // "<@char>", "", - // "", "", - // "<@func>", "", - // "", "", - // "<@id>", "", - // "", "", - // "<@keyword>", "", - // "", "", - // "<@number>", "", - // "", "", - // "<@op>", "", - // "", "", - // "<@param>", "", - // "", "", - // "<@string>", "", - // "", "", + "<@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=\"([^\"]+)\">).*()" + // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)()" 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(); // + 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 refMap; -- cgit v0.12 From 445513153c6c4f80eccf77c33ca38574b5972922 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 21 Sep 2010 09:35:32 +0200 Subject: qdoc: DITA XML generator now avoids escaping and elements. --- tools/qdoc3/ditaxmlgenerator.cpp | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tools/qdoc3/ditaxmlgenerator.cpp b/tools/qdoc3/ditaxmlgenerator.cpp index 0170644..de70d29 100644 --- a/tools/qdoc3/ditaxmlgenerator.cpp +++ b/tools/qdoc3/ditaxmlgenerator.cpp @@ -3010,9 +3010,10 @@ QString DitaXmlGenerator::getMarkedUpSynopsis(const Node* node, } marked.replace(QRegExp("<@param>([a-z]+)_([1-9n])"), "\\1\\2"); +#if 0 marked.replace("<@param>",""); marked.replace("",""); - +#endif if (style == CodeMarker::Summary) { marked.replace("<@name>",""); // was "" marked.replace("",""); // was "" @@ -3023,10 +3024,12 @@ QString DitaXmlGenerator::getMarkedUpSynopsis(const Node* node, extraRegExp.setMinimal(true); marked.replace(extraRegExp,""); } +#if 0 else { marked.replace("<@extra>",""); marked.replace("",""); } +#endif if (style != CodeMarker::Detailed) { marked.replace("<@type>",""); @@ -3062,15 +3065,19 @@ void DitaXmlGenerator::writeText(const QString& markedCode, "<@type>", "<@type>", "<@headerfile>", "<@headerfile>", "<@func>", "<@func>", + "<@param>", "<@param>", + "<@extra>", "<@extra>", "", "", "", "", "", "", - "", "" + "", "", + "", "", + "", "" }; for (int i = 0, n = src.size(); i < n;) { if (src.at(i) == charLangle) { bool handled = false; - for (int k = 0; k != 8; ++k) { + for (int k = 0; k != 12; ++k) { const QString & tag = spanTags[2 * k]; if (tag == QStringRef(&src, i, tag.length())) { html += spanTags[2 * k + 1]; @@ -3104,7 +3111,10 @@ void DitaXmlGenerator::writeText(const QString& markedCode, // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)()" tags src = html; html = QString(); - static const QString markTags[] = { "link", "type", "headerfile", "func" }; + static const QString markTags[] = { + // 0 1 2 3 4 5 + "link", "type", "headerfile", "func", "param", "extra" + }; bool done = false; for (int i = 0, n = src.size(); i < n;) { if (src.at(i) == charLangle && src.at(i + 1) == charAt) { @@ -3120,10 +3130,10 @@ void DitaXmlGenerator::writeText(const QString& markedCode, } i += 2; bool handled = false; - for (int k = 0; k != 4; ++k) { + for (int k = 0; k != 6; ++k) { if (parseArg(src, markTags[k], &i, n, &arg, &par1)) { const Node* n = 0; - if (k == 0) { + if (k == 0) { // <@link> if (!html.isEmpty()) { xmlWriter().writeCharacters(html); html.clear(); @@ -3132,6 +3142,24 @@ void DitaXmlGenerator::writeText(const QString& markedCode, QString link = linkForNode(n, relative); addLink(link, arg); } + else if (k == 4) { // <@param> + if (!html.isEmpty()) { + xmlWriter().writeCharacters(html); + html.clear(); + } + xmlWriter().writeStartElement("i"); + xmlWriter().writeCharacters(arg.toString()); + xmlWriter().writeEndElement(); // + } + else if (k == 5) { // <@extra> + if (!html.isEmpty()) { + xmlWriter().writeCharacters(html); + html.clear(); + } + xmlWriter().writeStartElement("tt"); + xmlWriter().writeCharacters(arg.toString()); + xmlWriter().writeEndElement(); // + } else { if (!html.isEmpty()) { xmlWriter().writeCharacters(html); -- cgit v0.12