Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

markdown-it-replacements

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-replacements

Customize replacements in markdown-it typographer

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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.

Keywords

markdown-it

FAQs

Package last updated on 18 Jan 2022

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