The dom.edit module

The Edit base class, to perform operations on a DOM document and/or a related parce Document in different ways.

class Edit[source]

Bases: object

Base class to perform operations on a DOM document via a Range, an element.Element node, a parce.Document or a selection of a parce document in a parce.Cursor.

You must implement at least Edit.edit_range() to make it work. You can choose to reimplement other methods to alter behaviour or functionality.

Then you create an instance, and you can call one of the edit_xxx() methods.

range_from_root = False

If True, when there is a selection, a Range is created from the root node, otherwise from the younghest common ancestor.

range_from_cursor = False

If True, a Range is created from the cursor’s position to the end, instead of the full document in case there is no selection.

readonly = False

If True, does not write back changes to the parce Document

document()[source]

Return the parce Document, if available.

This is the document that was used when edit_cursor() or edit_document() was called. The document is only available during that edit call.

changes()[source]

Return the number of changes made to the parce Document.

find_block(node)[source]

The parce Block of the node (None if there is no parce Document).

edit(music)[source]

Convenience method calling one of the other edit_xxx methods depending on the type.

edit_cursor(cursor)[source]

Edit the range pointed to by the parce.Cursor.

The default implementation calls edit_range() with a Range, that by default encompasses the full DOM tree when there is no selection. Set range_from_cursor to True if you want the edited range to be from the cursor’s position to the document end when there is no selection.

If the cursor has a selection, the Range encompasses only the child nodes that are within the cursor’s selection. The ancestor of the range is by default the younghest common ancestor of the start and end nodes of the range. Set range_from_root to True if you want the ancestor of the range to be the DOM tree root anyway.

edit_document(document)[source]

Edit the full parce.Document.

The default implementation calls edit_cursor() with a parce.Cursor pointing to the beginning of the document, without selection.

edit_node(node)[source]

Edit the full element.Element node.

The default implementation calls edit_range() with a Range encompassing the full element node.

edit_range(r)[source]

Edit the specified Range.

At least this method needs to be implemented to actually perform the operation.