Text rewrite rules
Your task
A documentation build pushes every source line through a chain of text rewrite rules. Each entry of rules is written "find|replace" and splits on its FIRST bar only, so the find text never holds a bar but the replacement may. Run the rules over a line in the order given, each rule finishing the whole line before the next one starts, so a later rule works on what the earlier ones produced. Inside one rule, scan left to right and replace every occurrence, resuming after the text just inserted, so a rule never rewrites its own output. Matching is case sensitive. Skip any rule whose find text is empty, since it would match everywhere. Return the rewritten lines in the order they were given.
Examples
apply_rewrite_chain(lines: list[str], rules: list[str]) -> list[str]Example 1
Input
apply_rewrite_chain(["ship TODO by friday"], ["TODO|FIXME"])Output
["ship FIXME by friday"]Example 2
Input
apply_rewrite_chain(["alpha"], ["alpha|beta", "beta|gamma"])Output
["gamma"]Example 3
Input
apply_rewrite_chain(["aaaa"], ["aa|a"])Output
["aa"]