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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mth-live-cli

v1.0.2

Published

A CLI tool to convert Markdown files to HTML

Downloads

20

Readme

mth-cli

mth-cli is a command-line tool that converts Markdown files to HTML. It supports custom HTML templates, batch conversion of files, and a watch mode to automatically update HTML when Markdown files are modified.

Features

  • Convert single or multiple Markdown files to HTML.
  • Use custom HTML templates.
  • Watch mode for real-time file conversion on changes.
  • Batch conversion of all Markdown files in a directory.
  • Custom CSS support.

Installation

First, install the package globally using npm:

npm install -g mth-live-cli

This will install the mth-cli command globally on your system.

Usage

Using a Configuration File - mthclirc.json

Create a mthclirc.json file in the root of your project. To simplify the command line usage, you can use the configuration file instead of using flags:

{
    "watch": true,
    "single": false,
    "template":"path/to/template.html",
    "css": [
        "./styles.css"
    ],
    "live": true,
    "port": 8080
}

The CLI requires atleast two argumnents: inputDir and outputDir.

Basic Command

mth-cli <inputDir> <outputDir> [options]
  • : The directory containing Markdown files or a single Markdown file.
  • : The directory where the converted HTML files will be saved.

Options

| Option | Alias | Description | Default | | ------------ | ----- | ------------------------------------- | --------------------------- | | --single | -s | Convert a single Markdown file | false | | --template | -t | Path to a custom HTML template | src/template/default.html | | --css | -c | Path to a custom CSS file | "" | | --watch | -w | Watch the input directory for changes | false | | --live | -l | Enable live server functionality | false | | --port | -p | Port number for the live server | 8080 | | --help | | Show help | | | --version | | Show version number | |

Examples

1. Convert a Single Markdown File

Convert a single file named README.md into HTML:

mth-cli -s README.md output/

This will create output/README.html.

2. Convert Multiple Markdown Files

Convert all .md files in the docs directory to HTML files in the output directory:

mth-cli docs/ output/

This will convert all the Markdown files in docs and output the corresponding .html files to the output/ directory.

3. Using a Custom HTML Template

To specify a custom template, use the --template option. For example, if you have a custom template file template.html, run:

mth-cli docs/ output/ --template template.html

NOTE: In your template, use {{title}}, {{content}} and {{script}} , as a placeholders for the converted Markdown content:

<html>
  <head>
    <title>{{title}}</title>
  </head>
  <body>
    <h1>Markdown Output</h1>
    <div id="content">{{content}}</div>
    <script>{{script}}</script>
  </body>
</html>

4. Watching for File Changes

To automatically convert files when changes are detected, use the --watch option:

mth-cli docs/ output/ --watch

Any time a Markdown file in the docs/ directory is modified, the corresponding HTML file will be regenerated in the output/ directory.

5. Using Live Server

To start a live server for real-time viewing, use the --live and --port (default is 8080) options:

mth-cli docs/ output/ --live --watch

This will start a live server at http://localhost:8080 where you can view the converted HTML files. The page will automatically refresh when changes are detected.

NOTE: The live server will only work if the --watch option is also set.

6. Adding CSS Styles

You can enhance the appearance of your generated HTML files by including CSS stylesheets. To do this, simply provide the paths to your CSS files when running the CLI tool.

mth-cli --input ./path/to/markdown --output ./path/to/html --css ./path/to/styles.css

In this example:

Replace your-cli-tool with the actual name of your CLI tool.

  • input specifies the path to your Markdown files.
  • output specifies the directory where you want the generated HTML files to be saved.
  • css allows you to specify one or more CSS files to include in the generated HTML.

Multiple CSS Files

You can also provide multiple CSS files like this in the configuration file:

{
  "css": ["tmp/style-1.css", "tmp/style-2.css", "tmp/dir/style-3.css"]
}

This will include both styles1.css and styles2.css in your HTML files. Also this works only the current directories, i.e. tmp and tmp/dir will have different CSS files.

7. Command Help

Run the following command to see all available options:

mth-cli --help

Development

If you want to work on the tool locally:

1. Clone this repository:

git clone https://github.com/satyammattoo/mth-cli.git

2. Install dependencies:

npm install

3. Link the project:

npm link

3. Build and run the project:

npm run dev

4. Run the tool locally:

mth-cli <inputDir> <outputDir> [options]

Contributing

Feel free to open issues or submit pull requests for bug fixes, improvements, or new features. Contributions are welcome!

Author

Satyam Mattoo