Skip to content

dblume/md-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

License PHP5.3

Render Markdown in a Browser from the Command-line

With this toolset, you can issue a command from the terminal to render markdown in a browser window like so:

md README.md

Installation

There are two parts to this tool. The server side accepts requests with Markdown data and responds with its rendered HTML. The client side is a command that sends the request with Markdown data and opens a browser with the HTML.

The server side is already implemented at md.dlma.com. You just need to add the client snippet.

At the local client

Copy the following text and add it to your .bashrc:

md() {
    declare -r sys_name=$(uname -s)
    if [[ $sys_name == Darwin* ]]; then
        declare -r T=$(mktemp $TMPDIR$(uuidgen).html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        open $T
    elif [[ $sys_name == CYGWIN* ]]; then
        declare -r T=$(mktemp --suffix=.html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        cygstart $T
    else
        declare -r T=$(mktemp --suffix=.html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        if [[ -z "${WSL_DISTRO_NAME}" ]]; then
            gio open $T
            echo "rm \"$T\" >/dev/null 2>&1" | at now + 2 minutes
        else
            # Set BROWSER to your web browser's path
            "$BROWSER" $(realpath --relative-to=$PWD $T)
        fi
    fi
}

And then you have an md command to view the document in a browser, which you can use like:

md README.md

At the server

My implementation of this Markdown tool relies on a small change to Parsedown. The change allows HTML entity decoding to work. E.g., θ becomes θ.

At your web server, make a directory that has Parsedown.php (from the dblume fork) and index.php from this repo.

Is it any good?

Yes.

Licence

This software uses the MIT license

About

A command-line tool for rendering markdown documents in a browser

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages