#ifndef INLINENODE_H #define INLINENODE_H #include "node.h" #include #include /** * @desc ABC inline node for textual nodes. * * An inline node has content, but no children. An attempt to add children to * this node will result in a runtime exception. * Inline nodes define text itself, not textual tags, but the actual text inside * the tags. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class InlineNode : public Node { public: InlineNode(std::string content) : content(content) {}; /** * @brief Return node as HTML string. * * This method is virtual and required to be overridden. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ virtual std::string ToHtml() const = 0; /** * @brief Cannot add a child to this class. * * This method simply returns a runtime error, since there is no reason to add * a child to a textual node. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ void AddChild(std::unique_ptr child); /** * @brief Is the node empty. * * This is the same as checking if the nodes content is empty. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ bool IsEmpty() const { return this->content.empty(); }; protected: std::string content; }; /** * @desc A raw textual node. * * This node is simple, it simple returns it's content with no formatting. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class TextNode : public InlineNode { public: TextNode(std::string content) : InlineNode(content) {}; std::string ToHtml() const; }; /** * @desc A italic textual node. * * This node returns it's content wrapped with tags. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class ItalicNode : public InlineNode { public: ItalicNode(std::string content) : InlineNode(content) {}; std::string ToHtml() const; }; /** * @desc A bold textual node. * * This node returns it's content wrapped with tags. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class BoldNode : public InlineNode { public: BoldNode(std::string content) : InlineNode(content) {}; std::string ToHtml() const; }; /** * @desc A bold and italic textual node. * * This node returns it's content wrapped with AND / * tags. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class BoldItalicNode : public InlineNode { public: BoldItalicNode(std::string content) : InlineNode(content) {}; std::string ToHtml() const; }; /** * @desc An inline code block node. * * This node returns it's content wrapped with tags. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class CodeNode : public InlineNode { public: CodeNode(std::string content) : InlineNode(content) {}; std::string ToHtml() const; }; /** * @desc An anchor/link container node. * * This node is used to create an inline anchor tag. This node returns the * following {content}. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ class LinkNode : public InlineNode { protected: std::string link; public: LinkNode(std::string link, std::string content) : InlineNode(content), link(link) {}; std::string ToHtml() const; }; #endif