diff --git a/.github/ISSUE_TEMPLATE/cpp-bug-report.yml b/.github/ISSUE_TEMPLATE/cpp-bug-report.yml index 1e0b607..5e1c797 100644 --- a/.github/ISSUE_TEMPLATE/cpp-bug-report.yml +++ b/.github/ISSUE_TEMPLATE/cpp-bug-report.yml @@ -37,7 +37,9 @@ body: label: maddy version description: What version of maddy are you using? options: - - 1.2.0 (latest) + - 1.3.0 (latest) + - 1.2.1 + - 1.2.0 - 1.1.2 - 1.1.1 - 1.1.0 diff --git a/.github/ISSUE_TEMPLATE/markdown-bug-report.yml b/.github/ISSUE_TEMPLATE/markdown-bug-report.yml index 2642ff1..0da6e19 100644 --- a/.github/ISSUE_TEMPLATE/markdown-bug-report.yml +++ b/.github/ISSUE_TEMPLATE/markdown-bug-report.yml @@ -37,7 +37,9 @@ body: label: maddy version description: What version of maddy are you using? options: - - 1.2.0 (latest) + - 1.3.0 (latest) + - 1.2.1 + - 1.2.0 - 1.1.2 - 1.1.1 - 1.1.0 @@ -51,7 +53,7 @@ body: id: example attributes: label: Minimal Mardown example - description: To be able to reproduce your issue, please give some example Markdown which creates problems. + description: To be able to reproduce your issue, please give some example Markdown which creates problems. Please indent the Markdown by 4 spaces. validations: required: true - type: textarea diff --git a/.github/ISSUE_TEMPLATE/other.yml b/.github/ISSUE_TEMPLATE/other.yml new file mode 100644 index 0000000..3d9c65a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other.yml @@ -0,0 +1,11 @@ +name: Other +description: Anything that doesn't fit into one of the other issue categories +title: "" +body: + - type: textarea + id: whats-up + attributes: + label: What is the issue? + description: Is some tooling not working? Performance issues? ... + validations: + required: true diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a95f2e2..939b481 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,9 +4,11 @@ on: push: branches: - master + - dev pull_request: branches: - master + - dev jobs: test-on-ubuntu: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index f330323..b30d063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ maddy uses [semver versioning](https://semver.org/). * ? +## version 1.3.0 2023-08-26 + +* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Headlines can have inline parsing now. It is on by default, but can be disabled by config. + ## version 1.2.1 2023-08-06 * ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Parser.h version() method clashing with VERSION defines at global scope diff --git a/README.md b/README.md index 177cabc..62fb8ff 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # maddy [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -[![Version: 1.2.1](https://img.shields.io/badge/Version-1.2.1-brightgreen.svg)](https://semver.org/) +[![Version: 1.3.0](https://img.shields.io/badge/Version-1.3.0-brightgreen.svg)](https://semver.org/) maddy is a C++ Markdown to HTML **header-only** parser library. diff --git a/include/maddy/headlineparser.h b/include/maddy/headlineparser.h index 9eafec5..7b25d55 100644 --- a/include/maddy/headlineparser.h +++ b/include/maddy/headlineparser.h @@ -57,9 +57,11 @@ public: */ HeadlineParser( std::function parseLineCallback, - std::function(const std::string& line)> getBlockParserForLineCallback + std::function(const std::string& line)> getBlockParserForLineCallback, + bool isInlineParserAllowed = true ) : BlockParser(parseLineCallback, getBlockParserForLineCallback) + , isInlineParserAllowed(isInlineParserAllowed) {} /** @@ -103,7 +105,7 @@ protected: bool isLineParserAllowed() const override { - return false; + return this->isInlineParserAllowed; } void @@ -131,6 +133,9 @@ protected: line = std::regex_replace(line, hlRegex[i], hlReplacement[i]); } } + +private: + bool isInlineParserAllowed; }; // class HeadlineParser // ----------------------------------------------------------------------------- diff --git a/include/maddy/parser.h b/include/maddy/parser.h index 7d9b48b..aeb349d 100644 --- a/include/maddy/parser.h +++ b/include/maddy/parser.h @@ -57,7 +57,7 @@ public: * Check https://github.com/progsource/maddy/blob/master/CHANGELOG.md * for the changelog. */ - static const std::string& version() { static const std::string v = "1.2.1"; return v; } + static const std::string& version() { static const std::string v = "1.3.0"; return v; } /** * ctor @@ -287,10 +287,22 @@ private: maddy::HeadlineParser::IsStartingLine(line) ) { - parser = std::make_shared( - nullptr, - nullptr - ); + if (!this->config || this->config->isHeadlineInlineParsingEnabled) + { + parser = std::make_shared( + [this](std::string& line){ this->runLineParser(line); }, + nullptr, + true + ); + } + else + { + parser = std::make_shared( + nullptr, + nullptr, + false + ); + } } else if ( ( diff --git a/include/maddy/parserconfig.h b/include/maddy/parserconfig.h index cb1171a..a5469a2 100644 --- a/include/maddy/parserconfig.h +++ b/include/maddy/parserconfig.h @@ -70,11 +70,22 @@ struct ParserConfig */ bool isHTMLWrappedInParagraph; + /** + * en-/disable headline inline-parsing + * + * default: enabled + */ + bool isHeadlineInlineParsingEnabled; + + /** + * enabled parsers bitfield + */ uint32_t enabledParsers; ParserConfig() : isEmphasizedParserEnabled(true) , isHTMLWrappedInParagraph(true) + , isHeadlineInlineParsingEnabled(true) , enabledParsers(maddy::types::DEFAULT) {} }; // class ParserConfig diff --git a/tests/maddy/test_maddy_parser.cpp b/tests/maddy/test_maddy_parser.cpp index f69f44c..112189e 100644 --- a/tests/maddy/test_maddy_parser.cpp +++ b/tests/maddy/test_maddy_parser.cpp @@ -64,3 +64,34 @@ TEST(MADDY_PARSER, ItShouldParseWithSmallConfig) ASSERT_EQ(testHtml3, output); } + +TEST(MADDY_PARSER, ItShouldParseInlineCodeInHeadlines) +{ + const std::string headlineTest = R"( +# Some **test** markdown +)"; + const std::string expectedHTML = "

Some test markdown

"; + std::stringstream markdown(headlineTest); + + auto parser = std::make_shared(); + + const std::string output = parser->Parse(markdown); + + ASSERT_EQ(expectedHTML, output); +} + +TEST(MADDY_PARSER, ItShouldNotParseInlineCodeInHeadlineIfDisabled) +{ + const std::string headlineTest = R"( +# Some **test** markdown +)"; + const std::string expectedHTML = "

Some **test** markdown

"; + std::stringstream markdown(headlineTest); + auto config = std::make_shared(); + config->isHeadlineInlineParsingEnabled = false; + auto parser = std::make_shared(config); + + const std::string output = parser->Parse(markdown); + + ASSERT_EQ(expectedHTML, output); +}