How to remove white space in html using Tritium
Asked Answered
F

2

6

I'm using the Moovweb SDK and I'd like to remove excess white space from the beginning or end of any elements. It sometimes shows up as or and I want to remove it since it messes with my spacing. How can I get around doing this?
Thanks.

Fungible answered 3/5, 2013 at 22:48 Comment(0)
S
4

You can use regex to replace the leading and tailing whitespace with nothing.

Inside a tag, you can open up a text scope and use the replace(...) function to replace leading and trailing whitespace:

text() {
    replace(/^\s+|\s+$/, "")
}

Here's a working example in play.tritium.io:

http://play.tritium.io/648c6b2f72266b7b7db308e14dcb85f71707f4ee

Sheritasherj answered 4/5, 2013 at 9:25 Comment(1)
that solves the problem! To remove all extra/unnecessary space it's easy to, adding |(\s)\s+, like this: replace(/^\s+|\s+$|(\s)\s+/, "$1"). Note the extra $1 that reflects (\s) so we don't end with zero spaces in between words.Azine
D
0
text("   I'm an example             ")
text() {
  trim()
}

can also be used to remove white spaces

Differentiate answered 1/12, 2014 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.