Uh oh!
There was an error while loading. Please reload this page.
Update transitive.rb - #230
Conversation
This makes Transitive.rb do exactly what the docs say it should do. It outputs Pretty xml except for text nodes which are left untouched.
This formatter was adding newline characters so the Text nodes grew every time you saved/wrote them. Adding #strip fixes it. I've been working with it and it works perfectly.
naitoh
commented
Jan 9, 2025
tompng
commented
Jan 9, 2025
Formatting this html content html="<html><title> foo </title><body><div> bar </div></body></html>"REXML::Document.new(html).write(STDOUT,2,true)In the document
This is transitive output. It looks weird, but it's indented, it's valid, and the content is preserved. <html><title> foo </title><body><div> bar </div></body></html>This is not transitive. It looks pretty but the content is not preserved. <html><title>
foo
</title><body><div>
bar
</div></body></html> |
If you guys want to preserve Transitive the way that it is for backward compatibility, that's fine with me. My issue is that I need a user friendly (pretty) output that doesn't change my text nodes. I don't see any scenario where having the formatter change the text is advantageous. When I write my xml with Pretty, it adds a bunch of whitespace so when I read it back it's wrong. Its a different string that doesn't work. This makes no sense to me becuase the purpose of XML is to be read by a program, not a human. Pretty makes it human readable but now program readable. I really like Pretty.rb. I'd love to see it have an option to preserve text nodes. That would be the best imho. In fact, I would suggest making the default behavior of Pretty be to preserve text nodes, and have an option to indent with a bunch of whitespace. That makes sense to me. Are you guys receptive to that instead? |
kou
commented
Jan 10, 2025
What does "text nodes" mean? Could you provide a sample XML and an expected pretty output for it? |
naitoh
commented
Jan 11, 2025
Thanks for your comment.
Depending on your answer below, I think it would be more appropriate to extend
|
naitoh
commented
May 7, 2025
Could you answer this? |
GitHub: fixGH-228
This makes Transitive.rb do exactly what the docs say it should do. It outputs Pretty xml except for text nodes which are left untouched. If you read the issue that I posted, you can see that the current Transitive output is garbled. Also, this has the benefit of being initialized using Prestty.rb, initialize method for simplicity.