However, the DRY principals are being screwed around with like they don't exist. Some better architecture needs to be implemented. But that will take place after block code nodes and anchor tags are implemented. I will remain on this branch for those other implementations, for now.
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#include "structureNode.h"
|
|
#include <cstdio>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
using std::string;
|
|
|
|
string DocumentNode::ToHtml() const {
|
|
std::stringstream ss;
|
|
ss << "<!DOCTYPE html>\n\t<html lang=\"en\">\n\t\t<head>\n\t\t\t<meta "
|
|
"charset=\"UTF-8\">\n\t\t\t<meta "
|
|
"name=\"viewport\" content=\"width=device-width, "
|
|
"initial-scale=1.0\">\n\t\t\t<title>Document</title>\n\t\t</"
|
|
"head>\n\t<body>\n";
|
|
|
|
for (const auto &child : this->GetChilren()) {
|
|
ss << child->ToHtml();
|
|
}
|
|
|
|
ss << "\n\t</body>\n</html>";
|
|
return ss.str();
|
|
}
|
|
|
|
HeadingNode::HeadingNode(int size) {
|
|
if (1 <= size && size <= 6) {
|
|
this->size = size;
|
|
return;
|
|
}
|
|
|
|
throw std::runtime_error("HeadingNode.size must be between 1 and 6.");
|
|
}
|
|
|
|
string HeadingNode::ToHtml() const {
|
|
std::stringstream ss;
|
|
ss << "<h" << size << ">";
|
|
|
|
for (const auto &child : this->GetChilren()) {
|
|
ss << child->ToHtml();
|
|
}
|
|
|
|
ss << "</h" << size << ">\n";
|
|
return ss.str();
|
|
}
|
|
|
|
string ParagraphNode::ToHtml() const {
|
|
std::stringstream ss;
|
|
ss << "<p>";
|
|
|
|
for (const auto &child : this->GetChilren()) {
|
|
ss << child->ToHtml();
|
|
}
|
|
|
|
ss << "</p>\n";
|
|
return ss.str();
|
|
}
|
|
|
|
string ListNode::ToHtml() const {
|
|
std::stringstream ss;
|
|
|
|
ss << (this->ordered ? "<ol>" : "<ul>") << "\n";
|
|
|
|
for (const auto &child : this->GetChilren()) {
|
|
ss << "<li>" << child->ToHtml() << "</li>" << "\n";
|
|
}
|
|
|
|
ss << (this->ordered ? "</ol>" : "</ul>") << "\n";
|
|
return ss.str();
|
|
}
|