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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@celsowm/markdown-wysiwyg

v1.0.6

Published

A simple Markdown WYSIWYG editor with dual-mode editing, toolbar and smart conversion.

Downloads

35

Readme

Markdown WYSIWYG Editor

A versatile JavaScript-based Markdown editor that offers a seamless experience by allowing users to switch between a What-You-See-Is-What-You-Get (WYSIWYG) visual editor and a raw Markdown text editor. It comes with a customizable toolbar, undo/redo functionality, and intelligent Markdown-to-HTML (and vice-versa) conversion.

image

Features

  • Dual Editing Modes:
    • WYSIWYG Mode: Edit rich text visually with familiar formatting tools.
    • Markdown Mode: Directly write and edit Markdown syntax in a textarea.
  • Easy Mode Switching: Instantly toggle between WYSIWYG and Markdown views using intuitive tabs.
  • Comprehensive Toolbar:
    • Headings (H1, H2, H3)
    • Bold, Italic, Strikethrough
    • Hyperlinks
    • Unordered and Ordered Lists
    • Indent and Outdent (for lists)
    • Blockquotes
    • Horizontal Rules
    • Tables (with interactive grid selector)
    • Code Blocks and Inline Code
    • SVG icons for a clean and modern look
  • Smart Conversion:
    • Uses Marked.js for Markdown → HTML
    • Custom-built HTML → Markdown parser
  • Undo/Redo support in both modes
  • Customizable:
    • Initial value
    • Toolbar visibility
    • Toolbar buttons
    • Table grid dimensions
    • onUpdate callback
  • Keyboard Shortcuts:
    • Tab / Shift+Tab: Indent/outdent, table cell nav
    • Ctrl+Z / Cmd+Z: Undo
    • Ctrl+Y / Ctrl+Shift+Z: Redo
  • Lightweight and self-contained

Demo

You can run the index.html file in your browser to see a live demonstration of the editor.
Or online here: demo

Installation / Setup

Include CSS:

<link rel="stylesheet" href="dist/editor.css">

Include JavaScript:

<!-- Dependency: Marked.js -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

<!-- Editor Script -->
<script src="dist/editor.js"></script>

Create an HTML Container:

<div id="myMarkdownEditor"></div>

Initialize via JavaScript:

<script>
document.addEventListener('DOMContentLoaded', () => {
  const editor = new MarkdownWYSIWYG('myMarkdownEditor', {
    initialValue: "## Hello World!\n\nThis is **Markdown** content.",
    onUpdate: (markdownContent) => {
      console.log("Updated content:", markdownContent);
    }
  });
});
</script>

Options

| Option | Type | Default | Description | |--------------------|----------|---------|------------------------------------------| | initialValue | string | '' | The initial Markdown content to load. | | showToolbar | boolean | true | Whether to display the toolbar. | | buttons | array | default | Custom toolbar button list. | | onUpdate | function | null | Callback triggered on content change. | | initialMode | string | 'wysiwyg' | Starting mode: 'wysiwyg' or 'markdown'. | | tableGridMaxRows | number | 10 | Max rows in the insert table selector grid. | | tableGridMaxCols | number | 10 | Max columns in the insert table selector grid. |

Public Methods

  • getValue(): Returns the current Markdown content as string.
  • setValue(markdownString, isInitialSetup): Sets the content of the editor.
  • switchToMode(mode): Switches mode: 'wysiwyg' or 'markdown'.
  • destroy(): Destroys the editor and cleans up listeners.

CDN Usage

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/celsowm/markdown-wysiwyg/dist/editor.css" />
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/celsowm/markdown-wysiwyg@latest/dist/editor.js"></script>

HTML → Markdown Conversion

The _htmlToMarkdown function (and helpers) recursively convert HTML from the visual editor into valid Markdown:

  • Converts tags like <b>, <em>, <h1>, <ul>, <table>, <code>, etc.
  • Detects code blocks and inline code
  • Properly formats nested lists and blockquotes
  • Escapes special characters (|, _, etc.)
  • Handles <th> vs <td> to produce proper Markdown tables

Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create a feature branch
  3. Commit and push
  4. Open a pull request

License

MIT License. See LICENSE file for details.