Skip to content

Instantly share code, notes, and snippets.

@calebsmith
Created March 16, 2014 21:41
Show Gist options
  • Save calebsmith/9590323 to your computer and use it in GitHub Desktop.
Save calebsmith/9590323 to your computer and use it in GitHub Desktop.
html -> markdown with sed
# A sed script to convert HTML slides for reveal.js to markdown
# Assumes @@@\n is used for slide separator, and Note: is used for slide notes
#
# N.B. - Don't use regexes for HTML...ever. This is just a quick intro to sed
# and works for 90% of my needs for slides written in HTML (well-formed). This
# breaks pretty crazily for nested HTML
#
# Usage:
# sed -f thisfilename filename.html > filename.md
/^ *$/d
/<section>/d
s/.*<\/section>/@@@\n/g
s/.*<!--/Note: /
s/-->//
s/.*<h1>/#/
s/<\/h1>//
s/.*<h2>/##/
s/<\/h2>//
s/.*<h3>/###/
s/<\/h3>//
s/.*<h4>/####/
s/<\/h4>//
s/.*<li>/* /
s/<\/li>/\n/
s/<ul>//
s/<\/ul>//
s/<ol>//
s/<\/ol>//
s/.*<p[^>]*>//g
s/<\/p>/\n/
s/.*<code[^>]*.*python.*>/```python/
s/.*<\/code><\/pre>/```/
/.*<a href="[^"]*".*>.*<\/a>/{
s/<a href="/[/
s/">/](/
s/<\/a>/)/
s/\[\(.*\)\]\((.*)\)/[\2\]\(\1\)/
s/\[(/[/
s/)\]/]/
}
s/.*<img src="\(.*\)" \/>/[](\1)/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment