Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid parsing template contents as html before passing to transform function #48

Closed
WickyNilliams opened this issue Oct 16, 2022 · 8 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@WickyNilliams
Copy link

I was playing around building a custom transform, and i noticed that the innards of the template seem to get parsed as html and then passed to to the transform function, rather than the raw content. For example:

<template webc:type="custom">
  <foo id={this.uid}>test</test>
</template>

If I've registered a custom transform like

page.setTransform("custom", content => console.log(content))

The content I receive has already been processed, so we see in the logs:

<foo id="{this.uid}">test</test>

Notice the quotes around the curly braces that weren't there before. If possible it would be nice to receive the raw, untouched contents, which can later be parsed after I have transformed it.

@zachleat
Copy link
Member

Curious if you tried mixing this with webc:raw?

@WickyNilliams
Copy link
Author

I didn't! I'll try next time I'm at the computer. Does raw prevent reprocessing? If raw fixes it, it would be nice to be able to configure a specific transform to default to raw like

page.setTransform(myTransform, { raw: true })

@WickyNilliams
Copy link
Author

Just tested, the result is the same even with webc:raw

@zachleat zachleat added the bug Something isn't working label Oct 17, 2022
@zachleat zachleat self-assigned this Oct 17, 2022
@zachleat zachleat added this to the Next minor release milestone Oct 17, 2022
@zachleat
Copy link
Member

Uncovered a pretty hefty bug with raw <template> here, thank you! <template> (when used without webc:root) will now return the raw preparsed input!

Shipping with the next version (probably 0.6)

@WickyNilliams
Copy link
Author

WickyNilliams commented Oct 17, 2022

Amazing! Thank you. Does this mean I should or shouldn't use webc:raw to get this behaviour?

@zachleat
Copy link
Member

Shipped with 0.5.4. Just <template webc:type> should suffice but this will also fix how we handle <template webc:raw> too!

@WickyNilliams
Copy link
Author

Lovely stuff. Appreciate it

@zachleat
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants