diff options
author | Martin Smith <martin.smith@qt.io> | 2018-06-14 12:41:42 +0200 |
---|---|---|
committer | Martin Smith <martin.smith@qt.io> | 2018-06-18 07:34:19 +0000 |
commit | 7aee128ca08637cfc66a3645c26342ce18501cc1 (patch) | |
tree | 1a21c58636ef426423096a1e6f0ac020b0b5ccfc /src/qdoc/doc.cpp | |
parent | 1ca3602f1c4492c1d723f53ae651e4306c9a45c4 (diff) | |
download | qttools-7aee128ca08637cfc66a3645c26342ce18501cc1.tar.gz |
qdoc: Allow escaping of single words to prevent autolinking
This update allows the writer to prevent QDoc from automatically
making a word into a link. For example, because LayoutMirroring
looks like a name that should become a link to something on a type
reference page, QDoc finds that reference page and the appropriate
section and makes LayoutMirroring be a link to it. By prepending a
single '\' to it in the text like this: \LayoutMirroring QDoc does
not turn it into a link and just appends LayoutMirroring to the text.
Change-Id: Ied7653d1e8f9d56dd5d86d1c16e2aaedf0a88a42
Task-number: QTBUG-20537
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/qdoc/doc.cpp')
-rw-r--r-- | src/qdoc/doc.cpp | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/qdoc/doc.cpp b/src/qdoc/doc.cpp index d4d800024..723e88092 100644 --- a/src/qdoc/doc.cpp +++ b/src/qdoc/doc.cpp @@ -1376,11 +1376,60 @@ void DocParser::parse(const QString& source, } } } else { - location().warning( - tr("Unknown command '\\%1'").arg(cmdStr), - detailsUnknownCommand(metaCommandSet,cmdStr)); - enterPara(); - append(Atom::UnknownCommand, cmdStr); + int curPos = 0; + int numUppercase = 0; + int numLowercase = 0; + int numStrangeSymbols = 0; + + while (curPos < cmdStr.size()) { + unsigned char latin1Ch = cmdStr.at(curPos).toLatin1(); + if (islower(latin1Ch)) { + ++numLowercase; + ++curPos; + } else if (isupper(latin1Ch)) { + ++numUppercase; + ++curPos; + } else if (isdigit(latin1Ch)) { + if (curPos > 0) + ++curPos; + else + break; + } else if (latin1Ch == '_' || latin1Ch == '@') { + ++numStrangeSymbols; + ++curPos; + } else if ((latin1Ch == ':') && + (curPos < cmdStr.size() - 1) && + (cmdStr.at(curPos + 1) == QLatin1Char(':'))) { + ++numStrangeSymbols; + curPos += 2; + } else if (latin1Ch == '(') { + if (curPos > 0) { + if ((curPos < cmdStr.size() - 1) && + (cmdStr.at(curPos + 1) == QLatin1Char(')'))) { + ++numStrangeSymbols; + pos += 2; + break; + } else { + // ### handle functions with signatures + // and function calls + break; + } + } else { + break; + } + } else { + break; + } + } + if ((numUppercase >= 1 && numLowercase >= 2) || numStrangeSymbols > 0) { + qDebug() << "APPENDING: " << cmdStr; + appendWord(cmdStr); + } else { + location().warning(tr("Unknown command '\\%1'").arg(cmdStr), + detailsUnknownCommand(metaCommandSet,cmdStr)); + enterPara(); + append(Atom::UnknownCommand, cmdStr); + } } } } // case '\\' (qdoc markup command) |