Skip to content

Commit

Permalink
Merge pull request #90 from andrejewski/position
Browse files Browse the repository at this point in the history
Add line, column, and index numbers to nodes
  • Loading branch information
andrejewski authored Apr 6, 2018
2 parents 7f1f890 + 1f3daa7 commit a7f8ade
Show file tree
Hide file tree
Showing 12 changed files with 8,807 additions and 401 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ Himalaya handles a lot of HTML's fringe cases, like:
### Preserves Whitespace
Himalaya does not cut corners and returns an accurate representation of the HTML supplied. To remove whitespace, post-process the JSON; check out [an example script](https://gist.github.com/andrejewski/773487d4f4a46b16865405d7b74eabf9).

### Line, column, and index positions
Himalaya can include the start and end positions of nodes in the parse output.
To enable this, you can pass `parse` the `parseDefaults` extended with `includePositions: true`:

```js
import { parse, parseDefaults } from 'himalaya'
parse('<img>', { ...parseDefaults, includePositions: true })
/* =>
[
{
"type": "element",
"tagName": "img",
"attributes": [],
"children": [],
"position": {
"start": {
"index": 0,
"line": 0,
"column": 0
},
"end": {
"index": 5,
"line": 0,
"column": 5
}
}
}
]
*/
```

## Going back to HTML
Himalaya provides a `stringify` method. The following example parses the HTML to JSON then parses the JSON back into HTML.

Expand Down
Loading

0 comments on commit a7f8ade

Please # to comment.