ID: 2109Owner: Samantha
Date: 2013-12-29 02:29:33Priority: Major
Product/Component: Cadre Bugs
A function that converts an HTML string into a DOM and back.

For the input:

x = dom({<a href="/">hel<b>l</b>o</a>});

We might expect:

x[0]._tag == "a";
x[0].href == "/";
x[0][0]._tag == "";
x[0][0]._text == "hel";
x[0][1]._tag == "b";
x[0][1][0]._tag == "";
x[0][1][0]._text == "l";
x[0][2]._tag == "";
x[0][2]._text == "o";

And then the original HTML could be retrieved with a complementary function such as html().

This would make it practical to do many document-crawling and modification tasks that currently require Javascript. Note that PHP and many other server-side languages have a DOM interface; this would be a great opportunity to demonstrate Octavia's potential for brevity.

In an ideal world, the DOM nodes would have a few magic properties:

1. Setting node._id = "foo" or removing a node should cascade upwards so that ancestor_node["#foo"] is always valid and up-to-date.

2. Same for node._class and ancestor_node[".class"], but this would be an array.

3. Special copy() and create() functions.

4. Implement functions for rearranging lists—insert_after(), insert_at(), append(), unshift().

5. Automatic bookkeeping of _parent for retrieving the parent node.

It may be best to do all of this by adding support for Octavia native classes and operator overloading, since this would be a purely linguistic construct.