Skip to content

👔 Generate inline elements from plain text using begin & offset

License

Notifications You must be signed in to change notification settings

chitacan/simple-inline

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-inline

Build Status

👔 Generate inline elements from plain text using begin & offset

Usage

const inline = require('simple-inline');

const text = 'hello world';
const styles = [{
  begin: 0,
  offset: 5,
  types: ['underline']
}, {
  begin: 6,
  offset: 5,
  types: ['bold', 'strike']
}, {
  begin: 4,
  offset: 3,
  types: ['italic']
}];

// generate html
const result = inline(text, styles);

Output

<span class="underline">hell</span><span class="underline italic">o</span><span class="italic"> </span><span class="bold strike italic">w</span><span class="bold strike">orld</span>

Install

$ npm i simple-inline

API

inline(text, styles[, options])

const inline = require('simple-inline');

text

type: string

styles

type: object (array)

An item must have begin, offset and types. types is string array and will be <span class="<types>"...

options

returnType

specify return type. html(default) or object.

const result = inline(text, styles, {
  returnType: 'object'
});

Test

$ npm test

License

MIT © Jaewe Heo

About

👔 Generate inline elements from plain text using begin & offset

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%