Skip to content

Commit

Permalink
fix: inner text at the end of parent element
Browse files Browse the repository at this point in the history
  • Loading branch information
Youen Péron committed Nov 20, 2023
1 parent a37033b commit 908a8d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/xixo/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/xixo/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,25 @@ func TestStreamWithoutModifications(t *testing.T) {
// {input: "<a>i<b>cb1</b>j<b>cb2</b>k<b>cb3</b>l</a>", element: "a"},
// {input: "<a>i<b>cb1</b>j<b>cb2</b>k</a>", element: "a"},

{input: "<a>\n<b>\n<d>contenta</d>\n</b>\n <!-- comment --><c nil='true'/>\n</a>", element: "a"},

{input: "<a>\n<b>\n<d>content without attrbut</d>\n</b>\n<c/>\n</a>", element: "a"},

{input: "<a><b/>\n</a>", element: "a"},
{input: "<a><b/>\n</a>", element: "b"},

{input: "<a><b/>\n<c/>\n</a>", element: "a"},
{input: "<a><b/>\n<c/>\n</a>", element: "b"},
{input: "<a><b/>\n<c/>\n</a>", element: "c"},

{input: "<a>\n<b>\n<d>contenta</d>\n</b>\n<c xsi:nil=\"true\"/>\n</a>", element: "a"},
{input: "<a>\n<b>\n<d>contentb</d>\n</b>\n<c xsi:nil=\"true\" />\n</a>", element: "b"},
{input: "<a>\n<b>\n<d>contentc</d>\n</b>\n<c xsi:nil=\"true\" />\n</a>", element: "c"},

{input: " <a><b><d></d> </b>\n<c/>\n</a>", element: "a"},
{input: " <a><b> contenu </b>\n<c/>\n</a>", element: "b"},
{input: " <a><b> contenu </b>\n<c xsi:nil=\"true\" />\n</a>", element: "c"},

{input: "<a><b attr='true'/>\n</a>", element: "a"},
{input: "<a><b attr=\"true\"/>\n</a>", element: "a"},

Expand Down

0 comments on commit 908a8d7

Please sign in to comment.