From c68208089072653637df62205e6ce22a74b2a1f2 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 5 Apr 2011 20:28:21 +0900 Subject: [PATCH] make it easier to get media dir; remove tidyHTML() --- anki/deck.py | 2 +- anki/importing/csvfile.py | 1 - anki/media.py | 3 +++ anki/utils.py | 24 ------------------------ 4 files changed, 4 insertions(+), 26 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index fb333f900..bef46d789 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -4,7 +4,7 @@ import time, os, random, re, stat, simplejson, datetime, copy from anki.lang import _, ngettext -from anki.utils import parseTags, tidyHTML, ids2str, hexifyID, \ +from anki.utils import parseTags, ids2str, hexifyID, \ checksum, fieldChecksum, addTags, delTags, stripHTML, intTime, \ splitFields from anki.hooks import runHook, runFilter diff --git a/anki/importing/csvfile.py b/anki/importing/csvfile.py index b75c50489..3d68b2e8c 100644 --- a/anki/importing/csvfile.py +++ b/anki/importing/csvfile.py @@ -6,7 +6,6 @@ import codecs, csv, re from anki.importing import Importer, ForeignCard from anki.lang import _ from anki.errors import * -from anki.utils import tidyHTML class TextImporter(Importer): diff --git a/anki/media.py b/anki/media.py index dc909177e..2ea090001 100644 --- a/anki/media.py +++ b/anki/media.py @@ -20,8 +20,11 @@ class MediaRegistry(object): self._updateDir() def dir(self, create=False): + "Call with create=None to retrieve dir without creating." if self._dir: return self._dir + elif create == None: + return self._updateDir(create) elif create: self._updateDir(True) return self._dir diff --git a/anki/utils.py b/anki/utils.py index 19b99d831..2d6722b15 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -149,30 +149,6 @@ def minimizeHTML(s): '\\1', s) return s -def tidyHTML(html): - "Remove cruft like body tags and return just the important part." - # contents of body - no head or html tags - html = re.sub(u".*(.*)", - "\\1", html.replace("\n", u"")) - # strip superfluous Qt formatting - html = re.sub(u"(?:-qt-table-type: root; )?" - "margin-top:\d+px; margin-bottom:\d+px; margin-left:\d+px; " - "margin-right:\d+px;(?: -qt-block-indent:0; " - "text-indent:0px;)?", u"", html) - html = re.sub(u"-qt-paragraph-type:empty;", u"", html) - # strip leading space in style execute, and remove if no contents - html = re.sub(u'style=" ', u'style="', html) - html = re.sub(u' style=""', u"", html) - # convert P tags into SPAN and/or BR - html = re.sub(u'(.*?)

', u'\\2
', html) - html = re.sub(u'

(.*?)

', u'\\1
', html) - html = re.sub(u'
$', u'', html) - html = re.sub(u"^
(.*)
$", u"\\1", html) - # this is being added by qt's html editor, and leads to unwanted spaces - html = re.sub(u"^

(.*?)

$", u'\\1', html) - html = minimizeHTML(html) - return html - def entsToTxt(html): def fixup(m): text = m.group(0)