Skip to content

Move attributes underneath a subobject when displaying json{} #108

@andremarianiello

Description

@andremarianiello

When using the json{} displayer, if an attribute name is tag, text, you get misleading results:

# echo '<div tag="hello">world</div>' |./pup 'div json{}'
[
 {
  "tag": "div",
  "text": "world"
 }
]

tag=hello attribute has disappeared

# echo '<div text="hello">world</div>' |./pup 'div json{}'
[
 {
  "tag": "div",
  "text": "hello world"
 }
]

text=hello attribute has been appended to text

Both these issues can be solved by giving attributes their own object underneath the node object

# echo '<div tag="hello">world</div>' |./pup 'div json{}'
[
 {
  "attrs": {
   "tag": "hello"
  },
  "tag": "div",
  "text": "world"
 }
]
# echo '<div text="hello">world</div>' |./pup 'div json{}'
[
 {
  "attrs": {
   "text": "hello"
  },
  "tag": "div",
  "text": "world"
 }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions