Compare commits

..

No commits in common. "1ede2cc2be3670d9f2daa3903e7f17905cc0811b" and "8c60ba236142898202287417809b0350b203e1d3" have entirely different histories.

4 changed files with 12 additions and 27 deletions

View File

@ -19,8 +19,3 @@ void Node::Inspect(int indent) {
child->Inspect(indent + 1); child->Inspect(indent + 1);
} }
} }
std::ostream &operator<<(std::ostream &os, Node const &node) {
os << node.ToHtml();
return os;
}

View File

@ -19,23 +19,12 @@
/// Reference: https://www.youtube.com/watch?v=AmjoK55h68Y&t=166s /// Reference: https://www.youtube.com/watch?v=AmjoK55h68Y&t=166s
class Node { class Node {
/**
* @brief Override the '<<' operator to write the content of the node
* directly.
*
* This overridden operator will simply write the result of this->ToHtml to
* the stream.
*
* @author Hayden Hargreaves (hhargreaves2006@gmail.com)
*/
friend std::ostream &operator<<(std::ostream &os, Node const &node);
protected: protected:
/** /**
* @brief List of children nodes. * @brief List of children nodes.
* *
* Most nodes will not have children, but some may, therefore this class * Most nodes will not have children, but some may, therefore this class must
* must have it. * have it.
* *
* @author Hayden Hargreaves (hhargreaves2006@gmail.com) * @author Hayden Hargreaves (hhargreaves2006@gmail.com)
*/ */
@ -69,8 +58,8 @@ public:
/** /**
* @brief Return a read-only (const) list of children. * @brief Return a read-only (const) list of children.
* *
* Return our list of unique ptrs, they are const and therefore only have * Return our list of unique ptrs, they are const and therefore only have read
* read access. * access.
* *
* @author Hayden Hargreaves (hhargreaves2006@gmail.com) * @author Hayden Hargreaves (hhargreaves2006@gmail.com)
*/ */

View File

@ -15,7 +15,7 @@ string DocumentNode::ToHtml() const {
"head>\n\t<body>\n"; "head>\n\t<body>\n";
for (const auto &child : this->GetChilren()) { for (const auto &child : this->GetChilren()) {
ss << *child; ss << child->ToHtml();
} }
ss << "\n\t</body>\n</html>"; ss << "\n\t</body>\n</html>";
@ -36,7 +36,7 @@ string HeadingNode::ToHtml() const {
ss << "<h" << size << ">"; ss << "<h" << size << ">";
for (const auto &child : this->GetChilren()) { for (const auto &child : this->GetChilren()) {
ss << *child; ss << child->ToHtml();
} }
ss << "</h" << size << ">\n"; ss << "</h" << size << ">\n";
@ -48,7 +48,7 @@ string ParagraphNode::ToHtml() const {
ss << "<p>"; ss << "<p>";
for (const auto &child : this->GetChilren()) { for (const auto &child : this->GetChilren()) {
ss << *child; ss << child->ToHtml();
} }
ss << "</p>\n"; ss << "</p>\n";
@ -61,7 +61,7 @@ string ListNode::ToHtml() const {
ss << (this->ordered ? "<ol>" : "<ul>") << "\n"; ss << (this->ordered ? "<ol>" : "<ul>") << "\n";
for (const auto &child : this->GetChilren()) { for (const auto &child : this->GetChilren()) {
ss << "<li>" << *child << "</li>" << "\n"; ss << "<li>" << child->ToHtml() << "</li>" << "\n";
} }
ss << (this->ordered ? "</ol>" : "</ul>") << "\n"; ss << (this->ordered ? "</ol>" : "</ul>") << "\n";
@ -74,7 +74,7 @@ string CodeBlockNode::ToHtml() const {
ss << "<code>\n"; ss << "<code>\n";
for (const auto &child : this->GetChilren()) { for (const auto &child : this->GetChilren()) {
ss << *child << "\n"; ss << child->ToHtml() << "\n";
} }
ss << "</code>\n"; ss << "</code>\n";

View File

@ -33,7 +33,7 @@ void test_nodes() {
root.AddChild(std::move(para)); root.AddChild(std::move(para));
root.AddChild(std::move(list)); root.AddChild(std::move(list));
std::cout << root << std::endl; std::cout << root.ToHtml() << std::endl;
} }
/** /**
@ -72,4 +72,5 @@ void test_document_converter() {
dc.ConvertWatcher(); dc.ConvertWatcher();
} }
int main(int argc, char **argv) { test_document_converter(); } int main(int argc, char **argv) {
test_document_converter(); }