Skip to content

Commit e7053a6

Browse files
luciansmithfbergmann
authored andcommitted
Update Maddy to not convert internal single underscores.
Still has problems with internal double-underscores, but at least those are less common.
1 parent fad7b3a commit e7053a6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/sbml/maddy/emphasizedparser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ class EmphasizedParser : public LineParser
4040
*/
4141
void Parse(std::string& line) override
4242
{
43+
// Modifed from previous version, with help from
44+
// https://stackoverflow.com/questions/61346949/regex-for-markdown-emphasis
4345
static std::regex re(
44-
R"((?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\/code>.*)([^_]*)_(?!.*`.*|.*<\/code>.*))"
46+
R"((?!.*`.*|.*<code>.*)\b_(?![\s])(?!.*`.*|.*<\/code>.*)(.*?[^\s])_\b(?!.*`.*|.*<\/code>.*))"
4547
);
4648
static std::string replacement = "<em>$1</em>";
4749

src/sbml/maddy/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Parser
5959
*/
6060
static const std::string& version()
6161
{
62-
static const std::string v = "1.4.0";
62+
static const std::string v = "1.5.0";
6363
return v;
6464
}
6565

src/sbml/maddy/strongparser.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ class StrongParser : public LineParser
4040
*/
4141
void Parse(std::string& line) override
4242
{
43+
// This version of the regex is changed exactly the same way
44+
// that the regex for the emphasized parser was changed, and
45+
// it then passes all the 'disabled' tests in the 'strong parser'
46+
// test, but then it fails general parsing. For some reason,
47+
// "__text__" translates "<i></i>text<i></i>" even though there
48+
// are no word boundaries at the correct places. It's weird!
49+
50+
// static std::vector<std::regex> res{
51+
// std::regex{
52+
// R"((?!.*`.*|.*<code>.*)\b\*\*(?![\s])(?!.*`.*|.*<\/code>.*)"
53+
// "(.*?[^\s])\*\*\b(?!.*`.*|.*<\/code>.*))"
54+
// },
55+
// std::regex{
56+
// R"((?!.*`.*|.*<code>.*)\b__(?![\s])(?!.*`.*|.*<\/code>.*)"
57+
// "(.*?[^\s])__\b(?!.*`.*|.*<\/code>.*))"
58+
// }
59+
// };
4360
static std::vector<std::regex> res{
4461
std::regex{
4562
R"((?!.*`.*|.*<code>.*)\*\*(?!.*`.*|.*<\/code>.*)([^\*\*]*)\*\*(?!.*`.*|.*<\/code>.*))"

0 commit comments

Comments
 (0)