Re: [Proto-Scripty] Re: FInd and iterate over ProcessingInstruction nodes?

2011-04-28 Thread Walter Davis
That's a very cool idea, certainly do-able with about 2 lines of Ruby  
code in my pre-processor! Thanks for the suggestion.


Walter

On Apr 28, 2011, at 5:15 AM, T.J. Crowder wrote:


Walter,

Unfortunately, I think you're out of luck, because I don't think
browsers retain processing instructions in the DOM. (Obviously if you
were dealing with the original XML, that would be different.) At
least, when I tried it, Firefox just completely dropped them and
Chrome converted them into comments (and sadly, the Comment node type
doesn't have any properties, so you can't get at them that way).

Which is too bad, because even without Prototype supporting them, it's
not hard to create a DOM walker that would have found them if they
were there:

* * * *
function walk(instructions, node) {
   var child;

   switch (node.nodeType) {
   case Node.PROCESSING_INSTRUCTION_NODE:
   instructions.push(node.data);
   break;
   case Node.ELEMENT_NODE:
   for (child = node.firstChild; child; child =
child.nextSibling) {
   walk(instructions, child);
   }
   break;
   }

   return instructions;
}

var instructions = walk([], document.documentElement);
* * * *

But again, that doesn't work, because the nodes just aren't there as
far as I can tell.

There is an element that you can include /nearly/ anywhere, though:
`script`. And in fact, the HTML5 specification even says[1] that
`script` ... allows authors to include dynamic script AND DATA blocks
in their documents. (My emphasis.)

So you might have your pre-processor convert them into `script`
elements, perhaps of type x-application/procinst, e.g.:

body
 ?pb Edition: current; Page: xxiii?
 h1Now This Is Interesting/h1
 pInteresting stuff here/p
 ?pb Edition: current; Page: xxiv?
 h1Even More Interesting/h1

becomes

body
 script type='x-application/procinst'pb Edition: current; Page:
xxiii/script
 h1Now This Is Interesting/h1
 pInteresting stuff here/p
 script type='x-application/procinst'pb Edition: current; Page:
xxiv/script
 h1Even More Interesting/h1

A quick test (http://jsbin.com/ijolu3) indicates that even IE6 knows
to leave `script` contents of an unknown type alone. I tried that on
current versions of Chrome, Firefox, and Safari, as well as IE6, IE7,
and IE9.

It isn't, strictly speaking *valid* because (for instance) you can't
have a `script` element that's an immediate child of a `ul`. But
firstly, that seems like an error in the spec (why not?), and
secondly, the browsers don't seem to mind.

[1] http://www.w3.org/TR/html5/scripting-1.html#script

FWIW,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Apr 28, 3:26 am, Walter Davis wa...@wdstudio.com wrote:

That would work if I was grepping through the source, but I'm trying
to pick this thing out of the DOM so I can hook onto it and add a
visible element near it. I can't seem to find a way to access it
there. Thanks for the suggestion, though.

Walter

On Apr 27, 2011, at 8:32 PM, kstubs wrote:








Probably your best best is REGEX



result = subject.match(/\?[a-zA-Z0-9 :;]*\?/img);


result is an array of matches.  So, result[0], result[1], and so  
on...



--
You received this message because you are subscribed to the Google
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
.
For more options, visit this group 
athttp://groups.google.com/group/prototype-scriptaculous?hl=en
.


--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: FInd and iterate over ProcessingInstruction nodes?

2011-04-28 Thread Walter Davis
Aha, I just read further, and it appears this won't work for what I'm  
doing, which is in part creating a valid XHTML branch to build epub  
documents, PrinceXML PDF documents, etc. from. I could certainly strip  
these out when building those iterations, but I guess I'll keep  
looking and see if I can figure out another way to go.


Walter

On Apr 28, 2011, at 5:15 AM, T.J. Crowder wrote:


It isn't, strictly speaking *valid* because (for instance) you can't
have a `script` element that's an immediate child of a `ul`. But
firstly, that seems like an error in the spec (why not?), and
secondly, the browsers don't seem to mind.


--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: FInd and iterate over ProcessingInstruction nodes?

2011-04-28 Thread T.J. Crowder
Hi,

Yeah, I don't think there's any valid way to do this in XHTML without
a lot of work. You could turn them into namespaced non-HTML XML
elements as discussed here[1], but metadata content isn't valid
everywhere, so that wouldn't be *quite* valid. (Might be valid
*enough*.)

My backup suggestion was to have your pre-processor attach the content
of the processing instructions as data-xyz attributes, either on their
parent element or the element that follows them, whichever makes more
sense for what you're doing. Not ideal at all, as they'll get
relocated if they appear inside a large block of text, but...

[1] http://www.w3.org/TR/html5/content-models.html#metadata-content

Good luck,

-- T.J. :-)

On Apr 28, 2:15 pm, Walter Davis wa...@wdstudio.com wrote:
 Aha, I just read further, and it appears this won't work for what I'm  
 doing, which is in part creating a valid XHTML branch to build epub  
 documents, PrinceXML PDF documents, etc. from. I could certainly strip  
 these out when building those iterations, but I guess I'll keep  
 looking and see if I can figure out another way to go.

 Walter

 On Apr 28, 2011, at 5:15 AM, T.J. Crowder wrote:







  It isn't, strictly speaking *valid* because (for instance) you can't
  have a `script` element that's an immediate child of a `ul`. But
  firstly, that seems like an error in the spec (why not?), and
  secondly, the browsers don't seem to mind.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: FInd and iterate over ProcessingInstruction nodes?

2011-04-27 Thread Walter Davis
That would work if I was grepping through the source, but I'm trying  
to pick this thing out of the DOM so I can hook onto it and add a  
visible element near it. I can't seem to find a way to access it  
there. Thanks for the suggestion, though.


Walter

On Apr 27, 2011, at 8:32 PM, kstubs wrote:


Probably your best best is REGEX

result = subject.match(/\?[a-zA-Z0-9 :;]*\?/img);


result is an array of matches.  So, result[0], result[1], and so on...

--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.


--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.