From 908a8d7b825a8d8501c595727c744dfeea874229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Youen=20P=C3=A9ron?= Date: Mon, 20 Nov 2023 09:15:58 +0000 Subject: [PATCH] fix: inner text at the end of parent element --- pkg/xixo/parser.go | 2 ++ pkg/xixo/parser_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/xixo/parser.go b/pkg/xixo/parser.go index 63bf065..15a773a 100644 --- a/pkg/xixo/parser.go +++ b/pkg/xixo/parser.go @@ -506,6 +506,8 @@ search_close_tag: if cur == '>' { // if tag name not found if prev == '/' { // tag special close result.autoClosable = true + result.outerTextBefore = string(x.scratchInnerText.bytes()) + x.scratchInnerText.reset() return result, true, nil } diff --git a/pkg/xixo/parser_test.go b/pkg/xixo/parser_test.go index a932527..39e9aa6 100644 --- a/pkg/xixo/parser_test.go +++ b/pkg/xixo/parser_test.go @@ -233,6 +233,10 @@ func TestStreamWithoutModifications(t *testing.T) { // {input: "icb1jcb2kcb3l", element: "a"}, // {input: "icb1jcb2k", element: "a"}, + {input: "\n\ncontenta\n\n \n", element: "a"}, + + {input: "\n\ncontent without attrbut\n\n\n", element: "a"}, + {input: "\n", element: "a"}, {input: "\n", element: "b"}, @@ -240,6 +244,14 @@ func TestStreamWithoutModifications(t *testing.T) { {input: "\n\n", element: "b"}, {input: "\n\n", element: "c"}, + {input: "\n\ncontenta\n\n\n", element: "a"}, + {input: "\n\ncontentb\n\n\n", element: "b"}, + {input: "\n\ncontentc\n\n\n", element: "c"}, + + {input: " \n\n", element: "a"}, + {input: " contenu \n\n", element: "b"}, + {input: " contenu \n\n", element: "c"}, + {input: "\n", element: "a"}, {input: "\n", element: "a"},