Skip to content

Commit

Permalink
issue #8590 XML: Issue with spacing around <programlisting>
Browse files Browse the repository at this point in the history
In the JavaDoc documentation we see:
```
{@code  text}
    Equivalent to <code>{@literal}</code>.
```
and
```
{@literal  text}
    Displays text without interpreting the text as HTML markup or nested javadoc tags
```

These commands have been implemented by means of transforming them into doxygen commands.

This implementation also:
- the `{@literal ..}` command, #4953 JavaDoc @literal is not recognized (Origin: bugzilla #688386)
- #4949 JavaDoc @code makes a block element instead of inline element (Origin: bugzilla #688381)
- #4952 JavaDoc @code generates link (Origin: bugzilla #688385)
  • Loading branch information
albert-github committed Dec 7, 2021
1 parent 5533ffa commit 6c5b929
Show file tree
Hide file tree
Showing 28 changed files with 240 additions and 69 deletions.
2 changes: 2 additions & 0 deletions src/cmdmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ CommandMap cmdMap[] =
{ "maninclude", CMD_MANINCLUDE },
{ "xmlinclude", CMD_XMLINCLUDE },
{ "iline", CMD_ILINE },
{ "iliteral", CMD_ILITERAL },
{ "endiliteral", CMD_ENDILITERAL },
{ 0, 0 },
};

Expand Down
2 changes: 2 additions & 0 deletions src/cmdmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ enum CommandType
CMD_MANINCLUDE = 114,
CMD_XMLINCLUDE = 115,
CMD_ILINE = 116,
CMD_ILITERAL = 117,
CMD_ENDILITERAL = 118,
};

enum HtmlTagType
Expand Down
15 changes: 11 additions & 4 deletions src/commentcnv.l
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,14 @@ SLASHopt [/]*
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<CComment>"{"[ \t]*"@code"/[ \t\n] {
copyToOutput(yyscanner,"@code",5);
copyToOutput(yyscanner,"@iliteral{code}",15);
yyextra->lastCommentContext = YY_START;
yyextra->javaBlock=1;
yyextra->blockName=&yytext[1];
BEGIN(VerbatimCode);
}
<CComment>"{"[ \t]*"@literal"/[ \t\n] {
copyToOutput(yyscanner,"@iliteral",9);
yyextra->lastCommentContext = YY_START;
yyextra->javaBlock=1;
yyextra->blockName=&yytext[1];
Expand Down Expand Up @@ -464,7 +471,7 @@ SLASHopt [/]*
yyextra->lastCommentContext = YY_START;
BEGIN(Verbatim);
}
<CComment,ReadLine>[\\@]("verbatim"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
<CComment,ReadLine>[\\@]("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
copyToOutput(yyscanner,yytext,(int)yyleng);
yyextra->blockName=&yytext[1];
yyextra->lastCommentContext = YY_START;
Expand All @@ -479,7 +486,7 @@ SLASHopt [/]*
<Scan>. { /* any other character */
copyToOutput(yyscanner,yytext,(int)yyleng);
}
<Verbatim>[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
<Verbatim>[\\@]("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
copyToOutput(yyscanner,yytext,(int)yyleng);
if (&yytext[1]==yyextra->blockName) // end of formula
{
Expand Down Expand Up @@ -511,7 +518,7 @@ SLASHopt [/]*
yyextra->javaBlock--;
if (yyextra->javaBlock==0)
{
copyToOutput(yyscanner," @endcode ",10);
copyToOutput(yyscanner," @endiliteral ",14);
BEGIN(yyextra->lastCommentContext);
}
else
Expand Down
9 changes: 5 additions & 4 deletions src/commentscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ static const std::map< std::string, DocCmdMap > docCmdMap =
{ "weakgroup", { &handleWeakGroup, CommandSpacing::Invisible }},
{ "xmlinclude", { 0, CommandSpacing::Inline }},
{ "xmlonly", { &handleFormatBlock, CommandSpacing::Invisible }},
{ "xrefitem", { &handleXRefItem, CommandSpacing::XRef }}
{ "xrefitem", { &handleXRefItem, CommandSpacing::XRef }},
{ "iliteral", { &handleFormatBlock, CommandSpacing::Inline }},
};

#define YY_NO_INPUT 1
Expand Down Expand Up @@ -1491,7 +1492,7 @@ STopt [^\n@\\]*

/* ----- handle arguments of the preformatted block commands ------- */

<FormatBlock>{CMD}("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endcode"|"endmsc")/{NW} { // possible ends
<FormatBlock>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"enddot"|"endcode"|"endmsc")/{NW} { // possible ends
addOutput(yyscanner,yytext);
if (&yytext[4]==yyextra->blockName) // found end of the block
{
Expand All @@ -1513,12 +1514,12 @@ STopt [^\n@\\]*
addOutput(yyscanner,'\n');
}
<FormatBlock>{CCS} { // start of a C-comment
if (!(yyextra->blockName=="code" || yyextra->blockName=="verbatim")) yyextra->commentCount++;
if (!(yyextra->blockName=="code" || yyextra->blockName=="verbatim" || yyextra->blockName=="iliteral")) yyextra->commentCount++;
addOutput(yyscanner,yytext);
}
<FormatBlock>{CCE} { // end of a C-comment
addOutput(yyscanner,yytext);
if (!(yyextra->blockName=="code" || yyextra->blockName=="verbatim"))
if (!(yyextra->blockName=="code" || yyextra->blockName=="verbatim" || yyextra->blockName=="iliteral"))
{
yyextra->commentCount--;
if (yyextra->commentCount<0)
Expand Down
12 changes: 10 additions & 2 deletions src/docbookvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ DB_VIS_C
filter(s->text());
m_t << "</computeroutput></literallayout>";
break;
case DocVerbatim::JavaDocLiteral:
filter(s->text(), true);
break;
case DocVerbatim::JavaDocCode:
m_t << "<computeroutput>";
filter(s->text(), true);
m_t << "</computeroutput>";
break;
case DocVerbatim::HtmlOnly:
break;
case DocVerbatim::RtfOnly:
Expand Down Expand Up @@ -1648,10 +1656,10 @@ DB_VIS_C
}


void DocbookDocVisitor::filter(const QCString &str)
void DocbookDocVisitor::filter(const QCString &str, const bool retainNewLine)
{
DB_VIS_C
m_t << convertToDocBook(str);
m_t << convertToDocBook(str, retainNewLine);
}

void DocbookDocVisitor::startLink(const QCString &file,const QCString &anchor)
Expand Down
2 changes: 1 addition & 1 deletion src/docbookvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DocbookDocVisitor : public DocVisitor
//--------------------------------------
// helper functions
//--------------------------------------
void filter(const QCString &str);
void filter(const QCString &str, const bool retainNewLine = false);
void startLink(const QCString &file,
const QCString &anchor);
void endLink();
Expand Down
50 changes: 50 additions & 0 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5576,6 +5576,54 @@ int DocPara::handleCommand(const QCString &cmdName, const int tok)
m_parser.tokenizer.setStatePara();
}
break;
case CMD_ILITERAL:
{
DocVerbatim::Type t = DocVerbatim::JavaDocLiteral;
m_parser.tokenizer.setStateILiteralOpt();
retval = m_parser.tokenizer.lex();

QCString fullMatch = m_parser.context.token->verb;
int idx = fullMatch.find('{');
int idxEnd = fullMatch.find("}",idx+1);
StringVector optList;
if (idx != -1) // options present
{
QCString optStr = fullMatch.mid(idx+1,idxEnd-idx-1).stripWhiteSpace();
optList = split(optStr.str(),",");
for (const auto &opt : optList)
{
if (opt.empty()) continue;
bool found = false;
QCString locOpt(opt);
locOpt = locOpt.stripWhiteSpace().lower();
if (locOpt == "code")
{
t = DocVerbatim::JavaDocCode;
}
else if (!locOpt.isEmpty())
{
warn(m_parser.context.fileName,m_parser.tokenizer.getLineNr(), "Unknown option '%s' for '\\iliteral'",qPrint(opt));
}
}
}

m_parser.tokenizer.setStateILiteral();
retval = m_parser.tokenizer.lex();
m_children.push_back(std::make_unique<DocVerbatim>(m_parser,this,m_parser.context.context,m_parser.context.token->verb,t,m_parser.context.isExample,m_parser.context.exampleName));
if (retval==0)
{
if (t == DocVerbatim::JavaDocCode)
{
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"javadoc code section ended without end marker");
}
else
{
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"javadoc literal section ended without end marker");
}
}
m_parser.tokenizer.setStatePara();
}
break;
case CMD_VERBATIM:
{
m_parser.tokenizer.setStateVerbatim();
Expand Down Expand Up @@ -5735,6 +5783,7 @@ int DocPara::handleCommand(const QCString &cmdName, const int tok)
case CMD_ENDDBONLY:
case CMD_ENDLINK:
case CMD_ENDVERBATIM:
case CMD_ENDILITERAL:
case CMD_ENDDOT:
case CMD_ENDMSC:
case CMD_ENDUML:
Expand Down Expand Up @@ -7376,6 +7425,7 @@ static uint isVerbatimSection(const char *data,uint i,uint len,QCString &endMark
CHECK_FOR_COMMAND("code",endMarker="endcode");
CHECK_FOR_COMMAND("msc",endMarker="endmsc");
CHECK_FOR_COMMAND("verbatim",endMarker="endverbatim");
CHECK_FOR_COMMAND("iliteral",endMarker="endiliteral");
CHECK_FOR_COMMAND("latexonly",endMarker="endlatexonly");
CHECK_FOR_COMMAND("htmlonly",endMarker="endhtmlonly");
CHECK_FOR_COMMAND("xmlonly",endMarker="endxmlonly");
Expand Down
2 changes: 1 addition & 1 deletion src/docparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class DocSeparator : public DocNode
class DocVerbatim : public DocNode
{
public:
enum Type { Code, HtmlOnly, ManOnly, LatexOnly, RtfOnly, XmlOnly, Verbatim, Dot, Msc, DocbookOnly, PlantUML };
enum Type { Code, HtmlOnly, ManOnly, LatexOnly, RtfOnly, XmlOnly, Verbatim, Dot, Msc, DocbookOnly, PlantUML, JavaDocCode, JavaDocLiteral };
DocVerbatim(DocParser &parser,DocNode *parent,const QCString &context,
const QCString &text, Type t,bool isExample,
const QCString &exampleFile,bool isBlock=FALSE,const QCString &lang=QCString());
Expand Down
2 changes: 2 additions & 0 deletions src/doctokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class DocTokenizer
void setStateDbOnly();
void setStateRtfOnly();
void setStateVerbatim();
void setStateILiteral();
void setStateILiteralOpt();
void setStateDot();
void setStateMsc();
void setStateParam();
Expand Down
44 changes: 41 additions & 3 deletions src/doctokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ LINENR {BLANK}*[1-9][0-9]*
%x St_XmlOnly
%x St_DbOnly
%x St_Verbatim
%x St_ILiteral
%x St_ILiteralOpt
%x St_Dot
%x St_Msc
%x St_PlantUMLOpt
Expand Down Expand Up @@ -841,12 +843,28 @@ LINENR {BLANK}*[1-9][0-9]*
yyextra->token->verb=stripEmptyLines(yyextra->token->verb);
return RetVal_OK;
}
<St_Verbatim>[^\\@\n]+ |
<St_Verbatim>\n |
<St_Verbatim>. { /* Verbatim text */
<St_ILiteral>{CMD}"endiliteral " { // note extra space as this is artificially added
// remove spaces that have been added
yyextra->token->verb=yyextra->token->verb.mid(1,yyextra->token->verb.length()-2);
return RetVal_OK;
}
<St_Verbatim,St_ILiteral>[^\\@\n]+ |
<St_Verbatim,St_ILiteral>\n |
<St_Verbatim,St_ILiteral>. { /* Verbatim / javadac literal/code text */
lineCount(yytext,yyleng);
yyextra->token->verb+=yytext;
}
<St_ILiteralOpt>{BLANK}*"{"[a-zA-Z_,:0-9\. ]*"}" { // option(s) present
yyextra->token->verb = QCString(yytext).stripWhiteSpace();
return RetVal_OK;
}
<St_ILiteralOpt>"\\ilinebr" |
<St_ILiteralOpt>"\n" |
<St_ILiteralOpt>. {
yyextra->token->sectionId = "";
unput_string(yytext,yyleng);
return RetVal_OK;
}
<St_Dot>{CMD}"enddot" {
return RetVal_OK;
}
Expand Down Expand Up @@ -1312,6 +1330,10 @@ LINENR {BLANK}*[1-9][0-9]*
yyextra->endMarker="endverbatim";
BEGIN(St_SecSkip);
}
<St_Sections>{CMD}"iliteral"/[^a-z_A-Z0-9] {
yyextra->endMarker="endiliteral";
BEGIN(St_SecSkip);
}
<St_Sections>{CMD}"dot"/[^a-z_A-Z0-9] {
yyextra->endMarker="enddot";
BEGIN(St_SecSkip);
Expand Down Expand Up @@ -1762,6 +1784,22 @@ void DocTokenizer::setStateLatexOnly()
BEGIN(St_LatexOnly);
}

void DocTokenizer::setStateILiteral()
{
yyscan_t yyscanner = p->yyscanner;
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
yyextra->token->verb="";
BEGIN(St_ILiteral);
}

void DocTokenizer::setStateILiteralOpt()
{
yyscan_t yyscanner = p->yyscanner;
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
yyextra->token->verb="";
BEGIN(St_ILiteralOpt);
}

void DocTokenizer::setStateVerbatim()
{
yyscan_t yyscanner = p->yyscanner;
Expand Down
15 changes: 13 additions & 2 deletions src/htmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ static bool mustBeOutsideParagraph(const DocNode *n)
case DocNode::Kind_Verbatim:
{
DocVerbatim *dv = (DocVerbatim*)n;
return dv->type()!=DocVerbatim::HtmlOnly || dv->isBlock();
DocVerbatim::Type t = dv->type();
if (t == DocVerbatim::JavaDocCode || t == DocVerbatim::JavaDocLiteral) return FALSE;
return t!=DocVerbatim::HtmlOnly || dv->isBlock();
}
case DocNode::Kind_StyleChange:
return ((DocStyleChange*)n)->style()==DocStyleChange::Preformatted ||
Expand Down Expand Up @@ -532,6 +534,14 @@ void HtmlDocVisitor::visit(DocVerbatim *s)
m_t << "</pre>";
forceStartParagraph(s);
break;
case DocVerbatim::JavaDocLiteral:
filter(s->text(), true);
break;
case DocVerbatim::JavaDocCode:
m_t << "<code class=\"JavaDocCode\">";
filter(s->text(), true);
m_t << "</code>";
break;
case DocVerbatim::HtmlOnly:
{
if (s->isBlock()) forceEndParagraph(s);
Expand Down Expand Up @@ -2148,7 +2158,7 @@ void HtmlDocVisitor::visitPost(DocParBlock *)



void HtmlDocVisitor::filter(const QCString &str)
void HtmlDocVisitor::filter(const QCString &str, const bool retainNewline)
{
if (str.isEmpty()) return;
const char *p=str.data();
Expand All @@ -2158,6 +2168,7 @@ void HtmlDocVisitor::filter(const QCString &str)
c=*p++;
switch(c)
{
case '\n': if(retainNewline) m_t << "<br/>"; m_t << c; break;
case '<': m_t << "&lt;"; break;
case '>': m_t << "&gt;"; break;
case '&': m_t << "&amp;"; break;
Expand Down
2 changes: 1 addition & 1 deletion src/htmldocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class HtmlDocVisitor : public DocVisitor
//--------------------------------------

void writeObfuscatedMailAddress(const QCString &url);
void filter(const QCString &str);
void filter(const QCString &str, const bool retainNewline = false);
void filterQuotedCdataAttr(const QCString &str);
void startLink(const QCString &ref,const QCString &file,
const QCString &relPath,const QCString &anchor,
Expand Down
13 changes: 11 additions & 2 deletions src/latexdocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ void LatexDocVisitor::visit(DocVerbatim *s)
m_ci.endCodeFragment("DoxyCode");
}
break;
case DocVerbatim::JavaDocLiteral:
filter(s->text(), true);
break;
case DocVerbatim::JavaDocCode:
m_t << "{\\ttfamily ";
filter(s->text(), true);
m_t << "}";
break;
case DocVerbatim::Verbatim:
m_t << "\\begin{DoxyVerb}";
m_t << s->text();
Expand Down Expand Up @@ -1894,14 +1902,15 @@ void LatexDocVisitor::visitPost(DocParBlock *)
if (m_hide) return;
}

void LatexDocVisitor::filter(const QCString &str)
void LatexDocVisitor::filter(const QCString &str, const bool retainNewLine)
{
filterLatexString(m_t,str,
m_insideTabbing,
m_insidePre,
m_insideItem,
m_ci.usedTableLevel()>0, // insideTable
false // keepSpaces
false, // keepSpaces
retainNewLine
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/latexdocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class LatexDocVisitor : public DocVisitor
// helper functions
//--------------------------------------

void filter(const QCString &str);
void filter(const QCString &str, const bool retainNewLine = false);
void startLink(const QCString &ref,const QCString &file,
const QCString &anchor,bool refToTable=FALSE);
void endLink(const QCString &ref,const QCString &file,
Expand Down
Loading

0 comments on commit 6c5b929

Please sign in to comment.