CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-markdown

A sensible Markdown parser for javascript

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

command-line.mddocs/

Command Line Interface

CLI tool for converting markdown files to HTML with dialect selection and flexible input/output handling.

Capabilities

md2html Command

Command-line utility for markdown to HTML conversion.

# Basic usage
md2html [options] [file]

# Options:
#   --dialect=DIALECT  Choose "Gruber" (default) or "Maruku"  
#   --help            Show usage information
#
# Input: File path or stdin when file is "-" or omitted
# Output: HTML written to stdout

Installation:

# Install globally to get md2html command
npm install -g markdown

# Or use locally installed version
npx md2html file.md

Basic File Conversion

Convert markdown files to HTML with automatic output.

Usage Examples:

# Convert file to HTML
md2html document.md > document.html

# Convert with output redirection
md2html README.md > README.html

# Process multiple files (shell loop)
for file in *.md; do
  md2html "$file" > "${file%.md}.html"
done

Dialect Selection

Choose between Gruber (default) and Maruku parsing dialects.

Usage Examples:

# Use default Gruber dialect
md2html document.md

# Use Maruku dialect for extended features
md2html --dialect=Maruku document.md

# Maruku supports tables, metadata, etc.
md2html --dialect=Maruku table.md > table.html

Stdin Processing

Process markdown from standard input for pipeline usage.

Usage Examples:

# Process from stdin
echo "# Hello World" | md2html

# Explicit stdin with dash
echo "**Bold text**" | md2html -

# Pipeline processing
curl -s https://example.com/doc.md | md2html --dialect=Maruku

# Process from here-document
md2html << 'EOF'
# Documentation

This is **important** information.

- Item 1
- Item 2
EOF

Help and Usage Information

Get command help and usage instructions.

# Show help
md2html --help

# Output:
# usage: md2html [--dialect=DIALECT] FILE
#
# Valid dialects are Gruber (the default) or Maruku

Error Handling

The command handles various error conditions:

# File not found
md2html nonexistent.md
# Writes error to stderr, exits with code 1

# Invalid dialect
md2html --dialect=Invalid file.md  
# No error (invalid dialect ignored, uses default)

# Permission errors
md2html /root/restricted.md
# Writes error to stderr, exits with code 1

Advanced Usage Patterns

Complex workflows combining shell features with md2html.

Batch Processing:

#!/bin/bash
# Convert all markdown files in directory tree

find . -name "*.md" -type f | while read -r file; do
  output="${file%.md}.html"
  echo "Converting: $file -> $output"
  md2html --dialect=Maruku "$file" > "$output"
done

Pipeline with Processing:

# Download, process, and format markdown
curl -s https://api.github.com/repos/user/repo/readme |
  jq -r '.content' |
  base64 -d |
  md2html --dialect=Maruku |
  tidy -q -i --show-warnings no

Conditional Dialect Selection:

#!/bin/bash
file="$1"

# Use Maruku for files with tables or metadata
if grep -q '|.*|' "$file" || grep -q '^[A-Za-z]*:' "$file"; then
  dialect="Maruku" 
else
  dialect="Gruber"
fi

echo "Using $dialect dialect for $file"
md2html --dialect="$dialect" "$file"

Template Integration:

#!/bin/bash
# Wrap markdown conversion in HTML template

header='<!DOCTYPE html><html><head><title>Document</title></head><body>'
footer='</body></html>'

echo "$header"
md2html "$1"
echo "$footer"

Implementation Details

The md2html command is implemented in bin/md2html.js and uses the core markdown library:

// Simplified implementation overview
var markdown = require("markdown").markdown;
var nopt = require("nopt");

// Parse command line options
var opts = nopt({
  "dialect": ["Gruber", "Maruku"],
  "help": Boolean
});

// Process input stream
stream.on("end", function() {
  var html = markdown.toHTML(buffer, opts.dialect);
  console.log(html);
});

The command integrates with standard Unix conventions:

  • Reads from files or stdin
  • Writes HTML to stdout
  • Writes errors to stderr
  • Uses appropriate exit codes
  • Supports standard shell redirection and piping

docs

command-line.md

core-api.md

dialects.md

index.md

markdown-class.md

tile.json