Giter VIP home page Giter VIP logo

markdown-it-replacements's Introduction

markdown-it-replacements

This markdown-it plugin replaces the "replacements" feature in markdown-it typographer, allowing you to customize the replacement rules (regular expression substitutions) done to inline text outside of autolinks.

There are four built-in replacement rules (mimicking some of the built-in markdown-it typographer):

  • +- → ± (rule "plusminus")
  • ... → … (rule "ellipsis")
  • --- → — (rule "mdash")
  • -- → – (rule "ndash")

Each rule can be turned off by specifying an option object when using the module (mapping each undesired rule name to false). Additional rules can be added by modifying the replacements module attribute (an array of rules, where each rule has a name rule.name, regular expression rule.re, substitution rule.sub, and boolean default on/off rule.default).

Sample Usage

// Without smart quotes
md = require('markdown-it')()
.use(require('markdown-it-replacements'));
md.renderInline('Hello... "world"---');
          // -> 'Hello… "world"—'

// With smart quotes
md = require('markdown-it')({typographer: true})
.use(require('markdown-it-replacements'));
md.renderInline('Hello... "world"---');
          // -> 'Hello… “world”—'

// Using options to turn specific replacements on/off
md = require('markdown-it')({typographer: true})
.use(require('markdown-it-replacements'), {mdash: false});
md.renderInline('Hello... "world"---');
          // -> 'Hello… “world”---'

// Adding custom replacements
mir = require('markdown-it-replacements');
mir.replacements.push({
  name: 'allcaps',
  re: /[a-z]/g,
  sub: function (s) { return s.toUpperCase(); },
  default: true
});
md = require('markdown-it')({typographer: true}).use(mir);
md.renderInline('Hello... "world"---');
          // -> 'HELLO… “WORLD”—'

Notes

  • Unlike the built-in replacements rule, this module does not require the global typographer option to be set to true. (The reasoning being that, if you're using this module, you probably want to do the substitutions.) This means that the typographer option effectively controls whether to do smart-quote substitution.

markdown-it-replacements's People

Contributors

edemaine avatar

Watchers

 avatar

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.