Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

markdown-it-for-inline

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-for-inline

Inline tokens iterator for markdown-it markdown parser.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
decreased by-31.13%
Maintainers
1
Weekly downloads
 
Created
Source

markdown-it-for-inline

CI NPM version Coverage Status

Inline tokens iterator for markdown-it markdown parser.

This plugin allows to apply function to certain types of inline tokens. Speed will be not fastest of possible, but you can do quick prototyping of certain rule types.

Usage

Install

node.js, browser:

npm install markdown-it-for-inline --save
bower install markdown-it-for-inline --save

Use

var iterator = require('markdown-it-for-inline');

// plugin params are:
//
// - rule name (should be unique)
// - token type to apply
// - function
//
var md = require('markdown-it')()
            .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
              tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
            });

Differences in browser. If you load script directly into the page, without package system, module will add itself globally as window.markdownitForInline.

Example 2. Cut link prefixes

var iterator = require('markdown-it-for-inline');

var md = require('markdown-it')({ linkify: true })
            .use(iterator, 'url_beautify', 'link_open', function (tokens, idx) {
              // Make sure link contains only text
              if ((tokens[idx + 2].type !== 'link_close') ||
                  (tokens[idx + 1].type !== 'text')) {
                return;
              }
              // Do replacement
              tokens[idx + 1].content = tokens[idx + 1].content
                                          .replace(/^https?:\/\//, '')
                                          .replace(/^www./, '');
            });

Example 3. Make links open in new window

var iterator = require('markdown-it-for-inline');

var md = require('markdown-it')({ linkify: true })
            .use(iterator, 'url_new_win', 'link_open', function (tokens, idx) {
              tokens[idx].attrPush([ 'target', '_blank' ]);
            });

License

MIT

Keywords

FAQs

Package last updated on 05 Dec 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc