npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@type-editor/markdown

v0.0.3

Published

This is a refactored version of the ProseMirror's 'markdown' module. Original: https://github.com/ProseMirror/prosemirror-markdown

Downloads

172

Readme

@type-editor/markdown

This is a refactored version of the prosemirror-markdown module.

This module defines a parser and serializer for CommonMark text. It allows converting between Markdown text and ProseMirror documents, enabling Markdown-based editing workflows.

Installation

npm install @type-editor/markdown

Schema

The module provides a schema for CommonMark documents that includes standard block elements (paragraphs, headings, blockquotes, code blocks, lists) and inline elements (text, images, hard breaks) along with marks for emphasis, strong, links, and code.

import { schema } from '@type-editor/markdown';

// Use the markdown schema for your editor
const state = EditorState.create({
  schema: schema
});

Parsing Markdown

The MarkdownParser class converts Markdown text into ProseMirror documents. It uses markdown-it to tokenize the text and then applies custom rules to create the document tree.

Using the Default Parser

import { defaultMarkdownParser } from '@type-editor/markdown';

// Parse markdown text into a ProseMirror document
const doc = defaultMarkdownParser.parse('# Hello World\n\nThis is **bold** text.');

Creating a Custom Parser

import { MarkdownParser } from '@type-editor/markdown';
import { Schema } from '@type-editor/model';
import MarkdownIt from 'markdown-it';

const myParser = new MarkdownParser(
  mySchema,
  MarkdownIt('commonmark', { html: false }),
  {
    // Token specifications
    paragraph: { block: 'paragraph' },
    heading: {
      block: 'heading',
      getAttrs: (token) => ({ level: +token.tag.slice(1) })
    },
    // ... more token specs
  }
);

const doc = myParser.parse('# Custom parsing');

ParseSpec

The ParseSpec interface defines how markdown-it tokens are mapped to ProseMirror nodes and marks:

  • node - Maps to a single node of the specified type
  • block - Wraps content in a block node (uses _open/_close token variants)
  • mark - Adds a mark to the content
  • attrs - Static attributes for the node or mark
  • getAttrs - Function to compute attributes from the token
  • noCloseToken - Indicates the token has no _open/_close variants

Serializing to Markdown

The MarkdownSerializer class converts ProseMirror documents back to Markdown text.

Using the Default Serializer

import { defaultMarkdownSerializer } from '@type-editor/markdown';

// Serialize a ProseMirror document to markdown
const markdown = defaultMarkdownSerializer.serialize(doc);

Creating a Custom Serializer

import { MarkdownSerializer } from '@type-editor/markdown';

const mySerializer = new MarkdownSerializer(
  {
    // Node serializers
    paragraph(state, node) {
      state.renderInline(node);
      state.closeBlock(node);
    },
    heading(state, node) {
      state.write(state.repeat('#', node.attrs.level) + ' ');
      state.renderInline(node, false);
      state.closeBlock(node);
    },
    // ... more node serializers
  },
  {
    // Mark serializers
    strong: { open: '**', close: '**', mixable: true, expelEnclosingWhitespace: true },
    em: { open: '*', close: '*', mixable: true, expelEnclosingWhitespace: true },
    // ... more mark serializers
  }
);

const markdown = mySerializer.serialize(doc);

MarkdownSerializerState

The MarkdownSerializerState class tracks state during serialization and provides helper methods for writing markdown output:

  • write(content) - Write content to the output
  • text(text, escape) - Write text, optionally escaping special characters
  • renderInline(node) - Render inline content of a node
  • renderContent(node) - Render all content of a node
  • closeBlock(node) - Close a block node
  • wrapBlock(delim, firstDelim, node, f) - Wrap content in block delimiters
  • renderList(node, delim, firstDelim) - Render a list structure
  • esc(str) - Escape special markdown characters
  • repeat(str, n) - Repeat a string n times

Supported Elements

The default schema and serializers support the following CommonMark elements:

Block Elements

  • Paragraphs
  • Headings (levels 1-6)
  • Blockquotes
  • Code blocks (fenced with ```)
  • Horizontal rules
  • Ordered lists
  • Bullet lists
  • List items

Inline Elements

  • Text
  • Images
  • Hard breaks

Marks

  • Strong (bold)
  • Emphasis (italic)
  • Code (inline code)
  • Links

API Reference

Exports

// Schema
export { schema } from './schema';

// Parsing
export { MarkdownParser } from './from-markdown/MarkdownParser';
export { defaultMarkdownParser } from './from-markdown/default-markdown-parser';
export { markdownToPmNodesSchema } from './from-markdown/schema/markdown-to-pm-nodes-schema';

// Serializing
export { MarkdownSerializer } from './to-markdown/MarkdownSerializer';
export { MarkdownSerializerState } from './to-markdown/MarkdownSerializerState';
export { defaultMarkdownSerializer } from './to-markdown/default-markdown-serializer';
export { markdownSchemaNodes } from './to-markdown/schema/markdown-schema-nodes';
export { markdownSchemaMarks } from './to-markdown/schema/markdown-schema-marks';

// Types
export type { ParseSpec } from './types/ParseSpec';

License

MIT