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

[WIP] Namespaces #44

Closed
wants to merge 2 commits into from
Closed

[WIP] Namespaces #44

wants to merge 2 commits into from

Conversation

goetas
Copy link
Member

@goetas goetas commented Jun 4, 2014

Tires to implement this feature #43

(depends on approval of #37)

@@ -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');
Copy link
Member Author

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?

@technosophos
Copy link
Member

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.

@cognifloyd
Copy link
Contributor

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.

@goetas
Copy link
Member Author

goetas commented Jun 6, 2014

hi @cognifloyd!
As explained here http://www.w3.org/TR/html5/infrastructure.html#namespaces, html5 explicitly supports a limited set of xml namespaces.

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

@technosophos
Copy link
Member

@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.

@cognifloyd
Copy link
Contributor

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.

@goetas
Copy link
Member Author

goetas commented Jun 6, 2014

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 tpl prefix and do some dom tricky manipulations... (as https://github.com/goetas/twital/blob/master/src/Goetas/Twital/Helper/DOMHelper.php#L41)

Modifications to html5-php is not required

@cognifloyd
Copy link
Contributor

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.

@goetas
Copy link
Member Author

goetas commented Jun 6, 2014

@cognifloyd let me think about it this weekend, I have an idea that might work

@goetas goetas mentioned this pull request Jun 9, 2014
@goetas
Copy link
Member Author

goetas commented Jun 9, 2014

#45 is a better and wider solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants