ignore parse errors due to invalid html on export

This commit is contained in:
Damien Elmes 2010-06-28 11:52:25 +09:00
parent f03000d27b
commit b8401eff22

View file

@ -8,7 +8,7 @@ Exporting support
""" """
__docformat__ = 'restructuredtext' __docformat__ = 'restructuredtext'
import itertools, time, re, os import itertools, time, re, os, HTMLParser
from operator import itemgetter from operator import itemgetter
from anki import DeckStorage from anki import DeckStorage
from anki.cards import Card from anki.cards import Card
@ -40,11 +40,14 @@ class Exporter(object):
self._escapeCount += 1 self._escapeCount += 1
if self._escapeCount % 100 == 0: if self._escapeCount % 100 == 0:
self.deck.updateProgress() self.deck.updateProgress()
s = BS(text) try:
all = s('span', {'class': re.compile("fm.*")}) s = BS(text)
for e in all: all = s('span', {'class': re.compile("fm.*")})
e.replaceWith("".join([unicode(x) for x in e.contents])) for e in all:
text = unicode(s) e.replaceWith("".join([unicode(x) for x in e.contents]))
text = unicode(s)
except HTMLParser.HTMLParseError:
pass
return text return text
def cardIds(self): def cardIds(self):