Merge pull request #48 from progsource/headline-inline-parsing

Headline inline parsing
This commit is contained in:
Petra Baranski
2023-08-26 13:11:04 +02:00
committed by GitHub
6 changed files with 78 additions and 6 deletions

11
.github/ISSUE_TEMPLATE/other.yml vendored Normal file
View File

@@ -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

View File

@@ -4,9 +4,11 @@ on:
push: push:
branches: branches:
- master - master
- dev
pull_request: pull_request:
branches: branches:
- master - master
- dev
jobs: jobs:
test-on-ubuntu: test-on-ubuntu:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@@ -57,9 +57,11 @@ public:
*/ */
HeadlineParser( HeadlineParser(
std::function<void(std::string&)> parseLineCallback, std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback,
bool isInlineParserAllowed = true
) )
: BlockParser(parseLineCallback, getBlockParserForLineCallback) : BlockParser(parseLineCallback, getBlockParserForLineCallback)
, isInlineParserAllowed(isInlineParserAllowed)
{} {}
/** /**
@@ -103,7 +105,7 @@ protected:
bool bool
isLineParserAllowed() const override isLineParserAllowed() const override
{ {
return false; return this->isInlineParserAllowed;
} }
void void
@@ -131,6 +133,9 @@ protected:
line = std::regex_replace(line, hlRegex[i], hlReplacement[i]); line = std::regex_replace(line, hlRegex[i], hlReplacement[i]);
} }
} }
private:
bool isInlineParserAllowed;
}; // class HeadlineParser }; // class HeadlineParser
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -287,10 +287,22 @@ private:
maddy::HeadlineParser::IsStartingLine(line) maddy::HeadlineParser::IsStartingLine(line)
) )
{ {
parser = std::make_shared<maddy::HeadlineParser>( if (!this->config || this->config->isHeadlineInlineParsingEnabled)
nullptr, {
nullptr parser = std::make_shared<maddy::HeadlineParser>(
); [this](std::string& line){ this->runLineParser(line); },
nullptr,
true
);
}
else
{
parser = std::make_shared<maddy::HeadlineParser>(
nullptr,
nullptr,
false
);
}
} }
else if ( else if (
( (

View File

@@ -70,11 +70,22 @@ struct ParserConfig
*/ */
bool isHTMLWrappedInParagraph; bool isHTMLWrappedInParagraph;
/**
* en-/disable headline inline-parsing
*
* default: enabled
*/
bool isHeadlineInlineParsingEnabled;
/**
* enabled parsers bitfield
*/
uint32_t enabledParsers; uint32_t enabledParsers;
ParserConfig() ParserConfig()
: isEmphasizedParserEnabled(true) : isEmphasizedParserEnabled(true)
, isHTMLWrappedInParagraph(true) , isHTMLWrappedInParagraph(true)
, isHeadlineInlineParsingEnabled(true)
, enabledParsers(maddy::types::DEFAULT) , enabledParsers(maddy::types::DEFAULT)
{} {}
}; // class ParserConfig }; // class ParserConfig

View File

@@ -64,3 +64,34 @@ TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
ASSERT_EQ(testHtml3, output); ASSERT_EQ(testHtml3, output);
} }
TEST(MADDY_PARSER, ItShouldParseInlineCodeInHeadlines)
{
const std::string headlineTest = R"(
# Some **test** markdown
)";
const std::string expectedHTML = "<h1>Some <strong>test</strong> markdown</h1>";
std::stringstream markdown(headlineTest);
auto parser = std::make_shared<maddy::Parser>();
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 = "<h1>Some **test** markdown</h1>";
std::stringstream markdown(headlineTest);
auto config = std::make_shared<maddy::ParserConfig>();
config->isHeadlineInlineParsingEnabled = false;
auto parser = std::make_shared<maddy::Parser>(config);
const std::string output = parser->Parse(markdown);
ASSERT_EQ(expectedHTML, output);
}