Converting all files in a folder to md using pandoc on Mac

ぐ巨炮叔叔 提交于 2019-12-02 17:14:13

Since you mentioned you don't mind not using make, you can try bash.

I modified the code from this answer, use in the parent directory:

find ./ -iname "*.md" -type f -exec sh -c 'pandoc "${0}" -o "${0%.md}.pdf"' {} \;

It worked when I tested it, so it should work for you.

As per the request Any ideas how to specify the output folder? (Using html as the original file and md as the output):

find ./ -iname "*.html" -type f -exec sh -c 'pandoc "${0}" -o "./output/$(basename ${0%.html}.md)"' {} \;

I have tested this and it works for me.

Edit: As per a comment, the {} \; when used with find and the -exec option is used as a, more or less, placeholder for where the filename should be. As in it expands the filenames found to be placed in the command. The \; ends the -exec. See here for more explanation.

This is how I did it!

files=($(find ${INPUT_FOLDER} -type f -name '*.md'))
for item in ${files[*]}
do
  printf "   %s\n" $item
  install -d ${DIR}/build/$item
  pandoc $item -f markdown -t html -o ${DIR}/build/$item.html;
  rm -Rf ${DIR}/build/$item
done
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!