Skip to content

Instantly share code, notes, and snippets.

@son0fhobs
Created September 21, 2011 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save son0fhobs/1231583 to your computer and use it in GitHub Desktop.
Save son0fhobs/1231583 to your computer and use it in GitHub Desktop.
Remove HTML5 Elements and turn into Div's of that class
# Removes HTML5 elements
# Python regex to turn all html5 elements into div with classes of the same name
# Ex. <section> would become <div class="section">
# Do a Python regular expression replace, full support of Python regular expressions
editor.pyreplace(r'(\<(footer|section|article|header|nav)([^>]*)\>)', r'<div \3>')
#changes </tag> to </div>
editor.pyreplace(r'\<\/(foot
# Below is python to be used in the Notepad++ plugin
#html5 to html4
# This one line is a Notepad++, allowing for an undo action
editor.beginUndoAction()
# Replace HTML5 Ex. <section> Elements and turn to <div class="section">
editor.pyreplace(r'(\<(footer|section|article|header|nav)([^>]*)\>)', r'<div class="\2" \3>')
#takes two classes, combines into one (if class already attached to html5 element
editor.pyreplace(r'\<(.*)class="(.*)"(.*)class="(.*)"(.*)\>', r'<\1class="\2 \4"\3>')
#Get rid of empty spaces before bracket ends and double spaces between classes.
editor.pyreplace(r'\s*\>', r'>')
editor.pyreplace(r'(.)\s\s(.)', r'\1 \2')
#changes </tag> to </div>
editor.pyreplace(r'\<\/(footer|section|article|header|nav)>', '</div>')
#takes care of nav, but could create another class
editor.pyreplace(r'\<([^\/])?nav([^>]*)\>', '<div class="nav" \2>')
# <div class='nav' \2>
# Again, this one line is a notepad++ function
editor.endUndoAction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment