diff options
author | David Boddie <david.boddie@nokia.com> | 2011-01-20 16:26:10 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2011-01-20 16:26:10 (GMT) |
commit | 0418b2b540fcb0e3d76299e3df69ad600292adf9 (patch) | |
tree | 9b1ce67d5cfcfacfd2556146277698afe231dba0 /tools | |
parent | 41f93881ad51d21aece16d8c1c272c0ff3246db8 (diff) | |
download | Qt-0418b2b540fcb0e3d76299e3df69ad600292adf9.zip Qt-0418b2b540fcb0e3d76299e3df69ad600292adf9.tar.gz Qt-0418b2b540fcb0e3d76299e3df69ad600292adf9.tar.bz2 |
Ongoing improvements and fixes to syntax highlighting.
Added an atom for JavaScript code.
Fixed example file quoting to use the appropriate atom for each file.
Changed C++ code marking to mark up classes as types.
Fixed C++ quoting bug that caused the last character to be lost.
Fixed indentation of code to not insert spaces inside elements.
Documented the change in the meaning of the \c command.
Simplified the use of CSS classes in the HTML output.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qdoc3/atom.h | 36 | ||||
-rw-r--r-- | tools/qdoc3/codemarker.h | 2 | ||||
-rw-r--r-- | tools/qdoc3/cppcodemarker.cpp | 35 | ||||
-rw-r--r-- | tools/qdoc3/cppcodemarker.h | 1 | ||||
-rw-r--r-- | tools/qdoc3/generator.cpp | 28 | ||||
-rw-r--r-- | tools/qdoc3/htmlgenerator.cpp | 23 | ||||
-rw-r--r-- | tools/qdoc3/jscodemarker.cpp | 8 | ||||
-rw-r--r-- | tools/qdoc3/jscodemarker.h | 1 | ||||
-rw-r--r-- | tools/qdoc3/plaincodemarker.cpp | 5 | ||||
-rw-r--r-- | tools/qdoc3/plaincodemarker.h | 1 | ||||
-rw-r--r-- | tools/qdoc3/qmlcodemarker.cpp | 8 | ||||
-rw-r--r-- | tools/qdoc3/qmlcodemarker.h | 1 |
12 files changed, 100 insertions, 49 deletions
diff --git a/tools/qdoc3/atom.h b/tools/qdoc3/atom.h index a20e057..ab4ee44 100644 --- a/tools/qdoc3/atom.h +++ b/tools/qdoc3/atom.h @@ -78,9 +78,9 @@ class Atom EndQmlText, #endif FootnoteLeft, - FootnoteRight, + FootnoteRight, // 20 FormatElse, - FormatEndif, // 20 + FormatEndif, FormatIf, FormattingLeft, FormattingRight, @@ -88,19 +88,23 @@ class Atom GuidLink, Image, ImageText, - InlineImage, + InlineImage, // 30 +#ifdef QDOC_QML + JavaScript, + EndJavaScript, +#endif LegaleseLeft, - LegaleseRight, // 30 + LegaleseRight, LineBreak, Link, LinkNode, ListLeft, ListItemNumber, - ListTagLeft, // 36 - ListTagRight, // 37 - ListItemLeft, // 38 - ListItemRight, // 39 - ListRight, // 40 + ListTagLeft, // 40 + ListTagRight, // 41 + ListItemLeft, // 42 + ListItemRight, // 43 + ListRight, // 44 Nop, ParaLeft, ParaRight, @@ -108,30 +112,30 @@ class Atom Qml, QmlText, #endif - QuotationLeft, + QuotationLeft, // 50 QuotationRight, RawString, - SectionLeft, // 49 + SectionLeft, // 53 SectionRight, SectionHeadingLeft, SectionHeadingRight, SidebarLeft, SidebarRight, SinceList, - SnippetCommand, + SnippetCommand, // 60 SnippetIdentifier, SnippetLocation, - String, // 59 - TableLeft, // 60 + String, // 63 + TableLeft, // 64 TableRight, TableHeaderLeft, TableHeaderRight, TableRowLeft, TableRowRight, - TableItemLeft, + TableItemLeft, // 70 TableItemRight, TableOfContents, - Target, // 69 + Target, // 73 UnhandledFormat, UnknownCommand, Last = UnknownCommand diff --git a/tools/qdoc3/codemarker.h b/tools/qdoc3/codemarker.h index e643082..6c45581 100644 --- a/tools/qdoc3/codemarker.h +++ b/tools/qdoc3/codemarker.h @@ -48,6 +48,7 @@ #include <qpair.h> +#include "atom.h" #include "node.h" QT_BEGIN_NAMESPACE @@ -121,6 +122,7 @@ class CodeMarker virtual bool recognizeCode(const QString& code) = 0; virtual bool recognizeExtension(const QString& ext) = 0; virtual bool recognizeLanguage(const QString& lang) = 0; + virtual Atom::Type atomType() const = 0; virtual QString plainName(const Node *node) = 0; virtual QString plainFullName(const Node *node, const Node *relative = 0) = 0; diff --git a/tools/qdoc3/cppcodemarker.cpp b/tools/qdoc3/cppcodemarker.cpp index 2b7db62..9b696a7 100644 --- a/tools/qdoc3/cppcodemarker.cpp +++ b/tools/qdoc3/cppcodemarker.cpp @@ -103,6 +103,14 @@ bool CppCodeMarker::recognizeLanguage(const QString &lang) } /*! + Returns the type of atom used to represent C++ code in the documentation. +*/ +Atom::Type CppCodeMarker::atomType() const +{ + return Atom::Code; +} + +/*! Returns the \a node name, or "()" if \a node is a Node::Function node. */ @@ -417,7 +425,6 @@ QString CppCodeMarker::markedUpIncludes(const QStringList& includes) code += "<@preprocessor>#include <<@headerfile>" + *inc + "</@headerfile>></@preprocessor>\n"; ++inc; } - Location location; return code; } @@ -937,6 +944,7 @@ QString CppCodeMarker::addMarkUp(const QString &in, while (ch != EOF) { int second = i; QString tag; + bool target = false; if (isalpha(ch) || ch == '_') { QString ident; @@ -946,9 +954,10 @@ QString CppCodeMarker::addMarkUp(const QString &in, } while (isalnum(ch) || ch == '_'); if (classRegExp.exactMatch(ident)) { - tag = QLatin1String("class"); + tag = QLatin1String("type"); } else if (functionRegExp.exactMatch(ident)) { - tag = QLatin1String("function"); + tag = QLatin1String("func"); + target = true; } else if (types.contains(ident)) { tag = QLatin1String("type"); } else if (keywords.contains(ident)) { @@ -956,7 +965,8 @@ QString CppCodeMarker::addMarkUp(const QString &in, } else if (braceDepth == 0 && parenDepth == 0) { if (QString(code.unicode() + i - 1, code.length() - (i - 1)) .indexOf(QRegExp(QLatin1String("^\\s*\\("))) == 0) - tag = QLatin1String("function"); + tag = QLatin1String("func"); + target = true; } } else if (isdigit(ch)) { do { @@ -1074,13 +1084,20 @@ QString CppCodeMarker::addMarkUp(const QString &in, } } - if (!tag.isEmpty()) - out += QLatin1String("<@") + tag + QLatin1String(">"); - + QString text; if (tag.isEmpty() && i == code.length()) - out += protect(code.mid(second - 1, i - second + 1)); + text = code.mid(second - 1, i - second + 1); else - out += protect(code.mid(second - 1, i - second)); + text = code.mid(second - 1, i - second); + + if (!tag.isEmpty()) { + out += QLatin1String("<@") + tag; + if (target) + out += QLatin1String(" target=\"") + text + QLatin1String("()\""); + out += QLatin1String(">"); + } + + out += protect(text); if (!tag.isEmpty()) out += QLatin1String("</@") + tag + QLatin1String(">"); diff --git a/tools/qdoc3/cppcodemarker.h b/tools/qdoc3/cppcodemarker.h index bb307f9..8206dbe 100644 --- a/tools/qdoc3/cppcodemarker.h +++ b/tools/qdoc3/cppcodemarker.h @@ -59,6 +59,7 @@ class CppCodeMarker : public CodeMarker virtual bool recognizeCode(const QString& code); virtual bool recognizeExtension(const QString& ext); virtual bool recognizeLanguage(const QString& lang); + virtual Atom::Type atomType() const; virtual QString plainName(const Node *node); virtual QString plainFullName(const Node *node, const Node *relative); virtual QString markedUpCode(const QString& code, diff --git a/tools/qdoc3/generator.cpp b/tools/qdoc3/generator.cpp index 65b9a09..62ec966 100644 --- a/tools/qdoc3/generator.cpp +++ b/tools/qdoc3/generator.cpp @@ -524,8 +524,9 @@ void Generator::generateBody(const Node *node, CodeMarker *marker) Quoter quoter; Doc::quoteFromFile(fake->doc().location(), quoter, fake->name()); QString code = quoter.quoteTo(fake->location(), "", ""); - text << Atom(Atom::Code, code); - generateText(text, fake, CodeMarker::markerForFileName(fake->name())); + CodeMarker *codeMarker = CodeMarker::markerForFileName(fake->name()); + text << Atom(codeMarker->atomType(), code); + generateText(text, fake, codeMarker); } } } @@ -683,26 +684,17 @@ QString Generator::indent(int level, const QString& markedCode) int i = 0; while (i < (int) markedCode.length()) { - if (markedCode.at(i) == QLatin1Char('<')) { - while (i < (int) markedCode.length()) { - t += markedCode.at(i++); - if (markedCode.at(i - 1) == QLatin1Char('>')) - break; - } + if (markedCode.at(i) == QLatin1Char('\n')) { + column = 0; } else { - if (markedCode.at(i) == QLatin1Char('\n')) { - column = 0; - } - else { - if (column == 0) { - for (int j = 0; j < level; j++) - t += QLatin1Char(' '); - } - column++; + if (column == 0) { + for (int j = 0; j < level; j++) + t += QLatin1Char(' '); } - t += markedCode.at(i++); + column++; } + t += markedCode.at(i++); } return t; } diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index a3156c3..4385dfd 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -467,6 +467,9 @@ int HtmlGenerator::generateAtom(const Atom *atom, out() << "</p>\n"; break; case Atom::C: + // This may at one time have been used to mark up C++ code but it is + // now widely used to write teletype text. As a result, text marked + // with the \c command is not passed to a code marker. out() << formattingLeftMap()[ATOM_FORMATTING_TELETYPE]; if (inLink) { out() << protectEnc(plainCode(atom->string())); @@ -477,7 +480,7 @@ int HtmlGenerator::generateAtom(const Atom *atom, out() << formattingRightMap()[ATOM_FORMATTING_TELETYPE]; break; case Atom::Code: - out() << "<pre class=\"highlightedCode brush: cpp\">" + out() << "<pre class=\"cpp\">" << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()), marker,relative)) << "</pre>\n"; @@ -489,10 +492,16 @@ int HtmlGenerator::generateAtom(const Atom *atom, marker,relative)) << "</pre>\n"; break; + case Atom::JavaScript: + out() << "<pre class=\"js\">" + << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()), + marker,relative)) + << "</pre>\n"; + break; #endif case Atom::CodeNew: out() << "<p>you can rewrite it as</p>\n" - << "<pre class=\"highlightedCode brush: cpp\">" + << "<pre class=\"cpp\">" << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()), marker,relative)) << "</pre>\n"; @@ -501,7 +510,7 @@ int HtmlGenerator::generateAtom(const Atom *atom, out() << "<p>For example, if you have code like</p>\n"; // fallthrough case Atom::CodeBad: - out() << "<pre class=\"highlightedCode brush: cpp\">" + out() << "<pre class=\"cpp\">" << trimmedTrailing(protectEnc(plainCode(indent(codeIndent,atom->string())))) << "</pre>\n"; break; @@ -1773,7 +1782,7 @@ void HtmlGenerator::generateBrief(const Node *node, CodeMarker *marker, void HtmlGenerator::generateIncludes(const InnerNode *inner, CodeMarker *marker) { if (!inner->includes().isEmpty()) { - out() << "<pre class=\"highlightedCode brush: cpp\">" + out() << "<pre class=\"cpp\">" << trimmedTrailing(highlightedCode(indent(codeIndent, marker->markedUpIncludes(inner->includes())), marker,inner)) @@ -2757,8 +2766,8 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, // replace all <@link> tags: "(<@link node=\"([^\"]+)\">).*(</@link>)" bool done = false; for (int i = 0, srcSize = src.size(); i < srcSize;) { - if (src.at(i) == charLangle && src.at(i + 1).unicode() == '@') { - if (alignNames && !done) {// && (i != 0)) Why was this here? + if (src.at(i) == charLangle && src.at(i + 1) == charAt) { + if (alignNames && !done) { html += "</td><td class=\"memItemRight bottomAlign\">"; done = true; } @@ -2819,6 +2828,7 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, if (parseArg(src, typeTag, &i, srcSize, &arg, &par1)) { par1 = QStringRef(); const Node* n = marker->resolveTarget(arg.toString(), myTree, relative, self); + html += QLatin1String("<span class=\"type\">"); if (n && n->subType() == Node::QmlBasicType) { if (relative && relative->subType() == Node::QmlClass) addLink(linkForNode(n,relative), arg, &html); @@ -2827,6 +2837,7 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, } else addLink(linkForNode(n,relative), arg, &html); + html += QLatin1String("</span>"); handled = true; } else if (parseArg(src, headerTag, &i, srcSize, &arg, &par1)) { diff --git a/tools/qdoc3/jscodemarker.cpp b/tools/qdoc3/jscodemarker.cpp index 80df0aa..5a513f7 100644 --- a/tools/qdoc3/jscodemarker.cpp +++ b/tools/qdoc3/jscodemarker.cpp @@ -101,6 +101,14 @@ bool JsCodeMarker::recognizeLanguage(const QString &language) return language == "JavaScript" || language == "ECMAScript"; } +/*! + Returns the type of atom used to represent JavaScript code in the documentation. +*/ +Atom::Type JsCodeMarker::atomType() const +{ + return Atom::JavaScript; +} + QString JsCodeMarker::markedUpCode(const QString &code, const Node *relative, const Location &location) diff --git a/tools/qdoc3/jscodemarker.h b/tools/qdoc3/jscodemarker.h index 6d85063..9b55819 100644 --- a/tools/qdoc3/jscodemarker.h +++ b/tools/qdoc3/jscodemarker.h @@ -59,6 +59,7 @@ public: virtual bool recognizeCode(const QString &code); virtual bool recognizeExtension(const QString &ext); virtual bool recognizeLanguage(const QString &language); + virtual Atom::Type atomType() const; virtual QString markedUpCode(const QString &code, const Node *relative, diff --git a/tools/qdoc3/plaincodemarker.cpp b/tools/qdoc3/plaincodemarker.cpp index 9819593..e7926da 100644 --- a/tools/qdoc3/plaincodemarker.cpp +++ b/tools/qdoc3/plaincodemarker.cpp @@ -66,6 +66,11 @@ bool PlainCodeMarker::recognizeLanguage( const QString& /* lang */ ) return false; } +Atom::Type PlainCodeMarker::atomType() const +{ + return Atom::Code; +} + QString PlainCodeMarker::plainName( const Node * /* node */ ) { return ""; diff --git a/tools/qdoc3/plaincodemarker.h b/tools/qdoc3/plaincodemarker.h index 1c469a0..34fa63d 100644 --- a/tools/qdoc3/plaincodemarker.h +++ b/tools/qdoc3/plaincodemarker.h @@ -59,6 +59,7 @@ public: bool recognizeCode( const QString& code ); bool recognizeExtension( const QString& ext ); bool recognizeLanguage( const QString& lang ); + Atom::Type atomType() const; QString plainName( const Node *node ); QString plainFullName( const Node *node, const Node *relative ); QString markedUpCode( const QString& code, const Node *relative, const Location &location ); diff --git a/tools/qdoc3/qmlcodemarker.cpp b/tools/qdoc3/qmlcodemarker.cpp index e0ba0e1..a7dc5a0 100644 --- a/tools/qdoc3/qmlcodemarker.cpp +++ b/tools/qdoc3/qmlcodemarker.cpp @@ -103,6 +103,14 @@ bool QmlCodeMarker::recognizeLanguage(const QString &language) } /*! + Returns the type of atom used to represent QML code in the documentation. +*/ +Atom::Type QmlCodeMarker::atomType() const +{ + return Atom::Qml; +} + +/*! Returns the name of the \a node. Method names include are returned with a trailing set of parentheses. */ diff --git a/tools/qdoc3/qmlcodemarker.h b/tools/qdoc3/qmlcodemarker.h index b1d365c..1665b16 100644 --- a/tools/qdoc3/qmlcodemarker.h +++ b/tools/qdoc3/qmlcodemarker.h @@ -60,6 +60,7 @@ public: virtual bool recognizeCode(const QString &code); virtual bool recognizeExtension(const QString &ext); virtual bool recognizeLanguage(const QString &language); + virtual Atom::Type atomType() const; virtual QString plainName(const Node *node); virtual QString plainFullName(const Node *node, const Node *relative); virtual QString markedUpCode(const QString &code, |