Skip to content

Commit 31a6ce3

Browse files
luciansmithfbergmann
authored andcommitted
Encode all &, <, and > in markdown.
This is non-standard markdown! But it has the advantage of creating valid HTML more often, so I think on balance it's a win? This means that this translator will *not* translate valid HTML in markdown to actual HTML. I figured this was a more uncommon occurrence than (say) all the biomodels notes that have "<=>" as a reaction symbol, or that have '&' in a URL. We can drop this (I think) if tim-gromeyer/html2md#158 is addressed. But Maddy might need updating as well. Anyway: hack for now, but happy to revert if people think the cost is too severe.
1 parent b7cdc47 commit 31a6ce3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/sbml/util/util.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,22 @@ std::string util_markdown_to_html(const std::string& markdown)
558558
//config->enabledParsers |= maddy::types::HTML_PARSER; // do not wrap HTML in paragraph
559559
//std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
560560

561-
std::stringstream markdownInput(markdown);
561+
//Note: tried to figure out difference between genuine HTML-ish of &, < and > vs.
562+
// ones that needed to be encoded, but failed. Everything will officially
563+
// translate if we encode them all indiscriminately, so hey! Here we go.
564+
std::regex pattern("&");
565+
std::string copy = std::regex_replace(markdown, pattern, "&amp;");
566+
567+
pattern = "&amp;amp;";
568+
copy = std::regex_replace(copy, pattern, "&amp;");
569+
570+
pattern = "<";
571+
copy = std::regex_replace(copy, pattern, "&lt;");
572+
573+
pattern = ">";
574+
copy = std::regex_replace(copy, pattern, "&gt;");
575+
576+
std::stringstream markdownInput(copy);
562577
static maddy::Parser parser;
563578
return parser.Parse(markdownInput);
564579
}

0 commit comments

Comments
 (0)