/* * This project is licensed under the MIT license. For more information see the * LICENSE file. */ #pragma once // ----------------------------------------------------------------------------- #include #include #include "blockparser.h" // ----------------------------------------------------------------------------- namespace maddy { // ----------------------------------------------------------------------------- /** * ParagraphParser * * @class */ class ParagraphParser : public BlockParser { public: /** * ctor * * @method * @param {std::function} parseLineCallback * @param {std::function(const std::string& line)>} getBlockParserForLineCallback */ ParagraphParser( std::function aParseLineCallback, std::function(const std::string& line)> aGetBlockParserForLineCallback ) : BlockParser( aParseLineCallback, aGetBlockParserForLineCallback ), isStarted( false ), isFinished( false ) {} /** * IsStartingLine * * If the line is not empty, it will be a paragraph. So this block parser has * to always run as the last one! * * @method * @param {const std::string&} line * @return {bool} */ static bool IsStartingLine( const std::string& line ) { return !line.empty(); } /** * IsFinished * * An empty line will end the paragraph. * * @method * @return {bool} */ bool IsFinished() const override { return this->isFinished; } protected: bool isInlineBlockAllowed() const override { return false; } bool isLineParserAllowed() const override { return true; } void parseBlock( std::string& line ) override { if( !this->isStarted ) { line = "

" + line + " "; this->isStarted = true; return; } if( line.empty() ) { line += "

"; this->isFinished = true; return; } line += " "; } private: bool isStarted; bool isFinished; }; // class ParagraphParser // ----------------------------------------------------------------------------- } // namespace maddy