2.3.1 • Published 3 years ago

remark-emoticons v2.3.1

Weekly downloads
467
License
MIT
Repository
github
Last release
3 years ago

remark-emoticons Build Status Coverage Status

This remark plugin parses ASCII emoticons such as :D or shortcodes such as :smiling-cat:. It can be configured to parse any shortcode/emoticon you wish.

It introduces a new MDAST node type: "emoticon".

This plugin is compatible with rehype, turning the emoticons or shortcodes into HTML <img> tags with customizable classes.

AST node (see mdast specification)

interface emoticon <: Node {
  type: "emoticon";
  value: string;
  data: {
    hName: "img";
    hProperties: {
      src: string;
      alt: string;
      className: string;
    }
  }
}

Syntax

The following Markdown:

:D

if you configured the plugin with:

{
  emoticons: {
    ':D': '/static/smileys/happy.png',
  },
  classes: 'some-smiley foo',
}

will produce this AST node:

{
  type: "emoticon",
  value: ":D",
  data: {
    hName: "img";
    hProperties: {
      src: '/static/smileys/happy.png';
      alt: ":D";
      className: "some-smiley foo";
    }
  }
}

If you use rehype stringifier it will output:

<img src="/static/smileys/happy.png" alt=":D" class="some-smiley foo">

Installation

npm:

npm install remark-emoticons

Usage

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

const remarkEmoticons = require('remark-emoticons')

Usage:

unified()
  .use(remarkParse)
  .use(remarkEmoticons, {
   emoticons: {
     ':D': '/static/smileys/happy.png',
   },
   classes: 'some-class'
  })
  .use(remark2rehype)
  .use(stringify)

License

MIT © Zeste de Savoir

2.3.1

3 years ago

2.3.0

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.0

4 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago