What is remark-smartypants?
The remark-smartypants package is a plugin for the remark markdown processor that automatically converts ASCII punctuation characters into 'smart' typographic punctuation. This includes converting straight quotes to curly quotes, double hyphens to en dashes, triple hyphens to em dashes, and more.
What are remark-smartypants's main functionalities?
Curly Quotes
This feature converts straight double quotes to curly double quotes. In the example, the straight quotes around 'Hello, world!' are converted to curly quotes.
const remark = require('remark');
const smartypants = require('remark-smartypants');
const markdown = '"Hello, world!"';
const result = remark().use(smartypants).processSync(markdown).toString();
console.log(result); // “Hello, world!”
En Dashes
This feature converts double hyphens to en dashes. In the example, '2010--2020' is converted to '2010–2020'.
const remark = require('remark');
const smartypants = require('remark-smartypants');
const markdown = '2010--2020';
const result = remark().use(smartypants).processSync(markdown).toString();
console.log(result); // 2010–2020
Em Dashes
This feature converts triple hyphens to em dashes. In the example, 'Wait---what?' is converted to 'Wait—what?'.
const remark = require('remark');
const smartypants = require('remark-smartypants');
const markdown = 'Wait---what?';
const result = remark().use(smartypants).processSync(markdown).toString();
console.log(result); // Wait—what?
Other packages similar to remark-smartypants
typogr
The typogr package provides similar functionality by improving the typography of text. It converts straight quotes to curly quotes, hyphens to en and em dashes, and more. Unlike remark-smartypants, typogr is not specifically designed for markdown processing but can be used in a broader range of text processing tasks.
smartypants
The smartypants package is a standalone library that converts ASCII punctuation characters into 'smart' typographic punctuation. It offers similar features to remark-smartypants but is not integrated with the remark ecosystem, making it more suitable for general text processing rather than markdown-specific tasks.
remark plugin to implement SmartyPants. Now with 100% more ESM!
Installing
npm install remark-smartypants
yarn add remark-smartypants
Usage
Example using remark:
import remark from "remark";
import smartypants from "remark-smartypants";
const result = await remark().use(smartypants).process("# <<Hello World!>>");
console.log(String(result));
I created this plugin because I wanted to add SmartyPants to MDX:
import mdx from "@mdx-js/mdx";
import smartypants from "remark-smartypants";
const result = await mdx("# ---Hello World!---", {
remarkPlugins: [smartypants],
});
Note that angle quotes in the former example (<<...>>
) are probably impossible in MDX because there they are invalid syntax.
This plugin uses retext-smartypants under the hood, so it takes the same options:
const result = await remark()
.use(smartypants, { dashes: "oldschool" })
.process("en dash (--), em dash (---)");
License
MIT License, Copyright (c) Matija Marohnić