Recognizing punctuation using LabelWords

LabelWords appears to include end punctuation (or any punctuation) directly adjacent to a word as part of the label. Is it possible to distinguish between letters and other characters (commas, quotation marks, periods, questions marks, exclamation marks, dashes...) when using label words?

I think we just split on space. What would you suggest? Should they be a "word" on their own? You can pre-split the string yourself... that is probably the best thing to do rather than us trying to provide different options.

let text = "hello, this is a test punctuation, etc. Ya.";
text = text.replace(/([^\w\d ])/gi, " $1");
new Label(text).center(); // now has spaces between words and punctuation

image

Splitting on space is a good suggestion. Unfortunately, it doesn't meet my use case. I am creating an instructional tool and need the text to appear as natural as possible so young students are working with conventional spacing. When modifying a label created with LabelWords is it possible to do it conditionally? For example, part of the label turns one color and any part that matches predetermined characters turns a different color or remains the same color? If not, it would be amazing to be able to set a LabelWords parameter to distinguish between letters and punctuation marks/ characters that are not letters.

For LabelWords, each item is a Label which cannot have different colors. But LabelLetters can, so I think you would end up with labelLetters if you want proper spacing but different colors. Have a look there and see if you come up with ideas. If you are stuck, let us know and we can try making an example.

https://zimjs.com/docs.html?item=LabelLetters

1 Like

Will do. Thanks!