(dom, squash_artifical_nl=True, strip_artifical_nl=True)
| 71 | |
| 72 | |
| 73 | def 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 | |
| 99 | def extract_text(dom, block_symbol='\n', sep_symbol='\n', squash_space=True): |
no test coverage detected
searching dependent graphs…