Skip to content

Commit 8007b6c

Browse files
committed
Merge branch 'albert-github-feature/issue_11240'
2 parents 1524236 + 1ff8ad0 commit 8007b6c

File tree

3 files changed

+127
-113
lines changed

3 files changed

+127
-113
lines changed

src/doctokenizer.l

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,8 @@ static void handleHtmlTag(yyscan_t yyscanner,const char *text)
16401640
// search for end of name
16411641
while (i<(int)yyleng && !isspace((uint8_t)c) && c!='=' && c!= '>') { c=tagText.at(++i); }
16421642
int endName=i;
1643-
HtmlAttrib opt;
1644-
opt.name = tagText.mid(startName,endName-startName).lower();
1643+
QCString optName,optValue;
1644+
optName = tagText.mid(startName,endName-startName).lower();
16451645
// skip spaces
16461646
while (i<(int)yyleng && isspace((uint8_t)c)) { c=tagText.at(++i); }
16471647
if (tagText.at(i)=='=') // option has value
@@ -1677,20 +1677,20 @@ static void handleHtmlTag(yyscan_t yyscanner,const char *text)
16771677
endAttrib=i;
16781678
if (i<(int)yyleng) { c=tagText.at(++i);}
16791679
}
1680-
opt.value = tagText.mid(startAttrib,endAttrib-startAttrib);
1681-
if (opt.name == "align") opt.value = opt.value.lower();
1682-
else if (opt.name == "valign")
1680+
optValue = tagText.mid(startAttrib,endAttrib-startAttrib);
1681+
if (optName == "align") optValue = optValue.lower();
1682+
else if (optName == "valign")
16831683
{
1684-
opt.value = opt.value.lower();
1685-
if (opt.value == "center") opt.value="middle";
1684+
optValue = optValue.lower();
1685+
if (optValue == "center") optValue="middle";
16861686
}
16871687
}
16881688
else // start next option
16891689
{
16901690
}
16911691
//printf("=====> Adding option name=<%s> value=<%s>\n",
1692-
// qPrint(opt.name),qPrint(opt.value));
1693-
yyextra->token.attribs.push_back(opt);
1692+
// qPrint(optName),qPrint(optValue));
1693+
yyextra->token.attribs.emplace_back(optName,optValue);
16941694
}
16951695
yyextra->token.attribsStr = tagText.mid(startAttribList,i-startAttribList);
16961696
}

src/htmlattrib.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,69 @@
1818
#include <vector>
1919

2020
#include "qcstring.h"
21+
#include "util.h"
2122

2223
/*! \brief Class representing a HTML attribute. */
2324
struct HtmlAttrib
2425
{
26+
HtmlAttrib(const QCString &n,const QCString &v) : name(n), value(v) {}
2527
QCString name;
2628
QCString value;
2729
};
2830

2931
/*! \brief Class representing a list of HTML attributes. */
3032
class HtmlAttribList : public std::vector<HtmlAttrib>
3133
{
34+
public:
35+
void mergeAttribute(const QCString &optName,const QCString &optValue)
36+
{
37+
auto it = std::find_if(begin(),end(),
38+
[&optName](const auto &opt) { return opt.name==optName; });
39+
if (it!=end()) // attribute name already in the list: append values
40+
{
41+
it->value += " " + optValue;
42+
}
43+
else // attribute name not yet in the list
44+
{
45+
emplace_back(optName,optValue);
46+
}
47+
}
48+
49+
QCString toString(QCString *pAltValue = nullptr) const
50+
{
51+
QCString result;
52+
for (const auto &att : *this)
53+
{
54+
if (!att.value.isEmpty()) // ignore attribute without values as they
55+
// are not XHTML compliant, with the exception
56+
// of the alt attribute with the img tag
57+
{
58+
if (att.name=="alt" && pAltValue) // optionally return the value of alt separately
59+
// need to convert <img> to <object> for SVG images,
60+
// which do not support the alt attribute
61+
{
62+
*pAltValue = att.value;
63+
}
64+
else
65+
{
66+
result+=" "+att.name+"=\""+convertToXML(att.value)+"\"";
67+
}
68+
}
69+
else if (att.name=="open")
70+
{
71+
// The open attribute is a boolean attribute.
72+
// Specifies that the details should be visible (open) to the user
73+
// As it is a boolean attribute the initialization value is of no interest
74+
result+=" "+att.name+"=\"true\"";
75+
}
76+
else if (att.name=="nowrap") // In XHTML, attribute minimization is forbidden, and the nowrap attribute must be defined as <td nowrap="nowrap">.
77+
{
78+
result+=" "+att.name+"=\"nowrap\"";
79+
}
80+
}
81+
return result;
82+
}
83+
3284
};
3385

3486
#endif

0 commit comments

Comments
 (0)