# Whitespace issue with Gumbo.jl

**URL:** <https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832>\
**Category:** Web Stack\
**Tags:** question\
**Created:** [December 19, 2018, 2:33pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832 "2018-12-19T14:33:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [December 19, 2018, 2:33pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/1 "2018-12-19T14:33:36Z")

</div>

I realize this probably isn’t an issue with `Gumbo.jl` but rather with Gumbo itself (unless there’s some switch or something that’s not exposed) – or maybe even the HTML5 parsing algorithm – but I thought I’d see if someone has a not all-too-hacky solution. (A hacky solution won’t be so hard 🙂)

The issue is simply that text like `foo<em> </em>bar` loses info about the whitespace, so if I extract the text, I end up with `foobar`, though browsers render this as `foo bar`, which makes sense to me (although the original markup does _not_ make sense; but it’s not mine).

So … is there any way to tell Gumbo to preserve whitespace, for example, so I can check if there actually is space in there or not?

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [December 19, 2018, 5:09pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/2 "2018-12-19T17:09:06Z")

</div>

Can you provide a minimal reproducible example?

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [December 19, 2018, 6:35pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/3 "2018-12-19T18:35:21Z")

</div>

Sure:

```julia
julia> using Gumbo
julia> doc = parsehtml("foo<em> </em>bar")
HTML Document:
<!DOCTYPE >
<HTML>
  <head></head>
  <body>
    foo
    <em></em>
    bar
  </body>
</HTML>

```

So, for example:

```julia
julia> using Cascadia
julia> nodeText(doc.root)
"foobar"

```

What I would have liked here is `"foo bar"`.

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [December 19, 2018, 7:05pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/4 "2018-12-19T19:05:41Z")

</div>

Aye. That does seem suboptimal. As a workaround maybe

```julia
# This is for single space between
doc = parsehtml(replace("foo<em> </em>", r"(?<=>)\s+(?=<)" => "_"))

```

Maybe open an issue at the repository.

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [December 20, 2018, 2:56pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/5 "2018-12-20T14:56:12Z")

</div>

Yeah, I thought about inserting a placeholder of some sort. It just seemed hackish. But, yeah, I’ll open up an issue and see. I suspect this is just a consequence of how the original Gumbo C library behaves, and it hasn’t been updated for years, it seems, so…

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [December 20, 2018, 3:06pm UTC](https://discourse.julialang.org/t/whitespace-issue-with-gumbo-jl/18832/6 "2018-12-20T15:06:30Z")

</div>

Opened an issue: [Tagged whitespace disappears · Issue #64 · JuliaWeb/Gumbo.jl · GitHub](https://github.com/JuliaWeb/Gumbo.jl/issues/64)
