Skip to content

Instantly share code, notes, and snippets.

@amineHY
Last active February 4, 2024 18:40
Show Gist options
  • Save amineHY/5f103aebdaa5cb030c2ce5065ff8f710 to your computer and use it in GitHub Desktop.
Save amineHY/5f103aebdaa5cb030c2ce5065ff8f710 to your computer and use it in GitHub Desktop.
Convert Asciidoc file to Markdown
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <input_file.adoc>"
exit 1
fi
# Input AsciiDoc file
input_file="$1"
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Error: Input file not found: $input_file"
exit 1
fi
# Output DocBook file
docbook_file="${input_file%.adoc}.xml"
# Output Markdown file
markdown_file="${input_file%.adoc}.md"
# Convert AsciiDoc to DocBook
asciidoctor -b docbook "$input_file" -o "$docbook_file"
# Check if the conversion was successful
if [ $? -ne 0 ]; then
echo "Error: AsciiDoc to DocBook conversion failed."
exit 1
fi
# Convert DocBook to Markdown
pandoc -f docbook -t markdown_strict "$docbook_file" -o "$markdown_file"
# Check if the conversion was successful
if [ $? -ne 0 ]; then
echo "Error: DocBook to Markdown conversion failed."
exit 1
fi
echo "Conversion completed successfully:"
echo " AsciiDoc -> DocBook: $input_file -> $docbook_file"
echo " DocBook -> Markdown: $docbook_file -> $markdown_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment