Book Elves Elf Life


$5.95 Dial-up
TECHNODOPE

Converting HTML to Markdown

With PolyEdit and regular expressions.

PolyEdit has a nice regex option in its find and replace dialog. You can use it to make complicated changes, like re-ordering text.

Reformatting a link is a good example. Compare standard HTML and Markdown syntax:

<a href="http://www.google.com/">Google</a>
[Google](http://www.google.com/)

Not only do we need to change the style of the container, we need to flip the order of the link URL and the linked text. Use the following regex in the find and replace dialog:

Find what: 
<a href="(.*?)">(.*?)</a> 

Replace with: 
[ -](- ) 

List items just need to be trimmed:

Find what: 
<li>(.*?)</li> 

Replace with: 
* -  

The old italic and bold tags have been deprecated in favor of em and strong. The following regex takes care of it all.

Find what: 
(<em>|<i>)(.*?)(</em>|</i>)

Replace with:
* -*
Find what: 
(<strong>|<b>)(.*?)(</strong>|</b>)

Replace with:
** -**

blog comments powered by Disqus

Copyright © 2009 Carson Fire • Privacy policy