yuanqing/charming

Split by letters break words

liqueflies opened this issue · 1 comments

Splitting long phrases letters break-words in wrong manner e.g:

Hello
World

Hello Wo
rld

Any ideas to fix this? wrap each word with a div?

I've found a smart way to do that:

const text = document.getElementById('#fancy-text');
charming(text, { splitRegex: /(\s+)/, classPrefix: 'word', tagName: 'div' });
const words = Array.from(document.querySelectorAll('[class*="word"]', text));
words.forEach(function (word) {
  charming(word, { classPrefix: 'letter' });
});