Last active
February 4, 2024 18:41
-
-
Save amineHY/63148c9df08d227a3e53ecdd447bcaa3 to your computer and use it in GitHub Desktop.
Converts an AsciiDoc file to PDF using asciidoctor-pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Help function to display usage instructions | |
function usage() { | |
echo "Usage: $0 <filename>" | |
echo "Converts an AsciiDoc file to PDF using asciidoctor-pdf." | |
echo "" | |
echo "Options:" | |
echo " -h, --help Display this help message." | |
} | |
# Parse command-line options | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
-h|--help) usage; exit 0;; | |
*) filename="$1"; shift ;; | |
esac | |
done | |
# Check if Asciidoctor PDF is installed | |
if ! command -v asciidoctor-pdf &> /dev/null | |
then | |
echo "Asciidoctor PDF is not installed. Installing it now." | |
sudo gem install asciidoctor-pdf | |
fi | |
# Check if a filename was provided as an argument | |
if [ $# -eq 0 ] | |
then | |
echo "Error: Please provide a filename as an argument." | |
exit 1 | |
fi | |
# Extract the filename and extension from the argument | |
filename=$1 | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
dirname="${dirname%.*}" | |
# Change directory to the directory of the file | |
cd "$directory" | |
# Convert AsciiDoc file to PDF | |
asciidoctor-pdf -a toc -a allow-uri-read -a doctype=book "$filename.$extension" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment