Skip to content

Commit

Permalink
Bug 136299 - attributes to <p> tag get lost
Browse files Browse the repository at this point in the history
Besides the `p` tag there were a number of other tags were also the attributes were lost:
- `br`
- `hr`
- `a` in case of used as an anchor i.e. with the `name=` attribute

In case of a `caption` with a `table` and no `id=` attribute with the `caption` there was still an anchor generated

In scanner.l the warnings message was a bit unclear.
  • Loading branch information
albert-github committed Feb 4, 2019
1 parent 8a31e77 commit 64ac364
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
21 changes: 15 additions & 6 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,12 @@ static int handleAHref(DocNode *parent,QList<DocNode> &children,const HtmlAttrib
{
if (!opt->value.isEmpty())
{
DocAnchor *anc = new DocAnchor(parent,opt->value,TRUE);
// copy attributes
HtmlAttribList attrList = tagHtmlAttribs;
// and remove the href attribute
bool result = attrList.remove(index);
ASSERT(result);
DocAnchor *anc = new DocAnchor(parent,opt->value,TRUE,attrList);
children.append(anc);
break; // stop looking for other tag attribs
}
Expand Down Expand Up @@ -1929,7 +1934,7 @@ DocLinkedWord::DocLinkedWord(DocNode *parent,const QCString &word,

//---------------------------------------------------------------------------

DocAnchor::DocAnchor(DocNode *parent,const QCString &id,bool newAnchor)
void DocAnchor::docAnchorInit(DocNode *parent,const QCString &id,bool newAnchor)
{
m_parent = parent;
if (id.isEmpty())
Expand Down Expand Up @@ -3073,7 +3078,7 @@ int DocHtmlHeader::parse()
}
else if (tagId==HTML_BR)
{
DocLineBreak *lb = new DocLineBreak(this);
DocLineBreak *lb = new DocLineBreak(this,g_token->attribs);
m_children.append(lb);
}
else
Expand Down Expand Up @@ -6080,13 +6085,13 @@ int DocPara::handleHtmlStartTag(const QCString &tagName,const HtmlAttribList &ta
break;
case HTML_BR:
{
DocLineBreak *lb = new DocLineBreak(this);
DocLineBreak *lb = new DocLineBreak(this,tagHtmlAttribs);
m_children.append(lb);
}
break;
case HTML_HR:
{
DocHorRuler *hr = new DocHorRuler(this);
DocHorRuler *hr = new DocHorRuler(this,tagHtmlAttribs);
m_children.append(hr);
}
break;
Expand Down Expand Up @@ -6861,6 +6866,10 @@ int DocPara::parse()
DocNode *n = g_nodeStack.pop();
ASSERT(n==this);
DBG(("DocPara::parse() end retval=%x\n",retval));
if (!g_token->endTag && retval == TK_NEWPARA && g_token->name.lower() == "p")
{
((DocPara *)n) -> m_attribs = g_token->attribs;
}
INTERNAL_ASSERT(retval==0 || retval==TK_NEWPARA || retval==TK_LISTITEM ||
retval==TK_ENDLIST || retval>RetVal_OK
);
Expand Down Expand Up @@ -7128,7 +7137,7 @@ void DocRoot::parse()
DocPara *par = new DocPara(this);
if (isFirst) { par->markFirst(); isFirst=FALSE; }
retval=par->parse();
if (!par->isEmpty())
if (!par->isEmpty() || par->attribs().count())
{
m_children.append(par);
lastPar=par;
Expand Down
23 changes: 20 additions & 3 deletions src/docparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,37 +300,52 @@ class DocURL : public DocNode
class DocLineBreak : public DocNode
{
public:
DocLineBreak(DocNode *parent) { m_parent=parent; }
DocLineBreak(DocNode *parent) { m_parent = parent; }
DocLineBreak(DocNode *parent,const HtmlAttribList &attribs)
: m_attribs(attribs) { m_parent = parent; }
Kind kind() const { return Kind_LineBreak; }
void accept(DocVisitor *v) { v->visit(this); }

const HtmlAttribList &attribs() const { return m_attribs; }

private:
HtmlAttribList m_attribs;
};

/** Node representing a horizontal ruler */
class DocHorRuler : public DocNode
{
public:
DocHorRuler(DocNode *parent) { m_parent = parent; }
DocHorRuler(DocNode *parent,const HtmlAttribList &attribs)
: m_attribs(attribs) { m_parent = parent; }
Kind kind() const { return Kind_HorRuler; }
void accept(DocVisitor *v) { v->visit(this); }

const HtmlAttribList &attribs() const { return m_attribs; }

private:
HtmlAttribList m_attribs;
};

/** Node representing an anchor */
class DocAnchor : public DocNode
{
public:
DocAnchor(DocNode *parent,const QCString &id,bool newAnchor);
DocAnchor(DocNode *parent,const QCString &id,bool newAnchor){docAnchorInit(parent,id,newAnchor);}
DocAnchor(DocNode *parent,const QCString &id,bool newAnchor,const HtmlAttribList &attribs) : m_attribs(attribs)
{docAnchorInit(parent,id,newAnchor);}
Kind kind() const { return Kind_Anchor; }
QCString anchor() const { return m_anchor; }
QCString file() const { return m_file; }
void accept(DocVisitor *v) { v->visit(this); }

const HtmlAttribList &attribs() const { return m_attribs; }

private:
QCString m_anchor;
QCString m_file;
HtmlAttribList m_attribs;
void docAnchorInit(DocNode *parent,const QCString &id,bool newAnchor);
};

/** Node representing a citation of some bibliographic reference */
Expand Down Expand Up @@ -1199,11 +1214,13 @@ class DocPara : public CompAccept<DocPara>
int handleHtmlHeader(const HtmlAttribList &tagHtmlAttribs,int level);

bool injectToken(int tok,const QCString &tokText);
const HtmlAttribList &attribs() const { return m_attribs; }

private:
QCString m_sectionId;
bool m_isFirst;
bool m_isLast;
HtmlAttribList m_attribs;
};

/** Node representing a parameter list. */
Expand Down
16 changes: 9 additions & 7 deletions src/htmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,17 @@ void HtmlDocVisitor::visit(DocURL *u)
}
}

void HtmlDocVisitor::visit(DocLineBreak *)
void HtmlDocVisitor::visit(DocLineBreak *br)
{
if (m_hide) return;
m_t << "<br />\n";
m_t << "<br "<< htmlAttribsToString(br->attribs()) << " />\n";
}

void HtmlDocVisitor::visit(DocHorRuler *hr)
{
if (m_hide) return;
forceEndParagraph(hr);
m_t << "<hr/>\n";
m_t << "<hr "<< htmlAttribsToString(hr->attribs()) << " />\n";
forceStartParagraph(hr);
}

Expand Down Expand Up @@ -614,7 +614,7 @@ void HtmlDocVisitor::visit(DocVerbatim *s)
void HtmlDocVisitor::visit(DocAnchor *anc)
{
if (m_hide) return;
m_t << "<a class=\"anchor\" id=\"" << anc->anchor() << "\"></a>";
m_t << "<a class=\"anchor\" id=\"" << anc->anchor() << "\"" << htmlAttribsToString(anc->attribs()) << "></a>";
}

void HtmlDocVisitor::visit(DocInclude *inc)
Expand Down Expand Up @@ -1206,9 +1206,9 @@ void HtmlDocVisitor::visitPre(DocPara *p)
//printf(" needsTag=%d\n",needsTag);
// write the paragraph tag (if needed)
if (needsTag)
m_t << "<p" << getDirHtmlClassOfNode(getTextDirByConfig(p), contexts[t]) << ">";
m_t << "<p" << getDirHtmlClassOfNode(getTextDirByConfig(p), contexts[t]) << htmlAttribsToString(p->attribs()) << ">";
else if(!paragraphAlreadyStarted)
m_t << getHtmlDirEmbedingChar(getTextDirByConfig(p));
m_t << getHtmlDirEmbedingChar(getTextDirByConfig(p)) << htmlAttribsToString(p->attribs());
}

void HtmlDocVisitor::visitPost(DocPara *p)
Expand Down Expand Up @@ -1492,7 +1492,9 @@ void HtmlDocVisitor::visitPre(DocHtmlTable *t)

if (t->hasCaption())
{
m_t << "<a class=\"anchor\" id=\"" << t->caption()->anchor() << "\"></a>\n";
QCString anc = t->caption()->anchor();
if (!anc.isEmpty())
m_t << "<a class=\"anchor\" id=\"" << anc << "\"></a>\n";
}

QString attrs = htmlAttribsToString(t->attribs());
Expand Down
2 changes: 1 addition & 1 deletion src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -6732,7 +6732,7 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
}
<DocCopyBlock><<EOF>> {
warn(yyFileName,yyLineNr,
"reached end of file while inside a %s block!\n"
"reached end of file while inside a `%s' block!\n"
"The command that should end the block seems to be missing!\n",
docBlockName.data());
yyterminate();
Expand Down

0 comments on commit 64ac364

Please sign in to comment.