Skip to content

Commit b7cdc47

Browse files
luciansmithfbergmann
authored andcommitted
Sanitize HTML input for html2md.
Since html2md messes up links if the HTML is somewhat non-standard, sanitizing the input before converting lets the library perform as it should (on the input I've tested it on, at least).
1 parent e7053a6 commit b7cdc47

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/sbml/util/util.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,16 @@ std::string util_markdown_to_html(const std::string& markdown)
565565

566566
std::string util_html_to_markdown(const std::string& html)
567567
{
568-
return html2md::Convert(html);
568+
std::regex pattern("[Hh][Rr][Ee][Ff] *= *");
569+
std::string copy = std::regex_replace(html, pattern, "href=");
570+
571+
pattern = "< *([a-zA-Z]*) */ *>";
572+
copy = std::regex_replace(copy, pattern, "<$1></$1>");
573+
574+
pattern = "< */ *([a-zA-Z]*) *>";
575+
copy = std::regex_replace(copy, pattern, "</$1>");
576+
577+
return html2md::Convert(copy);
569578
}
570579

571580

0 commit comments

Comments
 (0)