-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($compile): allow SVG and MathML templates via special type
property
#7265
Conversation
…perty Previously, templates would always be assumed to be valid HTML nodes. In some cases, it is desirable to use SVG or MathML or some other language. For the time being, this change is only truly meaningful for SVG elements, as MathML has very limited browser support. But in the future, who knows?
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@vojtajina It's pretty small, but it does include a new API feature, so that's the one thing that might be problematic. Pretty small though, most of this code is tests. |
@caitp Just to make sure I understand this... |
@@ -1813,6 +1827,20 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
} | |||
|
|||
|
|||
function wrapTemplate(type, template) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea: This is not really wrapping, it's constructing DOM (in the case of SVG/Math). How about we make it to construct DOM from HTML even for regular templates and call it constructDOMfromHTML
or somethin...
Anyway, just a comment, feel free to ignore this one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, if someone wants to come up with a better/more descriptive name for it, I don't have a problem with it. I think it's a good point.
My thinking is that it's (maybe) wrapping the template in a specific DOM node, so I called it wrapTemplate() --- but it is true that that's a bit of a misnomer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recastTemplate, maybe-perhaps? I know I haven't contributed as of yet, but I saw this in my inbox....
To Vojta's point, when I first read the line of code, I thought I would need to shed an enclosure . Reading the comments on the PR put me on the right track.
Yeah. createElementNS would get around it, but it would complicate jqLite too much to do it that way, so I think it's all we can do |
LGTM. |
Previously, templates would always be assumed to be valid HTML nodes. In some cases, it is desirable to use SVG or MathML or some other language.
For the time being, this change is only truly meaningful for SVG elements, as MathML has very limited browser support. But in the future, who knows?
NOTE: It would be nice (and more extensible) to simply add a namespaceURI option to the directive, but unfortunately this would require potentially difficult changes to jqLite.
This approach seemed much simpler, and would be more directly useful to persons wanting to use SVG content in a directive template, without a wrapping
<svg>
element. Additionally, it's much easier to simply write "svg" than a full namespace URI, so it's more approachable in this fashion as well.