From 0f09228adbfd3e3857b101ef69ded4bf9e5d4016 Mon Sep 17 00:00:00 2001 From: Hunam Date: Fri, 30 Jul 2021 11:00:03 +0200 Subject: [PATCH] vdoc: fix wrong escaping in HTML docs (#10638) --- cmd/tools/vdoc/html.v | 8 +++++++- cmd/tools/vdoc/html_tag_escape_test.v | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 cmd/tools/vdoc/html_tag_escape_test.v diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 07099ca9ac..e253898875 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -4,6 +4,7 @@ import os import net.urllib import strings import markdown +import regex import v.scanner import v.ast import v.token @@ -493,7 +494,12 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, } fn html_tag_escape(str string) string { - return str.replace_each(['<', '<', '>', '>']) + excaped_string := str.replace_each(['<', '<', '>', '>']) + mut re := regex.regex_opt(r'`.+[(<)(>)].+`') or { regex.RE{} } + if re.find_all_str(excaped_string).len > 0 { + return str + } + return excaped_string } /* diff --git a/cmd/tools/vdoc/html_tag_escape_test.v b/cmd/tools/vdoc/html_tag_escape_test.v new file mode 100644 index 0000000000..64a7d1c9c6 --- /dev/null +++ b/cmd/tools/vdoc/html_tag_escape_test.v @@ -0,0 +1,6 @@ +module main + +fn test_html_tag_escape() { + assert html_tag_escape('') == '<abc>' + assert html_tag_escape('``') == '``' +}