Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created June 15, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloberg/2937062 to your computer and use it in GitHub Desktop.
Save mloberg/2937062 to your computer and use it in GitHub Desktop.
Replace local links in markdown ([[link]]) with normal links ([link](link)).
#!/bin/sh
PREFIX=wiki
FILES=$(find . -type f -iname '*.md' -o -iname '*.markdown')
if [[ "$1" == "revert" ]]; then
# To Parse back to normal local [[links]]
for file in $FILES; do
sed -e 's/\[\(.*\)\](\/$PREFIX\/\(.*\))/[[\1]]/g' $file > $file.tmp
mv $file.tmp $file
done
else
# Rename local [[links]] to regular links.
for file in $FILES; do
sed -e 's/\[\[\(.*\)\]\]/[\1](\/$PREFIX\/\1)/g' $file > $file.tmp
mv $file.tmp $file
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment