Range
Overview
Range is a class in Aspose.Html FOSS for Python.
Inherits from: AbstractRange.
A contiguous portion of a document tree (WHATWG DOM §5).
This class provides 23 methods for working with Range objects in Python programs.
Available methods include: __init__, clone_contents, clone_range, collapse, compare_boundary_points, compare_point, create_contextual_fragment, delete_contents, detach, extract_contents, insert_node, intersects_node, and 11 additional methods.
All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package.
Properties: collapsed, common_ancestor_container, end_container, end_offset, start_container, start_offset.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
common_ancestor_container | "Node" | Read | The deepest node that contains both boundary points. |
start_container | "Node" | Read | The node that contains the start of the range. |
start_offset | int | Read | The offset within start_container. |
end_container | "Node" | Read | The node that contains the end of the range. |
end_offset | int | Read | The offset within end_container. |
collapsed | bool | Read | True if the start and end boundary points are identical. |
Methods
| Signature | Description |
|---|---|
__init__(owner_document: "Node") | Create a collapsed range at (owner_document, 0). |
set_start(node: "Node", offset: int) | Set the start boundary of the range. |
set_end(node: "Node", offset: int) | Set the end boundary of the range. |
set_start_before(node: "Node") | Set the start to the position just before node in its parent. |
set_start_after(node: "Node") | Set the start to the position just after node in its parent. |
set_end_before(node: "Node") | Set the end to the position just before node in its parent. |
set_end_after(node: "Node") | Set the end to the position just after node in its parent. |
collapse(to_start: bool) | Collapse the range to its start or end boundary point. |
select_node(node: "Node") | Select node and all its contents. |
select_node_contents(node: "Node") | Select the contents of node (not the node itself). |
extract_contents() → "DocumentFragment" | Remove and return the selected content as a DocumentFragment. |
clone_contents() → "DocumentFragment" | Return a DocumentFragment with deep copies of the selected content. |
delete_contents() | Remove the selected content from the document. |
insert_node(node: "Node") | Insert node at the start of the range. |
surround_contents(new_parent: "Node") | Surround the range’s contents with new_parent. |
clone_range() → "Range" | Return a new Range with identical boundary points. |
detach() | Unregister this range from live mutation tracking. |
is_point_in_range(node: "Node", offset: int) → bool | Return True if (node, offset) falls within the range (inclusive). |
compare_point(node: "Node", offset: int) → int | Return -1, 0, or 1 comparing (node, offset) against the range. |
compare_boundary_points(how: int, source_range: "Range") → int | Compare this range with source_range using boundary mode how. |
create_contextual_fragment(fragment: str) → "DocumentFragment" | Parse fragment in this range’s start-boundary element context. |
intersects_node(node: "Node") → bool | Return True if node is partially or fully within the range. |
to_string() → str | Return the concatenated text content of the range. |