From b6f8333231e95b737d2f76257f1800a651d7df9f Mon Sep 17 00:00:00 2001 From: lshprung Date: Sat, 18 Dec 2021 10:41:59 -0800 Subject: Added flag to select light or dark theme --- markdown-to-github-html.sh | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'markdown-to-github-html.sh') diff --git a/markdown-to-github-html.sh b/markdown-to-github-html.sh index 45ac52a..d4451b1 100755 --- a/markdown-to-github-html.sh +++ b/markdown-to-github-html.sh @@ -1,27 +1,30 @@ #!/usr/bin/sh NAME="$0" -CSS_LINK="https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css" -CSS_PATH="./github-markdown.css" +CSS_LINK_DIR="https://raw.githubusercontent.com/sindresorhus/github-markdown-css/main" +CSS_PATH="./github-markdown-light.css" +CUSTOM_CSS_PATH=0 INPUT="/dev/stdin" CUSTOM_INPUT=0 OUTPUT="/dev/stdout" CUSTOM_OUTPUT=0 COMPILER="marked --gfm" ENABLE_JS=0 #Set to 1 for --highlight flag +THEME="light" 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 " --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-light.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" + echo " -i, --input INPUT specify INPUT file" + echo " -o, --output OUTPUT output to specified OUTPUT file" + echo " -t, --theme light|dark Set whether the css theme should match github light or dark mode (default is light)" + echo " -y, --yes automatic yes to prompts" } # Parse arguments @@ -33,6 +36,7 @@ while [ $# -gt 0 ]; do ;; -c | --css) CSS_PATH="$2" + CUSTOM_CSS_PATH=1 shift 2 ;; -h | --help) @@ -53,6 +57,15 @@ while [ $# -gt 0 ]; do CUSTOM_OUTPUT=1 shift 2 ;; + -t | --theme) + if [ "$2" = "dark" ]; then + THEME="dark" + if [ $CUSTOM_CSS_PATH -eq 0 ]; then + CSS_PATH="./github-markdown-dark.css" + fi + fi + shift 2 + ;; -y | --yes) PROMPT="y" YES=1 @@ -82,11 +95,11 @@ fi # Prompt to download CSS file if not in CWD/specified CSS_PATH if [ ! -e "$CSS_PATH" ]; then if [ $YES -eq 0 ]; then - echo -n "Download github-markdown.css to $CSS_PATH? [Y/n] " + echo -n "Download github-markdown-$THEME.css to $CSS_PATH? [Y/n] " read -r PROMPT fi if [ ! "$PROMPT" = "n" ]; then - wget "$CSS_LINK" -O "$CSS_PATH" + wget "$CSS_LINK_DIR/github-markdown-$THEME.css" -O "$CSS_PATH" fi fi @@ -96,7 +109,11 @@ echo "" >> "$OUTPUT" # Add JS script sources, if enabled if [ $ENABLE_JS ]; then - echo "" >> "$OUTPUT" + if [ "$THEME" = dark ]; then + echo "" >> "$OUTPUT" + else + echo "" >> "$OUTPUT" + fi echo "" >> "$OUTPUT" echo "" >> "$OUTPUT" fi -- cgit