-
Notifications
You must be signed in to change notification settings - Fork 142
Allow HTML in attributes #322
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
Conversation
Adds html escaping in textareas
I'm 👎 on storing escaped data in attributes. It seems like a technical hack around conceptual contradiction — shortcodes are macros to produce HTML markup. |
I think escaping the data in some way is unavoidable. Its a common use case for shortcode attributes to hold names, strings for display, or other data which can't reasonably be expected to be free of all special characters. There's no other way, short of a core change, to get The idea of the filter on |
But, if we're looking for alternative approaches, replacing the attribute parser regex in core with something like an XML attribute reader would be a good start. My initial confusion at this issue came because intuitively I expected shortcode attributes to behave like HTML attributes and was surprised that |
I think the main problem I was getting around was that it breaks the view if an attribute has html in, when you have a textarea field that gets stored in an attribute this can happen with no clear way to recover easily. URL escaping was the only common way to handle this between JS and PHP besides I agree it's totally hacky but can't see how else would #236 be feasible? |
A slightly less hacky approach may be to embed the data inside |
@mattheu any thoughts on this? |
It would be nice to have an official core opinion on this. |
We chatted about this some today. It seems like encoding behind the scenes is the only way we can go for now. Could we make registration happen on the field-level, and automatically unencode so no modification to an existing shortcode is necessary? |
@sanchothefat One nit before this lands — could we call the argument |
Actually, now that #179 has landed, let's bump this out of v0.4.0 and come back to it if we need. |
Closing in favor of #496 |
This PR adds support for escaping html in attributes so that HTML no longer breaks the view rendering.
It should also go some way to paving the way forward for #236
It does a few things:
encodeURIComponent()
anddecodeURIComponent()
where appropriaterawurldecode()
automatically on the values provided the shortcode author uses theshortcode_atts()
function and provides the 3rd parameter stating the shortcode tag nameExample: