From ee15f271c68068da2a687bc3cad64a4b6546fb30 Mon Sep 17 00:00:00 2001 From: nejdetckenobi Date: Sun, 18 Oct 2026 18:53:08 +0300 Subject: [PATCH] Adds marp.sh --- marp.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 marp.sh diff --git a/marp.sh b/marp.sh new file mode 100755 index 0000000..28acf41 --- /dev/null +++ b/marp.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +# Marp Docker Image +IMAGE="marpteam/marp-cli:latest" + +# Display usage instructions +usage() { + echo "Usage:" + echo " $0 init - Pulls or updates the Marp Docker image." + echo " $0 serve [port] - Serves the specified directory via Docker (Default port: 8080)." + echo " $0 convert - Converts the file to the specified format (pdf, pptx, html, png, jpeg)." + exit 1 +} + +# Check argument count +if [ $# -lt 1 ]; then + usage +fi + +COMMAND=$1 +shift + +case "$COMMAND" in + init) + echo "Pulling Marp Docker image..." + docker pull "$IMAGE" + echo "Initialization complete." + ;; + + serve) + TARGET_DIR=$1 + PORT=${2:-8080} + + if [ -z "$TARGET_DIR" ]; then + echo "Error: Please specify a directory." + echo "Example: $0 serve ./presentations 8080" + exit 1 + fi + + DIR=$(realpath "$TARGET_DIR") + + if [ ! -d "$DIR" ]; then + echo "Error: '$TARGET_DIR' is not a valid directory." + exit 1 + fi + + echo "Serving directory '$DIR' at http://localhost:$PORT (Press Ctrl+C to stop)..." + docker run --rm -it --init \ + -v "$DIR:/home/marp/app" \ + -p "$PORT:8080" \ + "$IMAGE" \ + -s /home/marp/app \ + --allow-local-files + ;; + + convert) + FILE=$1 + FORMAT=$2 + + if [ -z "$FILE" ] || [ -z "$FORMAT" ]; then + echo "Error: Missing parameters." + echo "Usage: $0 convert " + echo "Example: $0 convert presentation.md pdf" + exit 1 + fi + + DIR=$(dirname "$(realpath "$FILE")") + BASENAME=$(basename "$FILE") + OUTPUT_FILE="$(basename "$BASENAME" .md).$FORMAT" + + echo "Converting '$FILE' to '$FORMAT' format..." + docker run --rm --init \ + -v "$DIR:/home/marp/app" \ + "$IMAGE" \ + "/home/marp/app/$BASENAME" \ + --output "/home/marp/app/$OUTPUT_FILE" \ + --allow-local-files + + echo "Conversion completed: $OUTPUT_FILE" + ;; + + *) + echo "Invalid command: $COMMAND" + usage + ;; +esac