~ubuntu-branches/ubuntu/natty/anki/natty

« back to all changes in this revision

Viewing changes to libanki/anki/exporting.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Bombe
  • Date: 2010-10-22 12:50:51 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20101022125051-hrscik3rhw9z31zh
Tags: 1.0.1-1
* Imported Upstream version 1.0.1 (Closes: #598167)
* Upstream version no longer contains string exceptions (Closes:
  #585262)
* Use getlocale(LC_MESSAGES) for default interface language instead of
  getdefaultlocale() (Closes: 576158)
* Switch to version 3.0 (quilt) package format
* Bump Standards-Version to 3.9.1, no changes necessary
* Remove some more code from libanki/anki/lang.py that is not needed
  with the fixed locale path patch
* Add Vcs-Git control fields pointing to the collab-maint repository
  on Alioth
* Remove *.anki exclusion on dh_compress, left over from time when
  example decks were included
* In anki launcher set sys.path[0] to /usr/share/anki rather than
  prepending it to sys.path
* debian/copyright: Copy list of contributors from about dialog

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
"""
9
9
__docformat__ = 'restructuredtext'
10
10
 
11
 
import itertools, time, re, os
 
11
import itertools, time, re, os, HTMLParser
12
12
from operator import itemgetter
13
13
from anki import DeckStorage
14
14
from anki.cards import Card
17
17
from anki.utils import findTag, parseTags, stripHTML, ids2str
18
18
from anki.tags import tagIds
19
19
from anki.db import *
20
 
from BeautifulSoup import BeautifulSoup as BS
21
20
 
22
21
class Exporter(object):
23
22
    def __init__(self, deck):
33
32
 
34
33
    def escapeText(self, text, removeFields=False):
35
34
        "Escape newlines and tabs, and strip Anki HTML."
 
35
        from BeautifulSoup import BeautifulSoup as BS
36
36
        text = text.replace("\n", "<br>")
37
37
        text = text.replace("\t", " " * 8)
38
38
        if removeFields:
40
40
            self._escapeCount += 1
41
41
            if self._escapeCount % 100 == 0:
42
42
                self.deck.updateProgress()
43
 
            s = BS(text)
44
 
            all = s('span', {'class': re.compile("fm.*")})
45
 
            for e in all:
46
 
                e.replaceWith("".join([unicode(x) for x in e.contents]))
47
 
            text = unicode(s)
 
43
            try:
 
44
                s = BS(text)
 
45
                all = s('span', {'class': re.compile("fm.*")})
 
46
                for e in all:
 
47
                    e.replaceWith("".join([unicode(x) for x in e.contents]))
 
48
                text = unicode(s)
 
49
            except HTMLParser.HTMLParseError:
 
50
                pass
48
51
        return text
49
52
 
50
53
    def cardIds(self):