Opened 11 years ago

Closed 5 years ago

#8494 closed defect (fixed)

_Templated: remove whitespace from templates

Reported by: bill Owned by:
Priority: high Milestone: 2.0
Component: Dijit Version: 1.2.3
Keywords: Cc:
Blocked By: Blocking:

Description

Possible future enhancement to _Templated is to remove unwanted whitespace from templates. "Unwanted" is more complicated than it sounds, since for a template like

<span>
   <span>hello</span> <span>world</span>
</span>

we presumably want to remove the beginning and ending spaces in the parent <span>, but leave the space between the two child spans.

See https://developer.mozilla.org/En/Whitespace_in_the_DOM for hints on how to remove spaces.

Besides the problem in #8492, white space in templates also causes unwanted spaces to show up in the final widget (maybe this is an IE only problem?), which is why many of our templates currently eliminate unwanted spaces between nodes by rearranging the > characters, like:

<button
    ><span> ...

I thought there was another ticket open about this, but can't find it.

Change History (3)

comment:1 Changed 11 years ago by Douglas Hays

str.replace(/((>)\r?\n\s*)?((^|\r?\n)\s*(<))?/g,"$2$5")

to remove newlines after a tag and newlines+whitespace before a tag (leaving trailing whitespace after a tag as a workaround to force a text node)

comment:2 Changed 8 years ago by bill

#14891 is a duplicate of this ticket.

comment:3 Changed 5 years ago by bill

Milestone: future2.0
Resolution: fixed
Status: newclosed

I added template trimming in delite but then had to scale it back because people complained that sometimes there was trimming when they didn't want it, see https://github.com/ibm-js/delite/issues/107. Anyway, marking this fixed for 2.0.

Note: See TracTickets for help on using tickets.