Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
htmlattrib.h
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2026 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
*/
12
13
#ifndef HTMLATTRIB_H
14
#define HTMLATTRIB_H
15
16
#include <vector>
17
18
#include "
dstring.h
"
19
#include "
util.h
"
20
21
/*! \brief Class representing a HTML attribute. */
22
struct
HtmlAttrib
23
{
24
HtmlAttrib
(
const
DString
&n,
const
DString
&v) :
name
(n),
value
(v) {}
25
DString
name
;
26
DString
value
;
27
};
28
29
/*! \brief Class representing a list of HTML attributes. */
30
class
HtmlAttribList
final :
public
std::vector<HtmlAttrib>
31
{
32
public
:
33
void
mergeAttribute
(
const
DString
&optName,
const
DString
&optValue)
34
{
35
auto
it = std::find_if(
begin
(),
end
(),
36
[&optName](
const
auto
&opt) {
return
opt.name==optName; });
37
if
(it!=
end
())
// attribute name already in the list: append values
38
{
39
it->value +=
" "
+ optValue;
40
}
41
else
// attribute name not yet in the list
42
{
43
emplace_back(optName,optValue);
44
}
45
}
46
47
DString
toString
(
DString
*pAltValue =
nullptr
)
const
48
{
49
DString
result;
50
for
(
const
auto
&att : *
this
)
51
{
52
if
(!att.value.empty())
// ignore attribute without values as they
53
// are not XHTML compliant, with the exception
54
// of the alt attribute with the img tag
55
{
56
if
(att.name==
"alt"
&& pAltValue)
// optionally return the value of alt separately
57
// need to convert <img> to <object> for SVG images,
58
// which do not support the alt attribute
59
{
60
*pAltValue = att.value;
61
}
62
else
63
{
64
result+=
" "
+att.name+
"=\""
+
convertToXML
(att.value)+
"\""
;
65
}
66
}
67
else
if
(att.name==
"open"
)
68
{
69
// The open attribute is a boolean attribute.
70
// Specifies that the details should be visible (open) to the user
71
// As it is a boolean attribute the initialization value is of no interest
72
result+=
" "
+att.name+
"=\"true\""
;
73
}
74
else
if
(att.name==
"nowrap"
)
// In XHTML, attribute minimization is forbidden, and the nowrap attribute must be defined as <td nowrap="nowrap">.
75
{
76
result+=
" "
+att.name+
"=\"nowrap\""
;
77
}
78
}
79
return
result;
80
}
81
82
};
83
84
#endif
85
DString
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition
dstring.h:84
HtmlAttribList
Class representing a list of HTML attributes.
Definition
htmlattrib.h:31
HtmlAttribList::mergeAttribute
void mergeAttribute(const DString &optName, const DString &optValue)
Definition
htmlattrib.h:33
HtmlAttribList::toString
DString toString(DString *pAltValue=nullptr) const
Definition
htmlattrib.h:47
begin
DirIterator begin(DirIterator it) noexcept
Definition
dir.cpp:176
end
DirIterator end(const DirIterator &) noexcept
Definition
dir.cpp:181
dstring.h
HtmlAttrib::HtmlAttrib
HtmlAttrib(const DString &n, const DString &v)
Definition
htmlattrib.h:24
HtmlAttrib::value
DString value
Definition
htmlattrib.h:26
HtmlAttrib::name
DString name
Definition
htmlattrib.h:25
convertToXML
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition
util.cpp:3232
util.h
A bunch of utility functions.
src
htmlattrib.h
Generated by
1.19.0