summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-12-18 10:41:59 -0800
committerlshprung <lshprung@yahoo.com>2021-12-18 10:41:59 -0800
commitb6f8333231e95b737d2f76257f1800a651d7df9f (patch)
treee109919b6accf6c3cdb0c813fb7d73958c607d8a
parentf49814b794c65e5baa277b7f6d3b649576ac5bfa (diff)
Added flag to select light or dark theme
-rwxr-xr-xmarkdown-to-github-html.sh39
1 files changed, 28 insertions, 11 deletions
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 "<link rel=\"stylesheet\" href=\"$CSS_PATH\">" >> "$OUTPUT"
# Add JS script sources, if enabled
if [ $ENABLE_JS ]; then
- echo "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/default.min.css\">" >> "$OUTPUT"
+ if [ "$THEME" = dark ]; then
+ echo "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/github-dark.min.css\">" >> "$OUTPUT"
+ else
+ echo "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/github.min.css\">" >> "$OUTPUT"
+ fi
echo "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js\"></script>" >> "$OUTPUT"
echo "<script>hljs.highlightAll();</script>" >> "$OUTPUT"
fi