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 get text from element without whitespace normalization and trimmed #169

Closed dhanrajbhandari closed 2 years ago

dhanrajbhandari commented 4 years ago

Currently, element.text() method gives trimmed and whitespace normalised text. Any other way to get element text without trimmed and whitespace normalised?

thanhdiqit commented 3 years ago

Look like in my case. I have filtered TextNode and get original text

node.children()
                    .filter {
                        $0.hasText()
                    }
                    .compactMap {
                        print("🚀🚀🚀")
                        print($0.ownText())
                    }
aehlke commented 3 years ago

@thanhdiqit good except delete hasText() as this reintroduces the behavior OP doesn't want (check the source code - it will exclude whitespace text nodes)

bozek-lu commented 2 years ago

Is there any option to disable trimming whitespaces?