|
Transform a text with possible latin-1 characters to the equivalent
valid text in HTML with all special characters with ordinal > 159
encoded as &#number;
Method: convert from plain text (open(filename, 'r')) to utf-8, run
through each character c, if ord(c) > 159, add the HTML encoded text
to a list, otherwise just add c to the list, then finally join the list
to make the new version of the text.
Note: A simpler method is just to set <?xml version="1.0"
encoding="utf-8" ?> as the first line in the HTML file, see
how rst2html.py starts the HTML file. (However, the method below shows
how to cope with special European characters in general.)
|