markdown-match-pairs
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

markdown-match-pairs

CI NPM version Coverage Status

This is a plugin that fixes the logic for bold text in markdown-it.

Issue

By default, markdown-it identifies whether ** can be closed based on the following rules:

  • If there is a space on the left, then open = true
  • If there is a space on the right, then close = true
  • If neither side has a space, it checks for special characters such as +-= or other language separators for example Chinese semicolons . If these symbols are present, they are treated as spaces.

This leads to the following parsing results:

render('**==foo==**') === '<p>**<mark>foo</mark>**</p>';
render('**中文:**中文') === '<p>**中文:**中文</p>';

In reality, we expect both cases to output a strong tag.

Implementation Logic

The implementation logic is as follows: insert a function before balance_pairs. After completing inline rule parsing, adjust the delimiters. After adjustment, whether ** can be closed depends on whether there was an open ** before it.

After using this plugin, the above examples will output as follows:

render('**==foo==**') === '<p><strong><mark>foo</mark></strong></p>';
render(' **Chinese:** Chinese ') === ' < p > < strong > Chinese: </ strong > Chinese </ p > ';

Install

npm install markdown-match-pairs --save

Usage

var md = require('markdown-it')()
.use(require('markdown-it-mark'));

Testing

This plugin has copied all existing test cases from the markdown-it repository to ensure that old test cases pass.

License

MIT

Package Sidebar

Install

npm i markdown-match-pairs

Weekly Downloads

3

Version

1.0.2

License

ISC

Unpacked Size

8.15 kB

Total Files

6

Last publish

Collaborators

  • shepherdwind