mirror of
https://github.com/progsource/maddy.git
synced 2026-03-25 07:50:39 +01:00
feat: add class to block code
This commit is contained in:
@@ -23,6 +23,7 @@ maddy uses [semver versioning](https://semver.org/).
|
|||||||
*  GitHub workflow
|
*  GitHub workflow
|
||||||
*  config flags `isEmphasizedParserEnabled` and `isHTMLWrappedInParagraph`
|
*  config flags `isEmphasizedParserEnabled` and `isHTMLWrappedInParagraph`
|
||||||
*  config flag `enabledParsers` to en-/disable each parser separately
|
*  config flag `enabledParsers` to en-/disable each parser separately
|
||||||
|
*  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
|
||||||
|
|||||||
@@ -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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user