diff --git a/pipeline.go b/pipeline.go index bd5bf42..2b62418 100644 --- a/pipeline.go +++ b/pipeline.go @@ -32,7 +32,7 @@ func StripTags(html string) string { switch r { case '<': - if i+1 < len(runes) && isTagStartRune(runes[i+1]) { + if i+1 < len(runes) && isTagStartRune(runes[i+1]) && hasTagCloser(runes, i+2) { inTag = true continue } @@ -67,6 +67,15 @@ func isTagStartRune(r rune) bool { } } +func hasTagCloser(runes []rune, start int) bool { + for i := start; i < len(runes); i++ { + if runes[i] == '>' { + return true + } + } + return false +} + // Imprint renders a node tree to HTML, strips tags, tokenises the text, // and returns a GrammarImprint — the full render-reverse pipeline. // Usage example: imp := Imprint(Text("welcome"), NewContext()) diff --git a/pipeline_test.go b/pipeline_test.go index 7450ee9..6dd0777 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -54,6 +54,14 @@ func TestStripTags_PreservesComparisonOperators_Good(t *testing.T) { } } +func TestStripTags_LiteralAngleBracket_Good(t *testing.T) { + got := StripTags(`a