A Markdown Preview CLI Tool Built in Go
Use the mdp
CLI tool to preview a Markdown file in the browser.
-
Cross platform: Linux / Macos / Windows.
-
Convert a Markdown file into an HTML file.
-
Support custom templates.
-
mdp
uses bluemonday to sanitize the Markdown content creating a safe HTML file.
- Go version 1.18.6 (or above)
-
Run:
$ go install github.com/rossijonas/mdp@latest
$ mdp
Usage of mdp:
-file string
Markdown file to preview
-s Skip auto-preview
-t string
Alternate template name
$ mdp -file MyFile.md
Using the -s
(skip preview) flag, mdp
generates an HTML file from the given Markdown file and saves the output file in /tmp
directory.
$ mdp -s -file MyFile.md
/tmp/mdp4030496412.html # the HTML file path is printed to the terminal
A custom template file may be used to provide custom styles and layouts.
mdp
accepts a Go html/template file provided using the -t
flag.
$ mdp -file MyFile.md -t template.tmpl
The content of the markdown file must be defined in the template file inside de <body>
tags as {{ .Body }}
.
Ex.: custom.tmpl
...
</head>
<body>
{{ .Body }}
</body>
<footer>
<p>© 2022</p>
</footer>
-
Add example Gif to README file.
-
Add test case testing an alternate template file.
-
Update the default template by adding another field that shows the name of the file being previewed.
-
Allow the user to specify a default template using an environment variable.
-
Allow the user to provide the input Markdown via STDIN.
This is an exercise from the book "Powerful Command-Line Applications in Go", but it may differ from the original exercise.