From f49814b794c65e5baa277b7f6d3b649576ac5bfa Mon Sep 17 00:00:00 2001 From: lshprung Date: Sat, 18 Dec 2021 10:05:47 -0800 Subject: Added basic highlight.js support --- markdown-to-github-html.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/markdown-to-github-html.sh b/markdown-to-github-html.sh index a8b9e37..45ac52a 100755 --- a/markdown-to-github-html.sh +++ b/markdown-to-github-html.sh @@ -8,18 +8,20 @@ CUSTOM_INPUT=0 OUTPUT="/dev/stdout" CUSTOM_OUTPUT=0 COMPILER="marked --gfm" -YES=0 #Set to 1 for --yes flag +ENABLE_JS=0 #Set to 1 for --highlight flag +YES=0 #Set to 1 for --yes flag print_help() { echo "Usage: $NAME [OPTION]... [INPUT]" echo "Compile INPUT markdown file to github-styled html" echo "" - echo " --compiler COMPILER set the markdown compiler to use. Default is marked --gfm" - echo " -c, --css CSS_PATH set the github-markdown.css file path (by default github-markdown.css in the CWD)" - echo " -h, --help print this help message" - echo " -i, --input INPUT specify INPUT file" - echo " -o, --output OUTPUT output to specified OUTPUT file" - echo " -y, --yes automatic yes to prompts" + echo " --compiler COMPILER set the markdown compiler to use. Default is marked --gfm" + echo " -c, --css CSS_PATH set the github-markdown.css file path (by default github-markdown.css in the CWD)" + echo " -h, --help print this help message" + echo " --highlight enable highlight.js support for code blocks (uses cdnjs as source)" + echo " -i, --input INPUT specify INPUT file" + echo " -o, --output OUTPUT output to specified OUTPUT file" + echo " -y, --yes automatic yes to prompts" } # Parse arguments @@ -37,6 +39,10 @@ while [ $# -gt 0 ]; do print_help exit 1 ;; + --highlight) + ENABLE_JS=1 + shift + ;; -i | --input) INPUT="$2" CUSTOM_INPUT=1 @@ -87,6 +93,14 @@ fi # Add meta, link, and style lines to OUTPUT echo "" >> "$OUTPUT" echo "" >> "$OUTPUT" + +# Add JS script sources, if enabled +if [ $ENABLE_JS ]; then + echo "" >> "$OUTPUT" + echo "" >> "$OUTPUT" + echo "" >> "$OUTPUT" +fi + echo "