Skip to content

Commit

Permalink
adapt REAMDE to new dom representation
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Jul 6, 2024
1 parent dfb7b48 commit e4ae3f8
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,25 @@ for node != nil {
If we start the `for` loop at the `<button>` and repeatedly call `GetNextNeighborNode` this would be the _order_ that the nodes are _visited_.

```text
β”œβ”€#document
β”‚ β”œβ”€html
β”‚ β”‚ β”œβ”€head
β”‚ β”‚ β”œβ”€body
β”‚ β”‚ β”‚ β”œβ”€nav
β”‚ β”‚ β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "up"
β”‚ β”‚ β”‚ β”œβ”€main
β”‚ β”‚ β”‚ β”‚ β”œβ”€button *️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€span 0️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "start" 1️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€div 2️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€h3 3️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "heading" 4️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€p 5️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "description" 6️⃣
β”‚ β”‚ β”‚ β”œβ”€footer 7️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€p 8️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "down" 9️⃣
#document
β”œβ”€html
β”‚ β”œβ”€head
β”‚ β”œβ”€body
β”‚ β”‚ β”œβ”€nav
β”‚ β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "up"
β”‚ β”‚ β”œβ”€main
β”‚ β”‚ β”‚ β”œβ”€button *️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€span 0️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "start" 1️⃣
β”‚ β”‚ β”‚ β”œβ”€div 2️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€h3 3️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "heading" 4️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€p 5️⃣
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "description" 6️⃣
β”‚ β”‚ β”œβ”€footer 7️⃣
β”‚ β”‚ β”‚ β”œβ”€p 8️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "down" 9️⃣
```

If you only want to visit the ElementNode's (and skip the `#text` Nodes) you can use `GetNextNeighborElement` instead.
Expand All @@ -175,9 +175,6 @@ The same functions also exist for the previous nodes, e.g. `GetPrevNeighborNode`

- πŸ§‘β€πŸ’» [Example code, next basics](/examples/next_basics/main.go)
- πŸ§‘β€πŸ’» [Example code, next inside a loop](/examples/next_loop/main.go)
- πŸ“Ί [Loom Video](#)

TODO: Loom Video

---

Expand All @@ -203,28 +200,28 @@ for _, node := range emptyTextNodes {
### Unwrap Node

```text
β”œβ”€#document
β”‚ β”œβ”€html
β”‚ β”‚ β”œβ”€head
β”‚ β”‚ β”œβ”€body
β”‚ β”‚ β”‚ β”œβ”€article *️⃣
β”‚ β”‚ β”‚ β”‚ β”œβ”€h3
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "Heading"
β”‚ β”‚ β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "short description"
#document
β”œβ”€html
β”‚ β”œβ”€head
β”‚ β”œβ”€body
β”‚ β”‚ β”œβ”€article *️⃣
β”‚ β”‚ β”‚ β”œβ”€h3
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "Heading"
β”‚ β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "short description"
```

If we take the input above and run `UnwrapNode(articleNode)` we can "unwrap" the `<article>`. That means removing the `<article>` while _keeping_ the children (`<h3>` and `<p>`).

```text
β”œβ”€#document
β”‚ β”œβ”€html
β”‚ β”‚ β”œβ”€head
β”‚ β”‚ β”œβ”€body
β”‚ β”‚ β”‚ β”œβ”€h3
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "Heading"
β”‚ β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "short description"
#document
β”œβ”€html
β”‚ β”œβ”€head
β”‚ β”œβ”€body
β”‚ β”‚ β”œβ”€h3
β”‚ β”‚ β”‚ β”œβ”€#text "Heading"
β”‚ β”‚ β”œβ”€p
β”‚ β”‚ β”‚ β”œβ”€#text "short description"
```

---
Expand Down Expand Up @@ -261,12 +258,12 @@ And the `#text` nodes stand out.
> For example in [neighbors_test.go](/neighbors_test.go)
```text
β”œβ”€#document
β”‚ β”œβ”€html
β”‚ β”‚ β”œβ”€head
β”‚ β”‚ β”œβ”€body
β”‚ β”‚ β”‚ β”œβ”€a (href=/about)
β”‚ β”‚ β”‚ β”‚ β”œβ”€#text "Read More"
#document
β”œβ”€html
β”‚ β”œβ”€head
β”‚ β”œβ”€body
β”‚ β”‚ β”œβ”€a (href=/about)
β”‚ β”‚ β”‚ β”œβ”€#text "Read More"
```

While the normal "net/html" [`Render()`](https://pkg.go.dev/golang.org/x/net/html#Render) function would have produced this:
Expand Down

0 comments on commit e4ae3f8

Please sign in to comment.