scinfu/SwiftSoup

Unwanted newlines in <pre><code> tags

ABridoux opened this issue · 1 comments

Problem exposition

I noticed that the function SwiftSoup.parse(:) will add newlines in a <pre><code> in specific cases, which breaks the code syntax inside that block. This is especially visible when the code inside the block is in Plist or XML format.

For instance, with the following HTML, the SwiftSoup.parse(:) will add new lines after each Plist tag, which breaks the code indentation.

<html>
  <head>
    <title>Try SwiftSoup</title>
  </head>
  <body>

    <pre><code class="plist">
    <dict>
  	<key>firstKey</key>
	<string>10</string>
	<key>secondKey</key>
	<string>Toto</string>
    </dict>

   </code></pre>
  </body>
</html>

The result of the online playground can be found here:
Screenschot- 17 34 40 2102-2021@2x

Possible cause

I think that the tags of the Plist code block interfere with the one from the HTML. Although this should not happen since those tags are inside a <pre><code> tag.

Temporary fix

By escaping the HTML special characters < and > in the Plist data before running the parse(:) function, this problem can be avoided.

Anyway, thank for this nice project which is very useful!

did this issue fixed with last releases?