Skip to content

Instantly share code, notes, and snippets.

@alexmwalker
Last active January 24, 2023 08:15
Show Gist options
  • Save alexmwalker/35ff1c56e24a461c18b2b945b1feb4d2 to your computer and use it in GitHub Desktop.
Save alexmwalker/35ff1c56e24a461c18b2b945b1feb4d2 to your computer and use it in GitHub Desktop.
This shell script takes any markdown file in the same folder and creates an Indesign-ready ICML file conversion in a new folder called 'icml'. You can then PLACE that ICML file into an Indesign Template. The idea is that your template file should already have all your Paragraph, Character and Graphic styles ready. Note that your ICML file remain…
#!/bin/bash
set -e
declare -r out_dir="./icml"
declare -r old_ifs=${IFS}
declare f
declare filename
if ! command -v pandoc >/dev/null
then
echo "Install pandoc first." 1>&2
exit 1
fi
if [ ! -d "${out_dir}" ]
then
mkdir -p "${out_dir}"
fi
IFS=$'\n'
for f in *.md
do
filename="${f%.*}"
echo "Converting ${f} to ${filename}.icml"
pandoc -s -f markdown -t icml -o "${out_dir}/${filename}.icml" "${filename}.md"
done
IFS=${old_ifs}
@hamyat
Copy link

hamyat commented Jan 24, 2023

Hi Alex!
Thanks for sharing. I tried to execute the file using bash command and found the following errors.

md_to_icml.sh: line 2: $'\r': command not found
: invalid optionine 3: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
md_to_icml.sh: line 4: $'\r': command not found
': not a valid identifierclare: f ': not a valid identifierclare: filename
md_to_icml.sh: line 9: $'\r': command not found
md_to_icml.sh: line 24: syntax error near unexpected token $'do\r'' 'd_to_icml.sh: line 24: do

Any solution, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment