r-lib / xml2

Bindings to libxml2
https://xml2.r-lib.org/
Other
220 stars 81 forks source link

Support indentation of generated xml / html #446

Open kevinushey opened 2 months ago

kevinushey commented 2 months ago

libxml2 supports indentation of generated XML / HTML documents, via https://github.com/GNOME/libxml2/blob/master/xmlwriter.c#L4570-L4589. It would be handy if this could be made available in write_xml() and write_html().

jennybc commented 2 months ago

By analogy with JSON, I'm interested in taking something like this:

{"user":{"id":1,"name":"John Doe","contact":{"email":"john.doe@example.com","phone":{"home":"555-555-5555","work":"555-555-5556"}},"address":{"street":"123 Main St","city":"Anytown","state":"CA","postalCode":"12345","coordinates":{"latitude":37.7749,"longitude":-122.4194}},"preferences":{"notifications":{"email":true,"sms":false},"theme":"dark"}}}

and prettifying it like this:

json |> jsonlite::prettify()
#> {
#>     "user": {
#>         "id": 1,
#>         "name": "John Doe",
#>         "contact": {
#>             "email": "john.doe@example.com",
#>             "phone": {
#>                 "home": "555-555-5555",
#>                 "work": "555-555-5556"
#>             }
#>         },
#>         "address": {
#>             "street": "123 Main St",
#>             "city": "Anytown",
#>             "state": "CA",
#>             "postalCode": "12345",
#>             "coordinates": {
#>                 "latitude": 37.7749,
#>                 "longitude": -122.4194
#>             }
#>         },
#>         "preferences": {
#>             "notifications": {
#>                 "email": true,
#>                 "sms": false
#>             },
#>             "theme": "dark"
#>         }
#>     }
#> }
#> 

But with HTML.