Merge pull request #41 from progsource/codeblock-parser-language-class

Codeblock parser language class
This commit is contained in:
Petra Baranski
2023-07-24 20:40:57 +02:00
committed by GitHub
3 changed files with 34 additions and 1 deletions

View File

@@ -21,6 +21,9 @@ maddy uses [semver versioning](https://semver.org/).
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_BUILD_WITH_TESTS` is on, moved test cmake code to the `tests` subfolder * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_BUILD_WITH_TESTS` is on, moved test cmake code to the `tests` subfolder
* ![**REMOVED**](https://img.shields.io/badge/-REMOVED-%23900) travis CI and appveyor * ![**REMOVED**](https://img.shields.io/badge/-REMOVED-%23900) travis CI and appveyor
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow
* ![**DEPRECATED**](https://img.shields.io/badge/-DEPRECATED-%23666) config flags `isEmphasizedParserEnabled` and `isHTMLWrappedInParagraph`
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) config flag `enabledParsers` to en-/disable each parser separately
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) class attribute to code blocks if there is text after the three backticks like ` ```cpp`
* ? * ?
## version 1.1.2 2020-10-04 ## version 1.1.2 2020-10-04

View File

@@ -74,7 +74,7 @@ public:
static bool static bool
IsStartingLine(const std::string& line) IsStartingLine(const std::string& line)
{ {
static std::regex re("^(?:`){3}$"); static std::regex re("^(?:`){3}(.*)$");
return std::regex_match(line, re); return std::regex_match(line, re);
} }
@@ -123,6 +123,13 @@ protected:
return; return;
} }
} }
else if (!this->isStarted && line.substr(0, 3) == "```")
{
line = "<pre class=\"" + line.substr(3) + "\"><code>\n";
this->isStarted = true;
this->isFinished = false;
return;
}
line += "\n"; line += "\n";
} }

View File

@@ -59,3 +59,26 @@ TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
ASSERT_EQ(expected, outputString); ASSERT_EQ(expected, outputString);
} }
TEST_F(MADDY_CODEBLOCKPARSER, ItShouldUseAnythingBehindFirstBackticksAsClass)
{
std::vector<std::string> markdown = {
"```cpp"
, "some code"
, "some other code"
, "```"
};
std::string expected = "<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
for (std::string md : markdown)
{
cbParser->AddLine(md);
}
ASSERT_TRUE(cbParser->IsFinished());
std::stringstream& output(cbParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}