scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

How to prevent html fragment parsing from wrapping with html tags #180

Closed bcardarella closed 2 years ago

bcardarella commented 3 years ago

If I do the following:

Parser.parseFragment("<div>Hello, world!</div>", nil, "")

I get an resulting fragment with html of:

<html>
  <head></head>
  <body>
    <div>Hello, world!</div>
  </body>
</html>

whereas I want to preserve the actual fragment of just : <div>Hello, world!</div> and not wrap in additional tags. How best can I go about this?

polurezov8 commented 2 years ago

Hi @bcardarella 👋🏻 Try to use var html = try document.body()?.html() to avoid additional tags wrapping.