JSFiddle - React, Tailwind, and code Playground

by jeremyblalock

HTML

<p class='my-text'>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>

CSS

body {
    padding: 70px;
}

JavaScript

var entityMap = {
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': '&quot;',
    "'": '&#39;',
    "/": '&#x2F;'
};

function escapeHTML(string) {
    return String(string).replace(/[&<>"'\/]/g, function (s) {
        return entityMap[s];
    });
}

function findClampChar($el, line) {
    var text = $el.text(),
        chars = $el.text().split(''),
        $el2 = $el.clone().html(''),
        i, str = '';
    for (i = 0; i < chars.length; i += 1) {
        str += '<span>' + escapeHTML(chars[i]) + '</span>';
    }
    $el2.html(str);
    $el.after($el2);
    $el.hide();
    
    for (i = 0; i < chars.length; i *= 2) {
           
    }

}

findClampChar($('.my-text'), 3);