JuliaWeb/Gumbo.jl

Gumbo strips away template tags

Closed this issue · 8 comments

Ex:

julia> parsehtml("<template v-slot:avatar><q-icn name='moo' /></template>")
HTML Document:
<!DOCTYPE >
HTMLElement{:HTML}:<HTML>
  <head></head>
  <body></body>
</HTML>

vs

julia> parsehtml("<templatee v-slot:avatar><q-icn name='moo' /></templatee>")
HTML Document:
<!DOCTYPE >
HTMLElement{:HTML}:<HTML>
  <head></head>
  <body>
    <templatee v-slot:avatar="">
      <q-icn name="moo"></q-icn>
    </templatee>
  </body>
</HTML>

Gumbo: 0.8.0

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, icelake-client)

Thanks

Can anybody comment on this please? It's a major pain when building HTML frontends the <template> tag is key. I've been trying a million things to keep it in the DOM but nothing seems to work. Not sure if this is normal behaviour - it's true that browsers don't render <template> on the page but it's in the DOM.

Alternatively, maybe having the option/config to replace/remove :template from the TAGS collection - that would make it unknown and would just leave it.

Any advice would be appreciated. Thanks!

aviks commented

Can you test this with the C library, and see what the behaviour is there? In general, we're only a very thin layer around the C library. [Edit] Not needed any more. Results of my analysis are below.

aviks commented

Ok, so having investigated this, what we need is something along the lines of #75, but for TemplateNodes.

In CGumbo.jl we need to define const TEMPLATE = Int32(6). Then pass a preserve_template optional argument through the parsing options like in #75. Finally, in conversion.jl#load_node function, check the type and this argument to load the node. The actual node type (according to the gumbo .h file linked above) should be CGumbo.Node{CGumbo.Element}

Oh, awesome findings, thank you @aviks !

Is this still an issue? I need to be using template tags.

aviks commented

Yes, I don't think we've got a PR for this, and I've not had the time to implement this myself. The strategy described in #86 (comment) is what needs doing.

@aviks your hint to #75 was perfect. I just submitted a PR.