class documentation

class ParseTree(object): (source)

View In Hierarchy

Wrapper for zim parse trees.
Method __init__ Undocumented
Method cleanup_headings No summary
Method copy Undocumented
Method count Returns the number of occurences of 'text' in this tree.
Method countre Returns the number of matches for a regular expression in this tree.
Method decode_urls Calls decode_url() on all links that contain urls. See zim.parsing for details. Modifies the parse tree.
Method encode_urls Calls encode_url() on all links that contain urls. See zim.parsing for details. Modifies the parse tree.
Method extend Undocumented
Method find Find first occurence of tag in the tree @returns: a Node object or None
Method findall Find all occurences of tag in the tree @param tag: tag name @returns: yields Node objects
Method fromstring Set the contents of this tree from XML representation.
Method get_ends_with_newline Checks whether this tree ends in a newline or not
Method get_heading_level Undocumented
Method get_heading_text Undocumented
Method iter_href No summary
Method iter_tag_names Generator for tags in the page content @returns: yields an unordered list of tag names
Method iter_tokens Undocumented
Method remove_heading No summary
Method replace Modify the tree by replacing all occurences of tag by the return value of func.
Method set_heading_text Set the first heading of the parse tree to 'text'. If the tree already has a heading of the specified level or higher it will be replaced. Otherwise the new heading will be prepended.
Method tostring Serialize the tree to a XML representation
Method visit Visit all nodes of this tree
Instance Variable meta Undocumented
Property hascontent Returns True if the tree contains any content at all.
Property israw Returns True when this is a raw tree (which is representation of TextBuffer, but not really valid).
Static Method _node_to_etree Undocumented
Method _do_replace Undocumented
Method _elt_to_text Undocumented
Method _get_element_ends_with_newline Undocumented
Method _get_heading_element Undocumented
Method _get_root_attrib Undocumented
Method _insert_text Undocumented
Method _pop_root_attrib Undocumented
Method _replace Undocumented
Method _set_root_attrib Undocumented
Method _visit Undocumented
Instance Variable _etree Undocumented
Instance Variable _object_cache Undocumented
def __init__(self, *arg, **kwarg): (source)

Undocumented

def cleanup_headings(self, offset=0, max=6): (source)
Change the heading levels throughout the tree. This makes sure that al headings are nested directly under their parent (no gaps in the levels of the headings). Also you can set an offset for the top level and a max depth.
def copy(self): (source)

Undocumented

def count(self, text): (source)
Returns the number of occurences of 'text' in this tree.
def countre(self, regex): (source)
Returns the number of matches for a regular expression in this tree.
def decode_urls(self, mode=URL_ENCODE_READABLE): (source)
Calls decode_url() on all links that contain urls. See zim.parsing for details. Modifies the parse tree.
def encode_urls(self, mode=URL_ENCODE_READABLE): (source)
Calls encode_url() on all links that contain urls. See zim.parsing for details. Modifies the parse tree.
def extend(self, tree): (source)

Undocumented

def find(self, tag): (source)
Find first occurence of tag in the tree
Returns
a Node object or None
def findall(self, tag): (source)
Find all occurences of tag in the tree
Parameters
tagtag name
Returns
yields Node objects
def fromstring(self, string): (source)
Set the contents of this tree from XML representation.
def get_ends_with_newline(self): (source)
Checks whether this tree ends in a newline or not
def get_heading_level(self): (source)

Undocumented

def get_heading_text(self, level=1): (source)

Undocumented

def iter_href(self, include_page_local_links=False, include_anchors=False): (source)
Generator for links in the text
Parameters
include_page_local_linksUndocumented
include_anchorsif False remove the target location from the link and only yield unique links to pages
Returns
yields a list of unique HRef objects
def iter_tag_names(self): (source)
Generator for tags in the page content
Returns
yields an unordered list of tag names
def iter_tokens(self): (source)

Undocumented

def remove_heading(self, level=-1): (source)
If the tree starts with a heading, remove it and any trailing whitespace. Will modify the tree.
Returns
a 2-tuple of text and heading level or (None, None)
def replace(self, tags, func): (source)
Modify the tree by replacing all occurences of tag by the return value of func.
Parameters
tagstag name, or list of tag names
func

function to generate replacement values. Function will be called as:

        func(node)

Where node is a Node object representing the subtree. If the function returns another Node object or modifies node and returns it, the subtree will be replaced by this new node. If the function raises VisitorSkip the replace is skipped. If the function raises VisitorStop the replacement of all nodes will stop.

def set_heading_text(self, text, level=1): (source)
Set the first heading of the parse tree to 'text'. If the tree already has a heading of the specified level or higher it will be replaced. Otherwise the new heading will be prepended.
def tostring(self): (source)
Serialize the tree to a XML representation
def visit(self, visitor): (source)
Visit all nodes of this tree
Parameters
visitora Visitor or Builder object
Note
If the visitor modifies the attrib dict on nodes, this will modify the tree.
meta = (source)

Undocumented

@property
hascontent = (source)
Returns True if the tree contains any content at all.
Returns True when this is a raw tree (which is representation of TextBuffer, but not really valid).
@staticmethod
def _node_to_etree(node): (source)

Undocumented

def _do_replace(self, elt, replacements): (source)

Undocumented

def _elt_to_text(self, elt): (source)

Undocumented

def _get_element_ends_with_newline(self, element): (source)

Undocumented

def _get_heading_element(self, level=1): (source)

Undocumented

def _get_root_attrib(self, key, default=None): (source)

Undocumented

def _insert_text(self, elt, i, text): (source)

Undocumented

def _pop_root_attrib(self, key, default=None): (source)

Undocumented

def _replace(self, elt, tags, func): (source)

Undocumented

def _set_root_attrib(self, key, value): (source)

Undocumented

def _visit(self, visitor, node): (source)

Undocumented

_etree = (source)

Undocumented

_object_cache: dict = (source)

Undocumented