Giter Site home page Giter Site logo

md2html's Introduction

md2html Docker Automated build

Convert markdown to HTML using pandoc

  • Javascript-free
  • Syntax highlight
  • TOC
  • GitHub Light & Dark (auto mode)

Install pandoc

brew install pandoc

Useage:

git clone --depth=1 https://github.com/cntrump/md2html.git
cd md2html
./md2html.sh -i /path/to/your.md

md2html.sh

useage:
	md2html [-t 2] [-l zh] [-s] [-f markdown] -i /path/to/markdown.md
options:
	-f FORMAT: specify input format, default: markdown.
	-t N: toc-depth, N less than or equal to 0 means disable toc, default: 2.
	-l en: language tags, default: en.
	-s: create self contained html, inline all resources.
	-h: display this infomation.
example:
	md2html -i ./markdown.md
	md2html -t 2 -i ./markdown.md
	md2html -t 2 -l zh -i ./markdown.md
	md2html -s -i ./markdown.md
	md2html -f docx -i ./document.docx

Install to System Path

Run ./install.sh and input your login password:

Password:
Installed at /usr/local/bin/md2html

Docker

cntrump/md2html

docker pull cntrump/md2html

cd into your markdown file directory.

docker run -i -v "${PWD}:/data" --rm cntrump/md2html -i /path/to/markdown.md

Or create a shell script named md2html:

#!/usr/bin/env zsh

set -e

print_usage_and_exit() {
  echo "useage:"
  echo "\tmd2html [-t 2] [-l zh] [-s] [-f markdown] -i /path/to/markdown.md"
  echo "options:"
  echo "\t-f FORMAT: specify input format, default: markdown."
  echo "\t-t N: toc-depth, N less than or equal to 0 means disable toc, default: 2."
  echo "\t-l en: language tags, default: en."
  echo "\t-s: create self contained html, inline all resources."
  echo "\t-h: display this infomation."
  echo "example:"
  echo "\tmd2html -i ./markdown.md"
  echo "\tmd2html -t 2 -i ./markdown.md"
  echo "\tmd2html -t 2 -l zh -i ./markdown.md"
  echo "\tmd2html -s -i ./markdown.md"
  echo "\tmd2html -f docx -i ./document.docx"
  exit -1
}

INPUT_FORMAT="markdown"
LANG="en"
TOC_DEPTH=2
SELF_CONTAINED=
INPUT=

while getopts "f:t:l:i:hs" arg; do
  case "${arg}" in
    "f")
        INPUT_FORMAT=${OPTARG}
        ;;
    "t")
        TOC_DEPTH=${OPTARG}
        ;;
    "l")
        LANG=${OPTARG}
        ;;
    "i")
        INPUT=${OPTARG:a}
        ;;
    "h")
        print_usage_and_exit
        ;;
    "s")
        echo "[INFO] create self contained html."
        SELF_CONTAINED="-s"
        ;;
    "?")  
        echo "[WARNING] unkonw argument"
        ;;
    esac
done

if [ "${INPUT}" = "" ];then
  echo "[ERROR] no input file."
  print_usage_and_exit
fi

WORK_DIR=${INPUT:a:h}
FILE=${INPUT:a:t}

echo "workdir: ${WORK_DIR}"
echo "file: ${FILE}"

docker run -i -v "${WORK_DIR}:/data" --rm cntrump/md2html \
                                          -t ${TOC_DEPTH} \
                                          -l ${LANG} \
                                          -f ${INPUT_FORMAT} \
                                          ${SELF_CONTAINED} -i "${FILE}"

echo Output: "\033[0;32mfile://${INPUT:a:r}.html\033[0m"
echo Done.

usage:

md2html -i /path/to/markdown.md

md2html's People

Contributors

cntrump avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.