XHTMLJS: Updated to v0.3

by Jon Davis 22. March 2008 23:17

I've updated XHTMLJS to version 0.3.

http://cachefile.net/scripts/xhtmljs/0.3/

Try the XHTML editor.

This implements the full strict tagset listed at:

http://www.htmldog.com/reference/htmltags/

It still has some flaws, but this mainly resolves what I observed previously, "a few more failures beyond indentation, namely some XHTML-accepted tags (like <input>) are still going missing in strict mode. The Editor should allow for the de-toggling of strict mode, and IMO I think enabling strict mode for the jQuery extension was a mistake. Also, plain-text '>' (&gt; in markup) is not outputting as '&gt;' but as '>'. "

There are still indentation bugs and missing event handlers, among a few other glitches, but this is an important milestone.

UPDATE: The editor itself had a bug I just fixed (kept the 0.3 version designation) where it would only XHTMLize the first node entered. This required no change to xhtml.js.

kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Pet Projects | Open Source | Web Development

XHTMLJS: New Javascript XHTML editor

by Jon Davis 15. March 2008 17:49

I just pushed a v0.2 of the DOM-to-XHTML conversion script.

  • New real-time XHTML editor! -- Type bad HTML into one textbox, see good XHTML come out the other textbox
    • I needed this so that I can test the XHTMLization with arbitrary markup, but the net result is a really handy tidy page that anyone an use without writing Javascript code
  • Moved the function declarations to an object variable at window.xhtmljs
  • Fixed an "[object]" output bug where there is no text and no HTML tag name
  • Extended jQuery using .fn. rather than .prototype.

http://cachefile.net/scripts/xhtmljs/

In the next round of tweaks I'll clean the formatting logic as there are some indentation errors. Awfully handy, somehow I overlooked it.

Update: Ugh, a few more failures beyond indentation, namely some XHTML-accepted tags (like <input>) and attributes (like onxxxx event handlers) are still going missing in strict mode. The Editor should allow for the de-toggling of strict mode, and IMO I think enabling strict mode for the jQuery extension was a mistake. Also, plain-text ">" (&gt; in markup) is not outputting as "&gt;" but as ">".

kick it on DotNetKicks.com

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Web Development

innerXHTML DOM-to-XHTML Generator in Javascript

by Jon Davis 13. March 2008 00:25

Developers often need XHTML-compliant HTML markup when they fetch DOM elements' innerHTML. Since the W3C hasn't standardized on this property (and I don't know why?!), the browsers have been inconsistent in their approaches to innerHTML. Firefox doesn't put the trailing slash in <br> tags, for instance, while Internet Explorer shows tags in all-caps and strips the quotation marks from some attributes.

This week after my rant got posted on Ajaxian.com, I figured I'd do my part to express my sincerity with the situation of by creating innerXHTML() and outerXHTML() functions in Javascript. Not the first-ever effort, but seemed appropriate considering the strong weight of my public rant. I intended to add it to the prototype of HTMLElement, but *gasp* .. wouldn't you know it, Internet Explorer doesn't expose a prototype for DOM elements!! Ack!! (Dang it, IE team, get out of your cave. :P )

So, take it or leave it, I wrote the innerXHTML() and outerXHTML() functions anyway, added them to the HTMLElement prototype for browsers that support it (yay Firefox), and added xhtml() for innerXHTML() equivalence for jQuery.

I posted it up at http://cachefile.net/scripts/xhtmljs/ with a lightweight test for initial coding efforts. More code than desirable is devoted to formatting (pretty line breaks and tabs), and if you don't like any of that fluff you can turn it off by setting the global variable xhtmlFormatting to "none" or, for now, to anything other than "formatted".

http://cachefile.net/scripts/xhtmljs/ 

Hope everyone likes it. Please give feedback (ideas, concerns, complaints, bug reports, etc) to jon@jondavis.net. I might post this on CodePlex if I get a lot of feedback, but in the absence of feedback I don't see much point.  

kick it on DotNetKicks.com

Currently rated 4.0 by 4 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , , , ,

Web Development

Extending XHTML Without A DTD

by Jon Davis 23. September 2007 23:33

Until Sprinkle I never did much with extending the HTML DOM with my own tags or attributes. When XML was introduced several years ago, people tried to "explain" it by just throwing in custom tags in their HTML and saying, "This is how the new semantic web is gonna look like, see?

<books><ol><book><li>My Book</li></book><book><li>My Other Book</li></book></ol></books>

Of course, that's not the greatest example, but at any rate, from this came XHTML which basically told everyone to formalize this whole XMLization of HTML markup so that custom tags can be declared using a strict DTD extention methodology. Great idea, only instead of picking the ball up and running with it for the sake of extensibility, people instead ran the other way and enforced strictness alone. So XHTML turned out to be a strictness protocol rather than an extensibility format.

Literally, even the latest, shiniest new web browsers, except for Opera (congratulations, Opera) have trouble dealing with inline XHTML extensions. At sprinklejs.com, the following at the top of the document causes a problem:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[ <!ATTLIST div src CDATA #IMPLIED > <!ATTLIST div anticache CDATA #IMPLIED > <!ATTLIST div wraptag CDATA #IMPLIED > <!ATTLIST div apply CDATA #IMPLIED > <!ATTLIST input anticache CDATA #IMPLIED > <!ATTLIST input apply CDATA #IMPLIED >]>

The problem? Just go try and run that and you'll see what the problem is. The stupid web browser doesn't even speak XHTML. It sees those ATTLIST tags and thinks aww heck this must be malformatted HTML 4.01 markup, so it tries to "clean" it up in-memory by closing out the DOCTYPE before it reaches the "]>". So, when it does reach the "]>", it thinks, "Huh. Odd. What's that doing here? I haven't reached a <body> tag yet. That must be a markup error. I'll just go and 'clean' that up by moving it to the top of the body." So it gets rendered as text.

If you do a Javascript alert(document.body.innerHTML); you'll see that it became content rather than treated as an XHTML pre-parser definition. W3C validator thinks it's just hunky dory, but IE7 / FF2 / Safari 3 simply don't have a clue. (Morons.)

But heck. It handles the custom tags without the declaration just fine. These browsers don't balk at the Sprinkle script when the XHTML extensions aren't declared. And the breaking point is just extra content, right?

So I "fixed" this by simply clearing that ugly bit out. Here we go:

function dtdExtensionsCleanup() { // tested on MSIE 6 & 7, Safari 3, Firefox 2 if ((document.body.innerHTML.replace(/ /g, '').replace(/\n/g, "").substr(0, 5) == "]&gt;") ||  ( document.body.innerHTML.substr(0, 11) == "<!--ATTLIST" ||   document.body.innerHTML.substr(0, 11) == "<!--ELEMENT" )) {  var subStrStartIndex = document.body.innerHTML.indexOf("&gt;",    document.body.innerHTML.indexOf("]"));  var subStrHtml = document.body.innerHTML.substring(subStrStartIndex + 4);  document.body.innerHTML = subStrHtml; } else {  // Opera 9.23 "just works" }}

kick it on DotNetKicks.com

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , ,

Web Development


 

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
 
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."

Jon was previously employed as a senior .NET developer at a very well-known Internet services company whom you're more likely than not to have directly done business with. However, this blog and all of jondavis.net have no affiliation with, and are not representative of, his former employer in any way.

Contact Me 


Tag cloud

Calendar

<<  October 2018  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar