The OpenD Programming Language

wrapTextNodes

This wraps every non-empty text mode in the document body with <t:t></t:t>, and sets an xmlns:t to the html root.

If you use it, be sure it's the last thing you do before calling toString

Why would you want this? Because CSS sucks. If it had a :text pseudoclass, we'd be right in business, but it doesn't so we'll hack it with this custom tag.

It's in an xml namespace so it should affect or be affected by your existing code, while maintaining excellent browser support.

To style it, use myelement > t\:t { style here } in your css.

Note: this can break the css adjacent sibling selector, first-child, and other structural selectors. For example, if you write <span>hello</span> <span>world</span>, normally, css span + span would select "world". But, if you call wrapTextNodes, there's a <t:t> in the middle.... so now it no longer matches.

Of course, it can also have an effect on your javascript, especially, again, when working with siblings or firstChild, etc.

You must handle all this yourself, which may limit the usefulness of this function.

The second parameter, whatToDoWithWhitespaceNodes, tries to mitigate this somewhat by giving you some options about what to do with text nodes that consist of nothing but whitespace.

You can: wrap them, like all other text nodes, you can ignore them entirely, leaving them unwrapped, and in the document normally, or you can use stripOut to remove them from the document.

Beware with stripOut: <span>you</span> <span>rock</span> -- that space between the spans is a text node of nothing but whitespace, so it would be stripped out - probably not what you want!

ignore is the default, since this should break the least of your expectations with document structure, while still letting you use this function.

void
wrapTextNodes
(,
TextWrapperWhitespaceBehavior whatToDoWithWhitespaceNodes = TextWrapperWhitespaceBehavior.ignore
)

Meta