Merge pull request #114 from timrae/export-deck-media
Don't include media files with _ unless they are referenced in model
This commit is contained in:
commit
965b3055a9
@ -203,7 +203,12 @@ class AnkiExporter(Exporter):
|
||||
if self.mediaDir:
|
||||
for fname in os.listdir(self.mediaDir):
|
||||
if fname.startswith("_"):
|
||||
media[fname] = True
|
||||
# Scan all models in mids for reference to fname
|
||||
for m in self.src.models.all():
|
||||
if int(m['id']) in mids:
|
||||
if self._modelHasMedia(m, fname):
|
||||
media[fname] = True
|
||||
break
|
||||
self.mediaFiles = media.keys()
|
||||
self.dst.crt = self.src.crt
|
||||
# todo: tags?
|
||||
@ -220,6 +225,16 @@ class AnkiExporter(Exporter):
|
||||
def removeSystemTags(self, tags):
|
||||
return self.src.tags.remFromStr("marked leech", tags)
|
||||
|
||||
def _modelHasMedia(self, model, fname):
|
||||
# First check the styling
|
||||
if fname in model["css"]:
|
||||
return True
|
||||
# If no reference to fname then check the templates as well
|
||||
for t in model["tmpls"]:
|
||||
if fname in t["qfmt"] or fname in t["afmt"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
# Packaged Anki decks
|
||||
######################################################################
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user