@facelessuser: Signing off now, you’ll be pleased to hear.
I’m v. happy with my code but I think I’ll explore a couple of ideas tomorrow evening - just for my own Python education:
-
I’m storing the spans in a temporary string before writing to the file. If, instead, I store a list of tuples (tidied_text, the_colour) then I can perform the entity-escaping, etc., in one fell swoop, perhaps with a list comprehension.
-
I’d like to gain a better understanding of generators. It’s screaming at me that processing spans within a line could be a good example for this. (This is probably an alternative to 1.)
BTW A while ago (yesterday? can’t remember) I did notice ‘\r’ popping up on occasion, but presumably split_by_newlines has removed this issue. Personally, I’m using:
tidied_text = tidied_text.replace('\t', ' ' * self.tab_size).strip('\r\n')
But, as I say, it’s probably no longer an issue.
Laterz, Andy.