Snippets

Lilian Besson (Naereen) Regexp to convert HTML links to rST or Markdown links

Created by Lilian Besson (Naereen) last modified by Lilian Besson
# HTML :
Input:
<a href=['"]([^'"\]]*)['"]>([^<]*)</a>
Output:
<a href='\2'>\1</a>

# rST :
Input:
`([^<`>]*) <([^`>]*)>`_
Output:
`\2 <\1>`_

# Markdown :
Input:
\[([^\]]*)\]\(([^\)]*)\)
Output:
[\2](\1)

---

# HTML to rST
Find what: <a href=['"]([^'"\]]*)['"]>([^<]*)</a>
Replace with: `\2 <\1>`_

# HTML to Markdown
Find what: <a href=['"]([^'"\]]*)['"]>([^<]*)</a>
Replace with: [\2](\1)

# rST to HTML
Find what: `([^<`>]*) <([^`>]*)>`_
Replace with: <a href='\2'>\1</a>

# rST to Markdown
Find what: `([^<`>_]*) <([^`_>]*)>`_
Replace with: [\1](\2)

# Markdown to HTML
Find what: \[([^\]]*)\]\(([^\)]*)\)
Replace with: <a href='\2'>\1</a>

# Markdown to rST
Find what: \[([^\]]*)\]\(([^\)]*)\)
Replace with: `\1 <\2>`_

Comments (1)

  1. Lilian Besson (Naereen)

    They can be used in SublimeText 2 or 3 or any decent text editors (with the "Find and replace" functions), or from the command line with sed :

    sed -iold s:'regexp':'output':g FILE1 FILE2
    

    (you might need to change the delimiter symbol : to something NOT present in the search regexp or the out template)

    Note: I use these regexp on files that I verify manually afterward, do NOT use them in production (they are not robust at all!).