Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outerHTML() will add spaces and new lines wrongly #37

Closed
AlonikiX opened this issue Oct 10, 2017 · 3 comments
Closed

outerHTML() will add spaces and new lines wrongly #37

AlonikiX opened this issue Oct 10, 2017 · 3 comments

Comments

@AlonikiX
Copy link

AlonikiX commented Oct 10, 2017

(the answer of issue #26 cannot solve my problem)
Hi, when I use parse() method to parse a html file, and then write the dom outer html to a new file, it will contain wrong spaces. For example, in the raw html, it has:
<div><p>a<p></div>

but in outerHtml():

<div>
    <p>
         a
    </p>
</div>

in this case, the position of 'a' change when render the html page.

Is there any method or solution to solve this problem?

@scinfu
Copy link
Owner

scinfu commented Oct 15, 2017

I'll do some tests and let you know

@scinfu
Copy link
Owner

scinfu commented Oct 16, 2017

Creating from new document the result is right:

    func testABC()throws{
        let doc: Document = Document("")
        let div = try doc.appendElement("div")
        let p = try div.appendElement("p")
        try p.appendText("abc")
        let text = try doc.outerHtml()
        //Result: "<div>\n <p>abc</p>\n</div>"
    }

if you need output "<div><p>abc</p></div>", you need to remove the pretty setting:

    func testABC()throws{
        let doc: Document = Document("<div><p>a<p></div>")
        let div = try doc.appendElement("div")
        let p = try div.appendElement("p")
        try p.appendText("abc")
        doc.outputSettings().prettyPrint(pretty: false)
        let text = try doc.outerHtml()
        //"<div><p>abc</p></div>"
    }

@AlonikiX
Copy link
Author

It works, thanks : )

@scinfu scinfu closed this as completed Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants