Mac OS X: Unix sed commands I use to clean MacDown HTML output

FWIW, this is the source code for a sed script I use on my Mac OS X system to convert HTML output generated by MacDown into a format I need. MacDown generates some extra “cruft” that I don’t need, so I use these sed commands to clean up that HTML output:

# clean h1 tags. also add newlines before each h1.
s?<h1 id="toc_.*">\(.*\)</h1>?\
\
\
<h1>\1</h1>?

# clean h2 tags
s?<h2 id="toc_.*">\(.*\)</h2>?<h2>\1</h2>?

# clean h3 tags
s?<h3 id="toc_.*">\(.*\)</h3>?<h3>\1</h3>?

# clean pre tags
s?<pre><code>?<pre>?

s?</code></pre>?</pre>?

# these next two lines are unique to modifying "scala>" content
# inside pre tags (something i do while converting the scala cookbook)
s?^scala&gt; \(.*\)$?scala\&gt; <strong>\1</strong>?

s?^<pre>scala&gt; \(.*\)$?<pre>scala\&gt; <strong>\1</strong>?

I won’t explain those sed commands, I just wanted to put it out here in case I needed it again. Okay, one thing to say is that the “header” patterns use the sed “search and replace” functionality.