aeidon.Parser

Source: aeidon/parser.py

Anchestors: aeidon.finder.Finder, builtins.object

class aeidon.Parser

Text parser for markup-tag-aware text editing.

Parser.clean_func

Function to clean tags or None

Parser.re_tag

Regular expression object to match any tag

The purpose of Parser is to split text to the actual text and its markup tags, allowing the text to be edited while keeping its tags separate and intact. An example would be replacing all “i”s with “j”s without changing italic markup:

>>> import re
>>> parser = aeidon.Parser(re.compile(r"<.+?>"))
>>> parser.set_text("<i>iii</i>")
>>> parser.pattern = "i"
>>> parser.replacement = "j"
>>> parser.replace_all()
3
>>> parser.get_text()
'<i>jjj</i>'

Methods

Parser.__init__(re_tag=None, clean_func=None)

Initialize a Parser instance.

Parser.get_text()

Reassemble the full text and return it.

Parser.replace(next=True)

Replace the current match of pattern.

next should be True to finish at end of match, False for beginning. Raise re.error if bad replacement.

Parser.set_text(text)

Set the target text to search in and parse it.