simplify websupport writer now that we don't have nested commentable nodes.

This commit is contained in:
Jacob Mason 2010-08-14 16:05:19 -05:00
parent ace0e37e03
commit 89566e69c9

View File

@ -20,38 +20,22 @@ class WebSupportTranslator(HTMLTranslator):
def __init__(self, builder, *args, **kwargs):
HTMLTranslator.__init__(self, builder, *args, **kwargs)
self.comment_class = 'spxcmt'
self.init_support()
def init_support(self):
self.cur_node = None
def dispatch_visit(self, node):
if is_commentable(node):
self.handle_visit_commentable(node)
HTMLTranslator.dispatch_visit(self, node)
def dispatch_departure(self, node):
HTMLTranslator.dispatch_departure(self, node)
if is_commentable(node):
self.handle_depart_commentable(node)
def handle_visit_commentable(self, node):
# If this node is nested inside another commentable node this
# node will not be commented.
if self.cur_node is None:
self.cur_node = self.add_db_node(node)
# We will place the node in the HTML id attribute. If the node
# already has an id (for indexing purposes) put an empty
# span with the existing id directly before this node's HTML.
if node.attributes['ids']:
self.body.append('<span id="%s"></span>'
% node.attributes['ids'][0])
node.attributes['ids'] = ['s%s' % self.cur_node.id]
node.attributes['classes'].append(self.comment_class)
def handle_depart_commentable(self, node):
if self.comment_class in node.attributes['classes']:
self.cur_node = None
db_node = self.add_db_node(node)
# We will place the node in the HTML id attribute. If the node
# already has an id (for indexing purposes) put an empty
# span with the existing id directly before this node's HTML.
if node.attributes['ids']:
self.body.append('<span id="%s"></span>'
% node.attributes['ids'][0])
node.attributes['ids'] = ['s%s' % db_node.id]
node.attributes['classes'].append(self.comment_class)
def add_db_node(self, node):
storage = self.builder.app.storage