Doxygen
Loading...
Searching...
No Matches
HtmlAttribList Class Referencefinal

Class representing a list of HTML attributes. More...

#include <src/htmlattrib.h>

Inheritance diagram for HtmlAttribList:
Collaboration diagram for HtmlAttribList:

Public Member Functions

void mergeAttribute (const DString &optName, const DString &optValue, bool prepend=false)
DString toString (DString *pAltValue=nullptr) const

Detailed Description

Class representing a list of HTML attributes.

Definition at line 30 of file htmlattrib.h.

Member Function Documentation

◆ mergeAttribute()

void HtmlAttribList::mergeAttribute ( const DString & optName,
const DString & optValue,
bool prepend = false )
inline

Definition at line 33 of file htmlattrib.h.

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 if (prepend)
40 {
41 it->value = optValue + " " + it->value;
42 }
43 else
44 {
45 it->value += " " + optValue;
46 }
47 }
48 else // attribute name not yet in the list
49 {
50 emplace_back(optName,optValue);
51 }
52 }
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:176
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:181

References begin(), and end().

Referenced by HtmlDocVisitor::operator()(), and HtmlDocVisitor::operator()().

◆ toString()

DString HtmlAttribList::toString ( DString * pAltValue = nullptr) const
inline

Definition at line 54 of file htmlattrib.h.

55 {
56 DString result;
57 for (const auto &att : *this)
58 {
59 if (!att.value.empty()) // ignore attribute without values as they
60 // are not XHTML compliant, with the exception
61 // of the alt attribute with the img tag
62 {
63 if (att.name=="alt" && pAltValue) // optionally return the value of alt separately
64 // need to convert <img> to <object> for SVG images,
65 // which do not support the alt attribute
66 {
67 *pAltValue = att.value;
68 }
69 else
70 {
71 result+=" "+att.name+"=\""+convertToXML(att.value)+"\"";
72 }
73 }
74 else if (att.name=="open")
75 {
76 // The open attribute is a boolean attribute.
77 // Specifies that the details should be visible (open) to the user
78 // As it is a boolean attribute the initialization value is of no interest
79 result+=" "+att.name+"=\"true\"";
80 }
81 else if (att.name=="nowrap") // In XHTML, attribute minimization is forbidden, and the nowrap attribute must be defined as <td nowrap="nowrap">.
82 {
83 result+=" "+att.name+"=\"nowrap\"";
84 }
85 }
86 return result;
87 }
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3233

References convertToXML().

Referenced by HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), and HtmlDocVisitor::operator()().


The documentation for this class was generated from the following file: