-
Notifications
You must be signed in to change notification settings - Fork 45
Better emphasis #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Better emphasis #77
Changes from all commits
9292d3c
2df2fe7
c89a983
1a12c2c
8e2c44c
30d6cf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,23 @@ class StrongParser : public LineParser | |
*/ | ||
void Parse(std::string& line) override | ||
{ | ||
// This version of the regex is changed exactly the same way | ||
// that the regex for the emphasized parser was changed, and | ||
// it then passes all the 'disabled' tests in the 'strong parser' | ||
// test, but then it fails general parsing. For some reason, | ||
// "__text__" translates "<i></i>text<i></i>" even though there | ||
// are no word boundaries at the correct places. It's weird! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The strong parser is usually handled before the emphasized one: https://github.com/progsource/maddy/blob/master/include/maddy/parser.h#L195 |
||
|
||
// static std::vector<std::regex> res{ | ||
// std::regex{ | ||
// R"((?!.*`.*|.*<code>.*)\b\*\*(?![\s])(?!.*`.*|.*<\/code>.*)" | ||
// "(.*?[^\s])\*\*\b(?!.*`.*|.*<\/code>.*))" | ||
// }, | ||
// std::regex{ | ||
// R"((?!.*`.*|.*<code>.*)\b__(?![\s])(?!.*`.*|.*<\/code>.*)" | ||
// "(.*?[^\s])__\b(?!.*`.*|.*<\/code>.*))" | ||
// } | ||
// }; | ||
static std::vector<std::regex> res{ | ||
std::regex{ | ||
R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,118 @@ TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode) | |
ASSERT_EQ(test.expected, test.text); | ||
} | ||
} | ||
|
||
TEST(MADDY_STRONGPARSER, ItReplacesUnderscoresAtStringEdges) | ||
{ | ||
std::string text = "__some text__"; | ||
std::string expected = "<strong>some text</strong>"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(DISABLED_MADDY_STRONGPARSER, ItDoesNotReplaceMarkdownWithInlineUnderscores) | ||
{ | ||
std::string text = "some text__bla__text testing __it__ out"; | ||
std::string expected = "some text__bla__text testing <strong>it</strong> out"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(DISABLED_MADDY_STRONGPARSER, ItOnlyReplacesUnderscoresAtWordBreaks) | ||
{ | ||
std::string text = "some __text__bla__ testing __it__ out"; | ||
std::string expected = | ||
"some <strong>text__bla</strong> testing <strong>it</strong> out"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(MADDY_STRONGPARSER, ItReplacesUnderscoresWithMultipleWords) | ||
{ | ||
std::string text = "some __text testing it__ out"; | ||
std::string expected = "some <strong>text testing it</strong> out"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(DISABLED_MADDY_STRONGPARSER, ItAllowsTripleUnderscores) | ||
{ | ||
// I'm not sure if this is standard or not, but this is how the github | ||
// markdown parser behaves. Other things I've seen want it to *not* | ||
// match. | ||
|
||
std::string text = "some ___text testing it__ out"; | ||
std::string expected = "some <strong>_text testing it</strong> out"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the CommonMark Spec, there is this example:
Also GitHub spec: https://github.github.com/gfm/#example-465 So I guess, the |
||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(MADDY_STRONGPARSER, ItDoesntReplaceUnderscoresInsideCodeBlocks) | ||
{ | ||
std::string text = | ||
"Stuff inside <code> blocks __shouldn't be strong__ </code> at all"; | ||
std::string expected = | ||
"Stuff inside <code> blocks __shouldn't be strong__ </code> at all"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(DISABLED_MADDY_STRONGPARSER, ItDoesNotReplaceUnderscoresInURLs) | ||
{ | ||
std::string text = "[Link Title](http://example.com/what__you__didn't__know)"; | ||
std::string expected = | ||
"[Link Title](http://example.com/what__you__didn't__know)"; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(MADDY_STRONGPARSER, ItParsesOutsideCodeBlocks) | ||
{ | ||
std::string text = | ||
"Stuff inside <code> blocks __shouldn't be strong__ </code>" | ||
" but outside __should__."; | ||
std::string expected = | ||
"Stuff inside <code> blocks __shouldn't be strong__ </code>" | ||
" but outside <strong>should</strong>."; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} | ||
|
||
TEST(MADDY_STRONGPARSER, ItParsesOutsideTickBlocks) | ||
{ | ||
std::string text = | ||
"Stuff inside `blocks __shouldn't be strong__ `" | ||
" but outside __should__."; | ||
std::string expected = | ||
"Stuff inside `blocks __shouldn't be strong__ `" | ||
" but outside <strong>should</strong>."; | ||
auto strongParser = std::make_shared<maddy::StrongParser>(); | ||
|
||
strongParser->Parse(text); | ||
|
||
ASSERT_EQ(expected, text); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to put this comment into your commit message instead and remove it from here, because as a comment it could become outdated at some point.