Skip to content
/ rmmd Public

A lightweight command-line tool to convert Markdown into HTML. It supports standard input, file processing and advanced options for wrapping output in a full HTML document. Built on unified.js.

License

Notifications You must be signed in to change notification settings

samliebl/rmmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rmmd

rmmd is a lightweight command-line tool to convert Markdown into HTML. It supports standard input, file processing, and advanced options for wrapping output in a full HTML document. Built on unified.js.

Contents

  1. Features
  2. Installation
  3. Usage
  4. Examples
  5. Output Formats
  6. Error Handling
  7. Developer Notes
  8. Contributing
  9. License

Features

  • Convert Markdown to HTML: Quickly process Markdown files or input streams into semantic HTML.
  • Flexible Input Options: Provide input via a file, stdin, or direct piping from another command.
  • File Output: Write the output to a file using the --file or -f option.
  • Full HTML Document Wrapping: Use the --enclose or -e option to wrap the HTML content in a complete, standards-compliant HTML document.
  • Command-line Options:
    • Process a file or piped content by default.
    • --file (-f): Specify a file to write the output.
    • --enclose (-e): Wrap output in a fully compliant HTML document.
    • --version (-v): Output the version.
    • --help (-h): Display help information.
    • Use --custom (-c) to enable custom syntax processing.
    • Leave out --custom to process only basic Markdown.
  • Modern Web Standards: Outputs valid HTML5 for browser compatibility.
  • Custom Markup Syntax:
    • = wraps text in <mark>:
      This is =marked text= in markdown.
      Produces:
      <p>This is <mark>marked text</mark> in markdown.</p>
    • + wraps text in <dfn>:
      This is +a definition text+ in markdown.
      Produces:
      <p>This is <dfn>a definition text</dfn> in markdown.</p>
    • ~ wraps text in <s>:
      This is ~a styled text passage~ in markdown.
      Produces:
      <p>This is <s>a styled text passage</s> in markdown.</p>

Installation

Install rmmd globally using npm:

npm install -g rmmd

This makes the rmmd command available globally on your system.

Usage

Basic Conversion

Convert a Markdown file to HTML:

rmmd example.md

Piping Markdown Content

Pipe Markdown content directly into rmmd:

cat example.md | rmmd

Write to a File

Use the --file or -f option to specify an output file:

rmmd example.md -f output.html

Wrap Output in an HTML Document

Use the --enclose or -e option to wrap the output in a complete HTML document:

rmmd example.md -e

Combine it with file output:

rmmd example.md -e -f wrapped.html

Display Version and Help

Check the version:

rmmd -v

Display help:

rmmd -h

Examples

  1. Convert Markdown to HTML and print to stdout:
    rmmd example.md
  2. Convert Markdown and write output to a file:
    rmmd example.md -f result.html
  3. Convert Markdown, wrap in an HTML document, and print:
    rmmd example.md -e
  4. Convert, wrap, and save to a file:
    rmmd example.md -e -f full-document.html
  5. Pipe Markdown content into rmmd and wrap in a document:
    cat example.md | rmmd -e
  6. Convert Markdown to HTML with basic syntax:
    rmmd example.md
  7. Convert Markdown to HTML with custom syntax:
    rmmd example.md --custom
  8. Wrap the output in an HTML document:
    rmmd example.md --enclose
  9. Combine custom syntax, file output, and HTML wrapping:
    rmmd example.md --custom --enclose --file output.html

Output Formats

Default HTML Output

By default, the tool converts Markdown to clean HTML:

<h1>Hello, World</h1>
<p>This is Markdown rendered as HTML.</p>

Enclosed HTML Output

Using the --enclose option wraps the output in a valid HTML document:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Markdown Output</title>
</head>
<body>
  <h1>Hello, World</h1>
  <p>This is Markdown rendered as HTML.</p>
</body>
</html>

Error Handling

The tool provides helpful error messages:

  • If no input is provided:
    No input provided. Use a file path or pipe Markdown content.
    
  • If the specified file does not exist:
    Error: ENOENT: no such file or directory, open 'example.md'
    
  • If invalid options are passed:
    error: unknown option '--invalid'
    

Developer Notes

The tool is modular, using separate libraries for Markdown processing and HTML wrapping. It follows modern ESM standards.

Project Structure

rmmd/
|-- bin/
|   |-- rmmd.js               # CLI logic
|-- lib/
|   |-- customMarkup.js          # Custom markup manager
|   |-- markdownToHtml.js        # Markdown to HTML conversion
|   |-- remarkMark.js            # <mark> syntax plugin
|   |-- remarkDfn.js             # <dfn> syntax plugin
|   |-- remarkStrikethrough.js   # <s> syntax plugin
|   |-- wrapHtml.js              # HTML wrapping logic

Internal Modules

  • markdownToHtml.js: Handles Markdown-to-HTML conversion.
  • wrapHtml.js: Wraps HTML output in a complete HTML document.

Adding New Syntax

  1. Create a new plugin file in lib/.
  2. Register it in customMarkup.js.
  3. Enable it in the customMarkup function call in markdownToHtml.js.

Contributing

Contributions welcome! Follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature:
    git checkout -b feature-name
  3. Commit your changes:
    git commit -m "Add feature"
  4. Push to your branch:
    git push origin feature-name
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.


Enjoy! -SL

About

A lightweight command-line tool to convert Markdown into HTML. It supports standard input, file processing and advanced options for wrapping output in a full HTML document. Built on unified.js.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published