A sensible Markdown parser for javascript
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
CLI tool for converting markdown files to HTML with dialect selection and flexible input/output handling.
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 stdoutInstallation:
# Install globally to get md2html command
npm install -g markdown
# Or use locally installed version
npx md2html file.mdConvert 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"
doneChoose 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.htmlProcess 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
EOFGet command help and usage instructions.
# Show help
md2html --help
# Output:
# usage: md2html [--dialect=DIALECT] FILE
#
# Valid dialects are Gruber (the default) or MarukuThe 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 1Complex 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"
donePipeline 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 noConditional 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"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: