Registry / serialization / markdown-it-for-inline

markdown-it-for-inline

JSON →
library2.0.1jsnpmunverified

markdown-it-for-inline is a plugin for the markdown-it markdown parser, providing an iterator specifically designed for processing inline tokens. It allows developers to apply custom functions to specific types of inline tokens, such as 'text' or 'link_open', to modify their content or attributes. While the README notes that its speed "will be not fastest of possible," it offers a quick and flexible method for prototyping and implementing custom rendering rules for inline content. The current stable version is 2.0.1, last published approximately two years ago as of late 2023. It maintains a stable API and integrates seamlessly with markdown-it's plugin architecture, focusing on enabling advanced manipulation of parsed inline structures rather than core parsing itself. Its release cadence is tied to stability and markdown-it compatibility, with updates typically addressing bug fixes or compatibility with newer markdown-it versions.

npm install markdown-it-for-inline
INSTALL
IMPORT
SIG · MARKDOWN-IT-FOR-IN
M
markdown-it-for-inline
serializationjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

iterator
import iterator from 'markdown-it-for-inline';
import { iterator } from 'markdown-it-for-inline';
The package exports a default function for use with `markdown-it.use()`. The README examples use a CommonJS `require` call, assigning the result to a variable like `iterator`.
iterator
const iterator = require('markdown-it-for-inline');
This is the CommonJS `require` syntax as shown in the package's README for Node.js environments.
markdownitForInline
const iterator = window.markdownitForInline;
const iterator = require('markdown-it-for-inline'); // In browser
When loaded directly in a browser without a package system, the module exposes itself globally as `window.markdownitForInline`.

Demonstrates how to use markdown-it-for-inline to add 'target="_blank"' to all generated links, making them open in a new browser tab or window.

import MarkdownIt from 'markdown-it'; import markdownitForInline from 'markdown-it-for-inline'; // Initialize markdown-it with linkify enabled to ensure links are parsed const md = new MarkdownIt({ linkify: true }); // Use the plugin to modify 'link_open' tokens // This example makes all links open in a new window by adding target="_blank" md.use(markdownitForInline, 'url_new_win', 'link_open', function (tokens, idx) { // `attrPush` adds a new attribute array or pushes to an existing one tokens[idx].attrPush([ 'target', '_blank' ]); }); const markdownContent = ` Check out my [website](https://example.com) and another link: https://another.org. This should also have target='_blank'. `; const htmlResult = md.render(markdownContent); console.log(htmlResult); // Expected output would have <a href="..." target="_blank">...</a> for links.
Debug
Known issues
gotchaThe plugin's README explicitly states that its speed 'will be not fastest of possible'. For very large documents or high-performance requirements, direct rule manipulation in markdown-it might be more efficient, though more complex.
fix
For critical performance paths, consider implementing custom markdown-it rules directly via `md.core.ruler.after` or `md.inline.ruler.after` for fine-grained control, rather than iterating through tokens.
affects: >=0.1.0
breakingWhile markdown-it-for-inline itself has a stable API, major version changes in its host library, `markdown-it`, can introduce breaking changes in token structures or parsing pipelines that might affect how this plugin interacts with tokens.
fix
Always test `markdown-it-for-inline` thoroughly when upgrading `markdown-it` to a new major version. Refer to `markdown-it`'s migration guides for specific token changes. If issues arise, check the plugin's GitHub issues for compatibility updates or workarounds.
affects: >=0.1.0 (with certain markdown-it versions)
gotchaEach rule registered with `md.use(iterator, 'rule_name', ...)` must have a unique rule name. Reusing a rule name will overwrite the previous rule or cause unexpected behavior without a clear error message.
fix
Ensure that the `rule name` parameter (the second argument to `md.use(iterator, 'rule_name', ...)`) is unique across all `markdown-it-for-inline` plugin instances and other markdown-it plugins.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: md.use is not a function
The markdown-it instance (`md`) has not been correctly initialized, or `md.use` is being called on a non-markdown-it object.
fix
Ensure you `import MarkdownIt from 'markdown-it';` and initialize it as `const md = new MarkdownIt();` before calling `.use()`.
Plugin does not appear to be loading or applying changes.
The specified token type for the iterator might be incorrect, or the logic within the iterator function is not correctly identifying or modifying tokens.
fix
Verify the `token type` (e.g., 'text', 'link_open') against the markdown-it token documentation. Use `console.log(tokens[idx])` inside the iterator function to inspect the token structure and confirm it matches expectations.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
markdown-itrequiredThis package is a plugin for markdown-it and requires it to function. It should be installed alongside markdown-it.
Agent activity
4 hits · last 30 days
node
4
Resources
markdown-it-for-inline — npm install markdown-it-for-inline · libregistry