From c326aa47b09745b60b25d07de3028f76a119c811 Mon Sep 17 00:00:00 2001 From: retiefjimm Date: Tue, 9 Nov 2010 23:02:33 -0600 Subject: [PATCH] Need to reverse sort entities list to get entities with ';' ahead of versions without. Like '"' and '"'. Otherwise '"' becomes '";'. --- constants.py | 1 - output.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.py b/constants.py index 9f14afb..89b0ef0 100644 --- a/constants.py +++ b/constants.py @@ -157,7 +157,6 @@ acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area', 'b', 'big', acceptable_attributes = ['href'] # entity list from http://code.google.com/p/doctype/wiki/CharacterEntitiesConsistent -# when version without ; is allowed, make sure to put the version with first. entities = { 'á' : 'á', 'Á' : 'Á', 'Á' : 'Á', diff --git a/output.py b/output.py index e756ca5..5244ceb 100644 --- a/output.py +++ b/output.py @@ -339,7 +339,8 @@ def removeEntities(text): # replace several named entities with character, such as — -> - # see constants.py for the list. - for e in entities: + # reverse sort will put entities with ; before the same one without, when valid. + for e in reversed(sorted(entities.keys())): v = entities[e] try: text = text.replace(e, v)