An open API service indexing awesome lists of open source software.

https://github.com/sibteali786/markdown-preview

mdp is a lightweight and cross-platform command-line tool for previewing Markdown files as HTML. It supports flexible input methods, including file-based input and STDIN, and allows customization of HTML templates via flags or environment variables
https://github.com/sibteali786/markdown-preview

golang

Last synced: 11 months ago
JSON representation

mdp is a lightweight and cross-platform command-line tool for previewing Markdown files as HTML. It supports flexible input methods, including file-based input and STDIN, and allows customization of HTML templates via flags or environment variables

Awesome Lists containing this project

README

          

# Markdown Preview Tool (`mdp`)

`mdp` is a lightweight and cross-platform command-line tool for previewing Markdown files as HTML. It supports flexible input methods, including file-based input and `STDIN`, and allows customization of HTML templates via flags or environment variables.

---

## Features

- **Preview Markdown Files:** Convert Markdown to HTML and open it in your default browser.
- **Support for STDIN:** Pipe Markdown content directly to the tool for quick previews.
- **Custom Templates:** Use custom HTML templates to style your output.
- **Cross-Platform Compatibility:** Works on Linux, macOS, and Windows.
- **Safe HTML Output:** Sanitizes output using `bluemonday` for security.
- **Quick Installation:** Install easily via Go.

---

## Installation

To install `mdp`, use the following command:

```bash
go get github.com/sibteali786/mdp
```

---

## Usage

### Basic Usage

Preview a Markdown file:

```bash
mdp -file example.md
```

### Using STDIN

Pipe Markdown content directly:

```bash
echo "# Hello World" | mdp
```

### Skipping Browser Preview

Generate the HTML without opening it in the browser:

```bash
mdp -file example.md -s
```

### Custom Templates

Use a custom HTML template file:

```bash
mdp -file example.md -t /path/to/template.html
```

Set a default template via an environment variable:

```bash
export MDP_TEMPLATE=/path/to/template.html
mdp -file example.md
```

### Priority of Input Methods

1. **`-file` flag:** If specified, the file is used as input.
2. **`STDIN`:** If no file is specified, `STDIN` is used.
3. If neither is provided, the tool exits with a usage message.

---

## Example

### Input Markdown (`example.md`)

```markdown
# Markdown Preview Tool

This is a simple tool to preview Markdown files as HTML.

## Features:

- Convert Markdown to HTML
- Use custom templates
- Secure output

## Example Code Block:
```

go run main.go

```

```

### Output HTML

```html



Markdown Preview Tool


Previewing file: example.md


Markdown Preview Tool


This is a simple tool to preview Markdown files as HTML.


Features:



  • Convert Markdown to HTML

  • Use custom templates

  • Secure output


Example Code Block:


go run main.go


```

---

## Testing

Run unit and integration tests:

```bash
go test
```

---

## Contributing

Contributions are welcome! Feel free to open issues, suggest features, or submit pull requests.

---

## License

This project is licensed under the [MIT License](LICENSE).

---

## Acknowledgments

- [Blackfriday Markdown Processor](https://github.com/russross/blackfriday)
- [Bluemonday HTML Sanitizer](https://github.com/microcosm-cc/bluemonday)

### Background
This tool was my attempt to learn `Go` and its abilities from the book `Powerful Command - Line Applications in Go`. I have also implemented challenges from exercise in the book and added support for
- Read markdown input from Stdin
- Use template from env set variable
- Showing current Filename at top of the Preview