Add Non_Opened to Type enum. It can be used if you want an element that
is only closed.
This commit is contained in:
parent
2067aaace3
commit
9d30189d31
|
@ -205,9 +205,10 @@ namespace docpp {
|
||||||
* @brief Enum for element types.
|
* @brief Enum for element types.
|
||||||
*/
|
*/
|
||||||
enum class Type {
|
enum class Type {
|
||||||
Self_Closing, /* Self-closing element (<tag></tag>)*/
|
Self_Closing, /* Self-closing element (<tag ... />)*/
|
||||||
Non_Self_Closing, /* Non-self-closing element (<tag>) */
|
Non_Self_Closing, /* Non-self-closing element (<tag></tag>) */
|
||||||
Non_Closed, /* Non-closed element (<tag>) */
|
Non_Closed, /* Non-closed element (<tag>) */
|
||||||
|
Non_Opened, /* Non-opened element (</tag>) */
|
||||||
Text_No_Formatting, /* Text element with no formatting (my text here). */
|
Text_No_Formatting, /* Text element with no formatting (my text here). */
|
||||||
Text, /* Text element with tab characters appropriately prepended (my text here). Note that this does *not* append a newline character. */
|
Text, /* Text element with tab characters appropriately prepended (my text here). Note that this does *not* append a newline character. */
|
||||||
};
|
};
|
||||||
|
|
|
@ -295,7 +295,11 @@ std::string docpp::HTML::Element::get(const Formatting formatting, const int tab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += "<" + this->tag;
|
if (this->type == docpp::HTML::Type::Non_Opened) {
|
||||||
|
ret += "</" + this->tag;
|
||||||
|
} else {
|
||||||
|
ret += "<" + this->tag;
|
||||||
|
}
|
||||||
|
|
||||||
for (const Property& it : this->properties.get_properties()) {
|
for (const Property& it : this->properties.get_properties()) {
|
||||||
if (!it.get_key().compare("")) continue;
|
if (!it.get_key().compare("")) continue;
|
||||||
|
@ -304,7 +308,7 @@ std::string docpp::HTML::Element::get(const Formatting formatting, const int tab
|
||||||
ret += " " + it.get_key() + "=\"" + it.get_value() + "\"";
|
ret += " " + it.get_key() + "=\"" + it.get_value() + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->type != docpp::HTML::Type::Self_Closing) {
|
if (this->type != docpp::HTML::Type::Self_Closing && this->type != docpp::HTML::Type::Non_Opened) {
|
||||||
ret += ">";
|
ret += ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,6 +316,8 @@ std::string docpp::HTML::Element::get(const Formatting formatting, const int tab
|
||||||
ret += this->data + "</" + this->tag + ">";
|
ret += this->data + "</" + this->tag + ">";
|
||||||
} else if (this->type == docpp::HTML::Type::Self_Closing) {
|
} else if (this->type == docpp::HTML::Type::Self_Closing) {
|
||||||
ret += this->data + "/>";
|
ret += this->data + "/>";
|
||||||
|
} else if (this->type == docpp::HTML::Type::Non_Opened) {
|
||||||
|
ret += ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formatting == docpp::HTML::Formatting::Pretty || formatting == docpp::HTML::Formatting::Newline) {
|
if (formatting == docpp::HTML::Formatting::Pretty || formatting == docpp::HTML::Formatting::Newline) {
|
||||||
|
|
|
@ -634,6 +634,9 @@ inline namespace HTML {
|
||||||
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::None) == "<h1>data</h1>");
|
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::None) == "<h1>data</h1>");
|
||||||
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::Pretty) == "<h1>data</h1>\n");
|
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::Pretty) == "<h1>data</h1>\n");
|
||||||
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::Newline) == "<h1>data</h1>\n");
|
REQUIRE(element.get<std::string>(docpp::HTML::Formatting::Newline) == "<h1>data</h1>\n");
|
||||||
|
|
||||||
|
element.set_type(docpp::HTML::Type::Non_Opened);
|
||||||
|
REQUIRE(element.get<std::string>() == "</h1>");
|
||||||
};
|
};
|
||||||
|
|
||||||
test_get_and_set();
|
test_get_and_set();
|
||||||
|
|
Loading…
Reference in a new issue