-
-
Save petzi53/8120df519b86578fd7c83e4d74db273f to your computer and use it in GitHub Desktop.
Script to convert book from docx to markdown with Pandoc
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
:: pandoc-docx-Rmd.bat | |
:: | |
:: Don't show these commands to the user | |
@ECHO off | |
:: Set the title of the window | |
TITLE Convert docx to markdown with Pandoc | |
:: Select file marker | |
:selectfile | |
:: Clear any preexisting filename variables | |
SET filename= | |
:: Ask which file we're converting. | |
SET /p filename=Which file? (Don't include the .docx file extension): | |
:: Feedback | |
ECHO Running pandoc... | |
:: Run pandoc | |
CALL pandoc -f docx -t markdown+auto_identifiers -s "$filename".docx -o "$filename".Rmd --atx-headers --wrap=none --extract-media="" | |
:: Feedback | |
ECHO Done. Ready for another file. | |
:: Let the user easily run that again | |
SET repeat= | |
SET /p repeat=Hit enter to convert another file, or any other key and enter to stop. | |
IF "%repeat%"=="" GOTO selectfile | |
:: Otherwise end | |
:end |
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 | |
cd -- "$(dirname "$0")" | |
# That tells the system to use a Bourne shell interpreter, | |
# and then tells OSX to run this script from the current directory. | |
# Don't echo these commands: | |
set +v | |
repeat= | |
while [ "$repeat" = "" ] | |
do | |
# Clear any preexisting filename variables | |
filename= | |
# Ask which file we're converting. | |
echo "Which file? (Don't include the .docx file extension): " | |
read filename | |
# Feedback | |
echo "Running pandoc..." | |
# Run pandoc | |
pandoc -f docx -t markdown+auto_identifiers -s "$filename".docx -o "$filename".Rmd --atx-headers --wrap=none --extract-media="" | |
# Feedback | |
echo "Done. Ready for another file." | |
# Let the user easily run that again | |
repeat= | |
echo "Hit enter to convert another file, or any other key and enter to stop. " | |
read repeat | |
# Otherwise end | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment