ca_redwards
01-13-2003, 07:48 PM
Welcome to version 2.0 of beetle's Code Challenge!
Hang onto your keyboards, this'll be a wild one...
The Challenge --------------
Create a function that rewrites HTML code as a JavaScript "clientlet" (I coined this term to emulate the concept of how Java servlets produce HTML). My HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) allows a clientlet to produce HTML. Your function will take HTML and produce a clientlet.
function html2js(html){
/*your code here*/
return clientlet
}
Three types of clientlet functions must be returned by your function:
1. Attributes TYPE('submit')
produces type="submit" there's a very important leading space before the word "type".
2. Tags INPUT(TYPE('submit')+VALUE('ok')) (TYPE+VALUE is INPUT pararm)
produces <input type="submit" value="ok">
3. Containers INPUT(TYPE('submit')).FORM(ACTION('mailto:')) produces <form action="mailto:"><input type="submit"></form>
Keep this in mind...
The HTML input can contain:
1. embedded JavaScripts,
2. containers (like A B I U),
3. tags (like IMG or INPUT), and
4. text (including new lines and HTML entities).
Hints/suggestions: Code the content of embedded JavaScripts as literal text. Code container contents recursively. Try regular expressions.
You may assume that the HTML input is valid: Containers will be nested properly, and tag attributes will be quoted...
But not necessarily standardized: Tag/attribute names can be upper/lower/mixed case. Whitespace may include new lines (even inside tags!).
Bonus points if you allow for escaped quote characters inside of string literals! Extra credit if your code is bookmarklet-ready (no quotes)!
The Rules --------------
Violation of these rules will result in disqualification.
Submissions must be 100% ECMAscript compliant. Code must be self-contained and run error-free on http://www.codingforums.com/images/icons/icon15.gif IE5, http://www.codingforums.com/images/icons/icon16.gif NS6 (or NS7), and MZ1.
Once you've submitted your code, you're done. Your submitted post cannot be edited, and any resubmissions will be ignored (well, unless it involves one character or less!).
Grading
Submitted code will be graded on a scale from 1 to 10. Attention will be paid to the functionality, efficiency, simplicity, and brevity of your approach. Although shorthand is allowed, multiple assignments are discouraged. The winner of this contest will receive the dubious honor of presenting the next one! Also, I'd like to include the winner's function (citing your authorship!) in an upcoming suite of HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) utilities.
http://www.codingforums.com/images/icons/icon2.gif The deadline for this challenge is extended to Sunday, January 26, at 9pm Pacific time.
Good luck! http://www.codingforums.com/images/smilies/thumbsup.gif
Hang onto your keyboards, this'll be a wild one...
The Challenge --------------
Create a function that rewrites HTML code as a JavaScript "clientlet" (I coined this term to emulate the concept of how Java servlets produce HTML). My HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) allows a clientlet to produce HTML. Your function will take HTML and produce a clientlet.
function html2js(html){
/*your code here*/
return clientlet
}
Three types of clientlet functions must be returned by your function:
1. Attributes TYPE('submit')
produces type="submit" there's a very important leading space before the word "type".
2. Tags INPUT(TYPE('submit')+VALUE('ok')) (TYPE+VALUE is INPUT pararm)
produces <input type="submit" value="ok">
3. Containers INPUT(TYPE('submit')).FORM(ACTION('mailto:')) produces <form action="mailto:"><input type="submit"></form>
Keep this in mind...
The HTML input can contain:
1. embedded JavaScripts,
2. containers (like A B I U),
3. tags (like IMG or INPUT), and
4. text (including new lines and HTML entities).
Hints/suggestions: Code the content of embedded JavaScripts as literal text. Code container contents recursively. Try regular expressions.
You may assume that the HTML input is valid: Containers will be nested properly, and tag attributes will be quoted...
But not necessarily standardized: Tag/attribute names can be upper/lower/mixed case. Whitespace may include new lines (even inside tags!).
Bonus points if you allow for escaped quote characters inside of string literals! Extra credit if your code is bookmarklet-ready (no quotes)!
The Rules --------------
Violation of these rules will result in disqualification.
Submissions must be 100% ECMAscript compliant. Code must be self-contained and run error-free on http://www.codingforums.com/images/icons/icon15.gif IE5, http://www.codingforums.com/images/icons/icon16.gif NS6 (or NS7), and MZ1.
Once you've submitted your code, you're done. Your submitted post cannot be edited, and any resubmissions will be ignored (well, unless it involves one character or less!).
Grading
Submitted code will be graded on a scale from 1 to 10. Attention will be paid to the functionality, efficiency, simplicity, and brevity of your approach. Although shorthand is allowed, multiple assignments are discouraged. The winner of this contest will receive the dubious honor of presenting the next one! Also, I'd like to include the winner's function (citing your authorship!) in an upcoming suite of HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) utilities.
http://www.codingforums.com/images/icons/icon2.gif The deadline for this challenge is extended to Sunday, January 26, at 9pm Pacific time.
Good luck! http://www.codingforums.com/images/smilies/thumbsup.gif