wraps each line in a paragraph in an element
npm install textsplitter



TextSplitter is a lightweight library designed to split text into individual characters, words, or lines. It also includes a new feature to preserve HTML tags when using the splitLines function.
You can install TextSplitter using npm or yarn:
``bash`
npm install textsplitter --save`
orbash`
yarn add textsplitter
Import the required functions from 'textsplitter':
`javascript`
import { splitLetters, splitWords, splitLines } from 'textsplitter';
Use the following functions according to your requirements:
- splitLetters(container, openingtag, closingtag): Splits individual characters.splitWords(container, openingtag, closingtag)
- : Splits words.splitLines(container, openingtag, closingtag)
- : Splits lines while preserving HTML tags.
React usage example:
`javascript
useEffect(() => {
const lines = splitLines(ref.current, openingtag, closingtag);
// If not calculating correctly, this might be an issue with fonts that are not ready yet
document.fonts.ready.then(() => {
splitLines(ref.current, openingtag, closingtag);
});
return () => {
// Destroy lines (return to its initial state)
lines.destroy();
};
}, []);
`
`javascript``
splitLines(document.getElementById("container"), "
MIT © Niels Reijnders
---
If you're looking for a lightweight library to split text into characters, words, or lines while preserving HTML tags, TextSplitter is the right choice! Easily integrate it into your projects using npm or yarn.