Simplifies complex HTML into clean, email-friendly markup. Strips out modern layout cruft while preserving structure and basic formatting.
- In Sublime Text: Preferences → Browse Packages...
- Create a new folder called
HtmlCleaner - Copy all files from this package into that folder:
HtmlCleaner.pyHtmlCleaner.sublime-commandsDefault.sublime-keymap
- Keyboard shortcut:
Ctrl+Shift+H(Windows/Linux) orCmd+Shift+H(Mac) - Command palette:
Ctrl+Shift+P→ "HTML Cleaner: Clean Selection"
If you have a selection, only that selection is cleaned. Otherwise, the entire file is cleaned.
Keeps:
- Basic structure:
p,br,hr - Headings:
h1throughh6 - Formatting:
strong,b,em,i,u - Links:
a(with href) - Images:
img(with src, alt, dimensions) - Lists:
ul,ol,li - Tables:
table,tr,td,th(email-safe) - Other:
blockquote,pre,code
Removes:
div,span,section,article,nav,header,footer(unwrapped - content kept)script,style,form,iframe(removed entirely with content)- Classes, IDs, inline styles, data attributes
- HTML comments
- Successive
characters - Empty tags
Converts:
<b>→<strong><i>→<em>
Edit the CONFIG dictionary at the top of HtmlCleaner.py to customize:
CONFIG = {
"keep_tags": [...], # Tags to preserve
"remove_with_content": [...], # Tags to delete entirely
"keep_attributes": {...}, # Which attributes to keep per tag
"remove_classes": True, # Strip class attributes
"remove_ids": True, # Strip id attributes
"remove_inline_styles": True, # Strip style attributes
"remove_comments": True, # Strip HTML comments
"convert_b_to_strong": True, # <b> → <strong>, <i> → <em>
"remove_successive_nbsp": True,
"remove_span_tags": True,
"remove_empty_tags": True,
"preserve_line_breaks": True,
}Edit Default.sublime-keymap:
[
{
"keys": ["ctrl+shift+h"],
"command": "html_cleaner"
}
]Change "ctrl+shift+h" to your preferred key combination.