-
Notifications
You must be signed in to change notification settings - Fork 113
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
[WIP] Namespaces #44
[WIP] Namespaces #44
Conversation
@@ -166,7 +163,7 @@ public function startTag($name, $attributes = array(), $selfClosing = FALSE) { | |||
$lname = $this->normalizeTagName($name); | |||
|
|||
// Make sure we have an html element. | |||
if (!$this->doc->documentElement && $name !== 'html') { | |||
if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) { | |||
$this->startTag('html'); |
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.
I do not understand why is necessary to have always a html root?
I am totally in favor of this change. It should be merged along with #37. RE: the 'html' element, I don't remember exactly why I did it that way. Any full HTML document needs a documentElement (otherwise the DOM implementation gets really flaky). IIRC, the standard strongly recommends (if not outright requires) a root HTML element. So I thought I was doing the right thing. But the way I enforced that doesn't quite look right. As you have added, it should be sensitive to whether we are in a fragment. |
Do you think that this will make it easier to extend html5 to support explicit xml-style namespaces as discussed in #12? I have something similar to #12's templating language, only I can't use processor instructions to create a new kind of template because I'll be parsing/editing existing template files made in things like Fluid (think grails "g:" but with "f:" namespace). I don't expect you to support the explicit namespaces in masterminds/html5, as it does not follow the spec. I expect to extend masterminds/html5 to add the support I need. |
hi @cognifloyd! If you are interested to add explicit xml-style namespaces to html5 documents, i suggest to take a look to this approach: https://github.com/goetas/twital/blob/master/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php#L25 Advertising: if you are interested to xml-style template engine (which uses attributes to declare template behavior), i suggest you to take a look to this project https://github.com/goetas/twital |
@cognifloyd, to add one thing to what @goetas has said... Largely because of @goetas 's work, one should be able to get a handle on the DOMDocument object and serialize it into an XML representation of the HTML semantics. I don't know if that will be exactly standards compliant to the XML part of the HTML5 spec... but it will absolutely support namespacing and XML parsing. Probably, though, what goetas is saying above is the most appropriate for what you're asking. |
The key thing for me is that I'll be editing templates (could be Fluid, Twig, Twital, Grails, or whatever) that have namespaced elements. I'm not worried about serialization yet. First step: parsing. If explicit namespaces are supported (maybe hidden by a flag) within html5-php, that would be one less pass over the DOMTree that I have to do before editing it (with querypath + some custom functions). Here's what I hacked together to see how it could be included: cognifloyd@9287135 Would you consider including something like this in html5-php? Where could a flag of some kind be set to enable/disable including explicit namespaces in the DOM Tree. As @goetas said, HTML5 does need to include support for a limited set of namespaces, so maybe including this isn't so far fetched of an idea (maybe it doesn't have to hidden behind some feature flag)? I hope, that as html5-php gets support for those explicit namespaces, that it is somehow extensible, so that I can register additional namespaces in the DomTreeBuilder. |
You have to choose how to write your templates: First way (pure xml style): <root xmlns:tpl="url">
<tpl:tag/>
</root> Second way (html style): <root>
<tpl:tag/>
</root> If you choose "pure xml style", my implementation (https://github.com/goetas/twital/blob/master/src/Goetas/Twital/SourceAdapter/HTML5Adapter.php#L25) will fix your issues. If you choose the "html style" where namespaces is not declared, you have to assign a URI to Modifications to html5-php is not required |
I'll have to deal with both styles of documents. But if html5-php already included the namespaces (in an extensible way), we wouldn't have to use either cleanup method. |
@cognifloyd let me think about it this weekend, I have an idea that might work |
#45 is a better and wider solution |
Tires to implement this feature #43
(depends on approval of #37)