3.0.0 • Published 5 years ago

stupid-rich-text v3.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Stupid Rich Text

A simple rich text format. Describe your content using a tree of objects.

This project mostly just contains a set of flow-types for these objects, and some helper methods to create them.

Installation

npm i stupid-rich-text

Nodes

There are four base nodes: 1. Null Node 2. String Node 3. Paragraph Node 4. Emphasized Node

They looks something like:

const nullNode = {
  type: 'null',
  children: [],
};
const stringNode = {
  type: 'string',
  content: 'A string!',
};
const paragraphNode = {
  type: 'paragraph',
  children: [],
};
const emphasizedNode = {
  type: 'emphasized',
  method: 'bold',
  children: [],
};

An example tree might be:

const nodeTree = {
  type: 'null',
  children: [
    {
      type: 'paragraph',
      children: [
        {
          type: 'string',
          content: 'First paragraph!',
        },
      ],
    },
    {
      type: 'paragraph',
      children: [
        {
          type: 'string',
          content: 'Second paragraph with a ',
        },
        {
          type: 'emphasized',
          method: 'bold',
          children: [
            {
              type: 'string',
              content: 'BOLD',
            },
          ],
        },
        {
          type: 'string',
          content: ' string!',
        },
      ],
    },
  ],
};

Which might render to the following markdown (if a markdown renderer is used):

First paragraph!

Second paragraph with a **BOLD** string!
3.0.0

5 years ago

2.1.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago