Once I wanted to automate the preparation of text for conversion to LaTeX. Starting with simple replacements, I got carried away with the process. In the end, it turned out something like a typographer.
Good sources of ideas were the “ Typography in Python ” topic and the list of rules from the “ Public flogging of online typographers ”. I tried to describe only unambiguous, easily implemented rules. Of course, not everything was possible to realize, and as soon as it became clear that an acceptable level had been reached, I decided to publish my work.