euporie.core.ft.html
Contain a HTML to formatted text parser.
Functions
|
Typed version of namedtuple. |
|
Add a border around formatted text. |
|
Align formatted text at a given width. |
Write fragments tagged with "[ReverseOverwrite]" over text to their left. |
|
|
Apply a style to formatted text. |
|
Return the index where to insert item x in list a, assuming a is sorted. |
|
Cast a value to a type. |
|
Return the ceiling of x as an Integral. |
|
Compute a cell's padding. |
|
Concatenate two blocks of formatted text, aligning at a given baseline. |
|
Convert CSS dimensions to terminal cell sizes. |
|
Get the dimensions of an image. |
|
Same as a == b. |
|
Split formatted text into a list of word fragments which form words. |
|
Return the character width of this text fragment list. |
|
Same as a >= b. |
|
Get the current active (running) Application. |
|
Extract a hex color from a string. |
|
Attempt to guess the format of a path. |
|
Extract the first integer from a string. |
|
Create or return the conversion IO loop. |
|
Same as a > b. |
|
Join a list of lines of formatted text. |
|
Retrieve the last character of formatted text. |
|
Same as a <= b. |
|
Evaluate an expression node or a string containing only a Python expression. |
|
Least-recently-used cache decorator. |
|
Same as a < b. |
|
Determine if a CSS selector matches a particular element. |
|
Calculate the length of the longest line in formatted text. |
|
Fill space at the end of lines. |
|
Convert CSS declarations into the internals style representation. |
|
Convert media rules to conditions. |
|
Collect all CSS styles from style tags. |
|
Pate formatted text on top of other formatted text. |
|
Get the cell width and aspect ration of a pixel dimension. |
|
Calculate the specificity score of a CSS selector. |
|
Take a single list of (style_str, text) tuples and yield one such list for each line. |
|
Strip whitespace (or a given character) from the ends of formatted text. |
|
Truncate all lines at a given length. |
|
Attempt to cast a string to a python type. |
|
Turn fully-qualified and potentially chained URL into filesystem instance |
|
Join a base URL and a possibly relative URL to form an absolute interpretation of the latter. |
Classes
|
A table cell. |
|
Turn any callable into a Filter. |
|
A named tuple to hold CSS selector data. |
|
An HTML parser. |
|
A tuple of four bools with directions. |
|
A tuple of four integers with directions. |
|
A description of a cell border: a |
|
A tuple of four strings with directions. |
|
Specified dimension (width/height) of a user control or window. |
|
A description of a direction. |
|
Simple event to which event handlers can be attached. For instance::. |
|
Alignment of formatted text. |
|
A collection of characters which can be used to draw a grid. |
|
A HTML formatted text renderer. |
|
Find tags and other markup and call handler functions. |
|
A Mapping is a generic container for associating key/value pairs. |
|
Represent an node in the DOM. |
|
|
|
A table. |
|
The computed theme of an element. |
|
|
|
|
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords. |
|
zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object |
- class euporie.core.ft.html.CssSelector(comb: str | None = None, item: str | None = None, attr: str | None = None, pseudo: str | None = None)
Bases:
NamedTuple
A named tuple to hold CSS selector data.
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- class euporie.core.ft.html.CustomHTMLParser(dom: euporie.core.ft.html.HTML)
Bases:
html.parser.HTMLParser
An HTML parser.
- CDATA_CONTENT_ELEMENTS = ('script', 'style')
- check_for_whole_start_tag(i)
- clear_cdata_mode()
- close()
Handle any buffered data.
- feed(data)
Feed data to the parser.
Call this as often as you want, with as little or as much text as you want (may include ‘n’).
- get_starttag_text()
Return full source of start tag: ‘<…>’.
- getpos()
Return current line number and offset.
- goahead(end)
- handle_charref(name)
- handle_comment(data)
- handle_decl(decl)
- handle_entityref(name)
- handle_pi(data)
- handle_startendtag(tag, attrs)
- parse(markup: str) euporie.core.ft.html.Node
Pare HTML markup.
- parse_bogus_comment(i, report=1)
- parse_comment(i, report=1)
- parse_declaration(i)
- parse_endtag(i)
- parse_html_declaration(i)
- parse_marked_section(i, report=1)
- parse_pi(i)
- parse_starttag(i)
- reset()
Reset this instance. Loses all unprocessed data.
- set_cdata_mode(elem)
- unknown_decl(data)
- updatepos(i, j)
- class euporie.core.ft.html.Direction(x: bool = False, y: bool = False)
Bases:
NamedTuple
A description of a direction.
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- class euporie.core.ft.html.HTML(markup: str, base: Path | str | None = None, width: int | None = None, height: int | None = None, collapse_root_margin: bool = False, fill: bool = True, css: CssSelectors | None = None, browser_css: CssSelectors | None = None, mouse_handler: Callable[[Node, MouseEvent], NotImplementedOrNone] | None = None, paste_fixed: bool = True, on_update: Callable[[HTML], None] | None = None, _initial_format: str = '')
Bases:
object
A HTML formatted text renderer.
Accepts a HTML string and renders it at a given width.
- async format_element(ft: StyleAndTextTuples, element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Format an element’s content based on its theme.
- property parser: euporie.core.ft.html.CustomHTMLParser
Load the HTML parser.
- render(width: int | None, height: int | None) StyleAndTextTuples
Render the current markup at a given size.
- async render_details_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render details, showing summary at the top and hiding contents if closed.
- async render_element(element: Node, available_width: int, available_height: int, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render a Node.
- async render_grid_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render a element with
display
set togrid
.- Parameters
element – The list of parsed elements to render
left – The position on the current line at which to render the output - used to indent subsequent lines when rendering inline blocks like images
fill – Whether to fill the remainder of the rendered space with whitespace
align_content – Whether to align the element’s content
- Returns
Formatted text
- async render_img_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render an image’s content.
- async render_input_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render an input element.
- async render_list_item_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render a list item.
- async render_node_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Generate flows for the contents of the element.
- async render_ol_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render lists, adding item numbers to child <li> elements.
- async render_svg_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Display images rendered as ANSI art.
- async render_table_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render a HTML table element.
- Parameters
element – The list of parsed elements to render
left – The position on the current line at which to render the output - used to indent subsequent lines when rendering inline blocks like images
fill – Whether to fill the remainder of the rendered space with whitespace
align_content – Whether to align the element’s content
- Returns
Formatted text
- async render_text_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render a text element.
- Parameters
element – The page element to render
left – The position on the current line at which to render the output - used to indent subsequent lines when rendering inline blocks like images
fill – Whether to fill the remainder of the rendered space with whitespace
align_content – Whether to align the element’s content
- Returns
Formatted text
- async render_ul_content(element: Node, left: int = 0, fill: bool = True, align_content: bool = True) StyleAndTextTuples
Render lists, adding item numbers to child <li> elements.
- property soup: euporie.core.ft.html.Node
Parse the markup.
- class euporie.core.ft.html.Node(dom: euporie.core.ft.html.HTML, name: str, parent: euporie.core.ft.html.Node | None, text: str = '', attrs: list[tuple[str, str | None]] | None = None, contents: list[euporie.core.ft.html.Node] | None = None)
Bases:
object
Represent an node in the DOM.
- find_all(tag: str, recursive: bool = False) Iterator[Node]
Find all child elements of a given tag type.
- property first_child_element: euporie.core.ft.html.Node | None
Return the first child element.
- property is_first_child_element: bool
True if the element if the first child element of its parent element.
- property is_first_child_node: bool
True if the element if the first child node of its parent element.
- property is_last_child_element: bool
True if the element if the last child element of its parent element.
- property is_last_child_node: bool
True if the element if the last child node of its parent element.
- property last_child_element: euporie.core.ft.html.Node | None
Return the last child element.
- property next_element: euporie.core.ft.html.Node | None
Return the next sibling element.
- property next_node: euporie.core.ft.html.Node | None
Return the next sibling node.
- property next_node_in_flow: euporie.core.ft.html.Node | None
Get the next node in the current element’s flow.
- property parents: list[euporie.core.ft.html.Node]
Yield all parent elements.
- property prev_element: euporie.core.ft.html.Node | None
Return the previous sibling element.
- property prev_node: euporie.core.ft.html.Node | None
Return the previous sibling node.
- property prev_node_in_flow: euporie.core.ft.html.Node | None
Get the previous node in the current element’s flow.
- property renderable_contents: list[euporie.core.ft.html.Node]
List the node’s contents including ‘::before’ and ‘::after’ elements.
- class euporie.core.ft.html.Theme(element: euporie.core.ft.html.Node, parent_theme: euporie.core.ft.html.Theme | None, available_width: int = 0, available_height: int = 0)
Bases:
collections.abc.Mapping
The computed theme of an element.
- property anchors: euporie.core.data_structures.DiBool
Which position directions are set.
- property attributes_theme: dict[str, str]
Calculate the theme defined by (depreciated) HTML attributes.
- property base_margin: euporie.core.data_structures.DiInt
Calculate the margin box.
- property block_align: euporie.core.ft.utils.FormattedTextAlign
Determine if the left and right margins are set to auto.
- property border_grid: euporie.core.border.GridStyle
Calculate a GridStyle based on the border lines.
- property border_line: euporie.core.border.DiLineStyle
Calculate the line style.
- property border_style: euporie.core.data_structures.DiStr
Calculate the visibility of the element’s borders.
- property border_visibility: euporie.core.data_structures.DiBool
Calculate the visibility of the element’s borders.
- get(k[, d]) D[k] if k in D, else d. d defaults to None.
- property grid_areas: dict[int, dict[int, str]]
The layout of grid-areas in the current node’s grid layout.
- property grid_column_start: int | None
The index of the first grid column spanned by the grid item.
Determine if the element is hidden.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- property margin: euporie.core.data_structures.DiInt
Calculate the margin box.
- property order: tuple[tuple[bool, int], int, tuple[bool, int]]
Items are sorted by ascending order value then their source code order.
- property padding: euporie.core.data_structures.DiInt
Calculate the padding box.
- property position: euporie.core.data_structures.DiInt
The position of an element with a relative, absolute or fixed position.
- property style_attribute_theme: dict[str, str]
Calculate the theme defined by the element’s style attribute.
- property text_align: euporie.core.ft.utils.FormattedTextAlign
The text alignment direction.
- update_space(available_width: int, available_height: int) None
Set the space available to the element for rendering.
- values() an object providing a view on D's values
- euporie.core.ft.html.css_dimension(value: str, vertical: bool = False, available: float | int | None = None) float | None
Convert CSS dimensions to terminal cell sizes.
- euporie.core.ft.html.match_css_selector(selector: str, attrs: str, pseudo: str, element_name: str, is_first_child_element: bool, is_last_child_element: bool, sibling_element_index: int | None, **element_attrs: Any) bool
Determine if a CSS selector matches a particular element.
- euporie.core.ft.html.parse_css_content(content: str) dict[str, str]
Convert CSS declarations into the internals style representation.
- euporie.core.ft.html.parse_media_condition(condition: str, dom: HTML) Filter
Convert media rules to conditions.
- euporie.core.ft.html.parse_style_sheet(css_str: str, dom: HTML, condition: Filter = <prompt_toolkit.filters.base.Always object>) None
Collect all CSS styles from style tags.