Skip to content

Instantly share code, notes, and snippets.

@fernandolopez
Last active December 24, 2015 11:09
Show Gist options
  • Save fernandolopez/6788747 to your computer and use it in GitHub Desktop.
Save fernandolopez/6788747 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Transformar páginas de didiwiki a markdown
sed -i -r 's/\x00/\n/g' * # Las páginas de didiwiki terminan en \0
sed -i -r 's/\[(\S+)\s(.+)\]/[\2](\1)/g' * # Los links tienen formato distinto
# Los links locales no tienen extensión
sed -i -r 's/(\[.+\]\([^(https?:)].+)\)/\1.md)/g' *
sed -i -r 's/\[([^(https?:)][^]]+)\]\s+$/[\1](\1.md)/g' *
# Los headings tienen sintaxis un poco distinta
sed -i -r 's/\s*=(\S+)/#\1/g;s/\s*==(\S+)/##\1/g;s/\s*===(\S+)/###\1/g;s/\s*====(\S+)/####\1/g' *
sed -i -r 's/\s*#=(\S+)/##\1/g;s/\s*#==(\S+)/###\1/g;s/\s*#===(\S+)/####\1/g' *
# Ya podemos considerar que están más o menos en markdown
for each in *; do
# No queremos renombrar el css ni archivos ya renombrados
[ -n "$(echo $each | grep -E -e '\.css$' -e '\.md$')" ] && continue
mv $each $each.md
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment