Add Non_Opened to Type enum. It can be used if you want an element that

is only closed.
This commit is contained in:
Jacob 2024-05-25 21:48:13 +02:00
parent 2067aaace3
commit 9d30189d31
3 changed files with 14 additions and 4 deletions

View file

@ -205,9 +205,10 @@ namespace docpp {
* @brief Enum for element types.
*/
enum class Type {
Self_Closing, /* Self-closing element (<tag></tag>)*/
Non_Self_Closing, /* Non-self-closing element (<tag>) */
Self_Closing, /* Self-closing element (<tag ... />)*/
Non_Self_Closing, /* Non-self-closing element (<tag></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, /* Text element with tab characters appropriately prepended (my text here). Note that this does *not* append a newline character. */
};

View file

@ -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()) {
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() + "\"";
}
if (this->type != docpp::HTML::Type::Self_Closing) {
if (this->type != docpp::HTML::Type::Self_Closing && this->type != docpp::HTML::Type::Non_Opened) {
ret += ">";
}
@ -312,6 +316,8 @@ std::string docpp::HTML::Element::get(const Formatting formatting, const int tab
ret += this->data + "</" + this->tag + ">";
} else if (this->type == docpp::HTML::Type::Self_Closing) {
ret += this->data + "/>";
} else if (this->type == docpp::HTML::Type::Non_Opened) {
ret += ">";
}
if (formatting == docpp::HTML::Formatting::Pretty || formatting == docpp::HTML::Formatting::Newline) {

View file

@ -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::Pretty) == "<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();