# -*- coding: UTF-8 -*- # # Desc: This file is part of the eCromedos document preparation system # Date: 2006/03/09 # Author: Tobias Koch (tkoch@ecromedos.net) # License: GNU General Public License, version 2 # URL: http://www.ecromedos.net # def getInstance(config): '''Returns a plugin instance.''' return Plugin(config) #end function class Plugin: def __init__(self, config): pass #end function def flush(self): pass #end function def process(self, node, format): '''Strip leading and trailing white-space from node content.''' default_nodes = [ "title", "author", "subject", "date", "publisher", "dedication", "caption"] if node.name in default_nodes: do_strip = True else: do_strip = False prop = node.properties while prop: if prop.name == "strip": if prop.content.lower() == "yes": do_strip = True break #end if prop = prop.next #end while #end if if not do_strip: return node # lstrip if node.children: for child in node.children: if child.type == "text": if child.prev and child.prev.type != "text": if child.prev.children == None: break #end if #end if string = child.getContent() stripped = string.lstrip() if not stripped: child.setContent("") elif len(stripped) < len(string): child.setContent(stripped) break else: break #end if #end if #end for #end if # rstrip child = node.last while child: if child.type == "text": if child.next and child.next.type != "text": if child.next.children == None: break #end if #end if string = child.getContent() stripped = string.rstrip() if not stripped: child.setContent("") elif len(stripped) < len(string): child.setContent(stripped) break else: break #end if #end if if child.children: child = child.last else: child = child.prev #end if #end while return node #end function #end class