GithubHelp home page GithubHelp logo

madiodio / remark-twemoji Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 1.0 110 KB

Remark plugin to replace your emoji by using Twemoji.

JavaScript 100.00%
remark twemoji remark-twemoji mdx remark-plugin emoji

remark-twemoji's Introduction

remark-twemoji

prettier npm travis

Remark plugin to replace your emoji by using twemoji.

Install

Note: Although it is marked as a peerDependency, twemoji is required to work with this module.

npm install --dev remark-twemoji twemoji 

Usage

remark().use(remarkTwemoji, { options });
  1. Basic usage
const remark = require("remark");
const twemoji = require("remark-twemoji");

const doc = "๐Ÿ˜‚";
remark()
  .use(twemoji)
  .process(doc, function(err, file) {
    console.log(String(file));
  });
// => <img class="emoji" draggable="false" alt="๐Ÿ˜‚" src="https://twemoji.maxcdn.com/2/128x128/1f602.png" title="๐Ÿ˜‚"/>
  1. Usage with mdx (basically what this plugin has been for):

Somewhere in your webpack config file:

const webpack = require("webpack");
const twemoji = require("remark-twemoji");

...{
  test: /\.md$/,
  exclude: /node_modules/,
  use: [
    "babel-loader",
    {
      loader: "@mdx-js/loader",
      options: {
        mdPlugins: [twemoji],
        isReact: true
      }
    }
  ]
},...

For more informations, check this section on the mdx docs.

Options

options.isReact (boolean)

When using this plugin in a React setup, Twemoji will parse a dom node containing the attribute class instead of className which causes a warning at runtime. So if you're using React in your setup, use this to instruct the plugin to replace class by className in the final node, eg: ...[twemoji, { isReact: true }]...

Other options

Object

  {
    callback: Function,   // default the common replacer
    attributes: Function, // default returns {}
    base: string,         // default MaxCDN
    ext: string,          // default ".png"
    className: string,    // default "emoji"
    size: string|number,  // default "36x36"
    folder: string        // in case it's specified
                          // it replaces .size info, if any
  }

These are the options you can pass to this plugin as the twemoji options, you can read more about them here.

Inspirations

License

MIT

remark-twemoji's People

Contributors

denis-sokolov avatar dependabot[bot] avatar madiodio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sebastinez

remark-twemoji's Issues

remark-twemoji is not installed?

I'm trying to use remark-twemoji in my Nuxt.js project. However, I'm getting a warning in the console during yarn generate, even after I installed remark-twemoji. No other Remark plugins I installed give errors.

Steps to reproduce:

  1. yarn add --dev remark-twemoji
    Output:

    [...]
    success Saved lockfile.
    success Saved 1 new dependency.
    info Direct dependencies
    โ””โ”€ [email protected]
    info All dependencies
    โ””โ”€ [email protected]
    Done in 62.47s.
    
  2. yarn generate

     WARN  remark-twemoji is not installed
    

Relevant part of my package.json after install:

{
    "devDependencies": {
    "remark-twemoji": "^0.1.1"
  }
}

Relevant part of my nuxt.config.js:

   content: {
        markdown: {
            plugins: [
                'remark-twemoji',
            ],
        },
    },

Running dir node_modules\remark-twemoji gives:

31.05.2020.  13:28    <DIR>          .
31.05.2020.  13:28    <DIR>          ..
31.05.2020.  13:09             1.489 index.js
31.05.2020.  13:27    <DIR>          node_modules
31.05.2020.  13:09             1.125 package.json
31.05.2020.  13:09             2.781 readme.md

Using remark-twemoji with gatsby mdx

I'm trying to use this plugin with gatsby-plugin-mdx
Here's what tha portion of the gatsby-config.js looks like:

    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        extensions: [`.mdx`, `.md`],
        defaultLayouts: {
          default: path.resolve("src/templates/md.js"),
          posts: path.resolve("src/templates/post.js"),
        },
        gatsbyRemarkPlugins: [
          `gatsby-remark-images`,
          `gatsby-remark-prismjs`,
        ],
        remarkPlugins: [require(`remark-twemoji`)],
      },
    },

And... well it works... sorta.
image

The images are far too large for the size of the text.
For some extra context, here's what a pseudo paragraph looks like:
image

remark@next (13)

Hi!

remark is switching to a new parser internally (micromark, see remarkjs/remark#536 for more info).
From a quick glance at the code, it seems this plugin should be fine. However, it would be good to check that in the future (there is 13.0.0-alpha.0 published now, and one or two more will come before the release)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.