Skip to content

A small module for styling text with html by using arrays of text style definitions. Commonly necessary for parsing text blocks from content management systems like Takeshape.io and other cm-systems.

License

Notifications You must be signed in to change notification settings

Coderwelsch/styles-to-text

Repository files navigation

Javascript Styles to Text

A small module for styling text with html by using arrays of text style definitions. Commonly necessary for parsing text blocks from content management systems like Takeshape.io and other cm-systems.

Example

Edit react-styles-to-text-example

Install

npm i styles-to-text
# or
yarn styles-to-text

Usage

import stylesToText from "styles-to-text";


const textToStyle = `To be, or not to be, that is the question.`;

const styleDefinitions = [  {
    offset: 0,
    length: 20,
    style: "BOLD"
}, {
    offset: 3,
    length: 17,
    style: "STRIKE"
}, {
    offset: 14,
    length: 15,
    style: "UNDERLINE"
}  ];

// Outputs this:
// <strong>To <del>be, or not <u>to be,</u></del></strong><u> that is the</u> question.
console.log(stylesToText(textToStyle, styleDefinitions));

Contributors are welcome!

Feel free to contribute and improve this little module! 😇

ToDos

  • Documentation :D
  • More features?
  • Tests

About

A small module for styling text with html by using arrays of text style definitions. Commonly necessary for parsing text blocks from content management systems like Takeshape.io and other cm-systems.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published