scinfu/SwiftSoup

Unwanted whitespace before <svg> when inside <a>

annomusa opened this issue · 1 comments

Description:

When I try to create an HTML element from a given string containing an <a> tag followed by an <svg>, the parsed result introduces an unwanted whitespace between the link text and the <svg> element.

Steps to Reproduce:

  1. Parse the following string using SwiftSoup:
let inputHTML = """
<a href="https://www.google.com">STRING<svg width="1em" height="1em"><circle cx="0.5em" cy="0.5em" r="0.5em" /></svg></a>
"""
let element = try Element(Tag.valueOf("span"), "")
try element.html(inputHTML)
  1. Print the element variable, the result will be like below
<html>
<a href="https://www.google.com">STRING
  <svg width="1em" height="1em">
    <circle cx="0.5em" cy="0.5em" r="0.5em" />
  </svg></a>

</html>

Expected Result

No whitespace after "STRING" just like the inputHTML that I inject

Image image

Actual Result

Theres an extra space after the "STRING"

Image image

Environment/Setup:

SwiftSoup version: 2.4.3
Xcode: 14.3.1
iOS version: iOS 16.0

anyway, thank you for your hard work and dedication. your efforts make a difference for developers like me. I appreciate it!

I can avoid this by setting the prettyPrint to be false

doc.outputSettings().prettyPrint(pretty: false)

But I think its better to avoid new line (+tab) if the parent tag is an <a>