MCPcopy Create free account
hub / github.com/gawel/pyquery / extract_text_array

Function extract_text_array

pyquery/text.py:73–96  ·  view source on GitHub ↗
(dom, squash_artifical_nl=True, strip_artifical_nl=True)

Source from the content-addressed store, hash-verified

71
72
73def extract_text_array(dom, squash_artifical_nl=True, strip_artifical_nl=True):
74 if callable(dom.tag):
75 return ''
76 r = []
77 if dom.tag in SEPARATORS:
78 r.append(True) # equivalent of '\n' used to designate separators
79 elif dom.tag not in INLINE_TAGS:
80 # equivalent of '\n' used to designate artificially inserted newlines
81 r.append(None)
82 if dom.text is not None:
83 r.append(dom.text)
84 for child in dom.getchildren():
85 r.extend(extract_text_array(child, squash_artifical_nl=False,
86 strip_artifical_nl=False))
87 if child.tail is not None:
88 r.append(child.tail)
89 if dom.tag not in INLINE_TAGS and dom.tag not in SEPARATORS:
90 # equivalent of '\n' used to designate artificially inserted newlines
91 r.append(None)
92 if squash_artifical_nl:
93 r = _squash_artifical_nl(r)
94 if strip_artifical_nl:
95 r = _strip_artifical_nl(r)
96 return r
97
98
99def extract_text(dom, block_symbol='\n', sep_symbol='\n', squash_space=True):

Callers 1

extract_textFunction · 0.85

Calls 4

_squash_artifical_nlFunction · 0.85
_strip_artifical_nlFunction · 0.85
appendMethod · 0.80
extendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…