Skip to content

Commit

Permalink
Multiple use of HTML attributes
Browse files Browse the repository at this point in the history
In case an attribute is used multiple times the XHTML validator gives (here for the style attribute):
    parser error : Attribute style redefined
Created routine to merge these types of attributes.
  • Loading branch information
albert-github committed Feb 28, 2019
1 parent 7c8994e commit a735007
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/htmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,34 @@ static bool isInvisibleNode(DocNode *node)
;
}

static void mergeHtmlAttributes(const HtmlAttribList &attribs, HtmlAttribList *mergeInto)
{
HtmlAttribListIterator li(attribs);
HtmlAttrib *att;
for (li.toFirst();(att=li.current());++li)
{
HtmlAttribListIterator ml(*mergeInto);
HtmlAttrib *opt;
bool found = false;
for (ml.toFirst();(opt=ml.current());++ml)
{
if (opt->name == att -> name)
{
found = true;
break;
}
}
if (found)
{
opt->value = opt->value + " " + att->value;
}
else
{
mergeInto->append(att);
}
}
}

static QCString htmlAttribsToString(const HtmlAttribList &attribs, QCString *pAltValue = 0)
{
QCString result;
Expand Down Expand Up @@ -1651,8 +1679,18 @@ void HtmlDocVisitor::visitPre(DocImage *img)
sizeAttribs+=" height=\""+img->height()+"\"";
}
// 16 cases: url.isEmpty() | typeSVG | inlineImage | img->hasCaption()

HtmlAttribList extraAttribs;
if (typeSVG)
{
HtmlAttrib opt;
opt.name = "style";
opt.value = "pointer-events: none;";
extraAttribs.append(&opt);
}
QCString alt;
QCString attrs = htmlAttribsToString(img->attribs(),&alt);
mergeHtmlAttributes(img->attribs(),&extraAttribs);
QCString attrs = htmlAttribsToString(extraAttribs,&alt);
QCString src;
if (url.isEmpty())
{
Expand All @@ -1664,7 +1702,7 @@ void HtmlDocVisitor::visitPre(DocImage *img)
}
if (typeSVG)
{
m_t << "<object type=\"image/svg+xml\" style=\"pointer-events: none;\" data=\"" << src
m_t << "<object type=\"image/svg+xml\" data=\"" << src
<< "\"" << sizeAttribs << attrs;
if (inlineImage)
{
Expand Down

0 comments on commit a735007

Please sign in to comment.