Created
October 19, 2012 09:24
-
-
Save hmps/3917136 to your computer and use it in GitHub Desktop.
The way the comment filter in Zen Coding for Sublime Text 2 was designed didn't really appeal to me. Removed starting block and put ending block in same line as end tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
''' | |
Comment important tags (with 'id' and 'class' attributes) | |
@author Sergey Chikuyonok ([email protected]) | |
@link http://chikuyonok.ru | |
''' | |
import zencoding | |
import zencoding.utils as utils | |
def add_comments(node, i): | |
""" | |
Add comments to tag | |
@type node: ZenNode | |
@type i: int | |
""" | |
id_attr = node.get_attribute('id') | |
class_attr = node.get_attribute('class') | |
'''nl = utils.get_newline() ''' | |
nl = '' | |
if id_attr or class_attr: | |
comment_str = '' | |
padding = node.parent and node.parent.padding or '' | |
if id_attr: comment_str += '#' + id_attr | |
if class_attr: comment_str += '.' + class_attr | |
'''node.start = node.start.replace('<', '<!-- /' + comment_str + ' -->' + nl + padding + '>', 1)''' | |
node.end = node.end.replace('>', '>' + nl + padding + '<!-- /' + comment_str + ' -->', 1) | |
# replace counters | |
counter = zencoding.utils.get_counter_for_node(node) | |
node.start = utils.replace_counter(node.start, counter) | |
node.end = utils.replace_counter(node.end, counter) | |
@zencoding.filter('c') | |
def process(tree, profile): | |
if profile['tag_nl'] is False: | |
return tree | |
for i, item in enumerate(tree.children): | |
if item.is_block(): | |
add_comments(item, i) | |
process(item, profile) | |
return tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File to change: Packages/ZenCoding/zencoding/filters/comment.py