File: test_utils.py

package info (click to toggle)
doxysphinx 3.3.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,296 kB
  • sloc: python: 2,974; javascript: 235; cpp: 88; makefile: 52; sh: 10
file content (21 lines) | stat: -rw-r--r-- 627 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from typing import Any

import lxml.etree as etree


def load_code_element(html_string: str) -> etree._Element:
    """loads a single pre or code element in an html snippet string.

    There has to be only one pre or code element!!
    """
    parser: Any = etree.HTMLParser()
    e = etree.fromstring(html_string, parser)
    result: Any = e.find(f".//pre")
    if result is None:
        result = e.find(f".//code")
    return result


def clean_html_string(html: str) -> str:
    """Removes whitespaces from html strings."""
    return html.replace("\n", "").replace("  ", "").replace("> ", ">").replace(" <", "<").strip()