You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-tiny-markup

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tiny-markup

Parse strings with tags into react components

0.0.11
npmnpm
Version published
Weekly downloads
657
-24.22%
Maintainers
1
Weekly downloads
 
Created
Source

react-tiny-markup

This component aims to parse a simple markup language nontechnical users may input - typically <i> and <b> tags. It will never be a complete HTML5 parser (tag nesting validation, autoclosing tags - none of that). I wanted a smaller (~3kB vs ~60+kB) alternative to sanitize-html.

Security:

It only renders react component without using dangerouslySetInnerHTML, therefore it is secure (unless you use dangerouslySetInnerHTML yourself in the custom renderer)

Examples:

// replace or remove tags
const str = `
  <ooo>inner</ooo>
  <remove>invi<b>s</b>ible</remove>
  <b>left in</b>
`;
<ReactTinyMarkup
  renderer={p => {
    switch (p.tag) {
      case 'ooo':
        return createElement('c', { key: p.key }, p.children);
      case 'remove':
        return null;
      default:
        return createElement(p.tag, { key: p.key }, p.children);
    }
  }}
>
  {str}
</ReactTinyMarkup>
// <c>inner</c><b>left in</b>
// simply parse tags
const str = 'abc<strong>a</strong>b<i>c</i>d<b>e</b>';
<ReactTinyMarkup>{str}</ReactTinyMarkup>
// abc<strong>a</strong>b<i>c</i>d<b>e</b>

// rewrite tag (`strong` in this case) and simply parse the rest
<ReactTinyMarkup
  renderer={p =>
    p.tag === 'strong' ? (
      <i key={p.key}>{p.children}</i>
    ) : (
      defaultRenderer(p)
    )
  }
>
  {str}
</ReactTinyMarkup>
// abc<i>a</i>b<i>c</i>d<b>e</b>

Keywords

html

FAQs

Package last updated on 13 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.