Skip to content

Commit

Permalink
Return GenericImporter to previous behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
1over137 committed Mar 20, 2024
1 parent 946412b commit 5564886
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vocabsieve/importer/GenericImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def defineWords(self) -> None:
new_note_item = SRSNote(
word=word, # fine if no definition
sentence=sentence, # fine if empty string
definition1=definition1.definition if definition1 is not None else None,
definition2=definition2.definition if definition2 is not None else None,
definition1=self._parent.definition.toAnki(definition1) if definition1 is not None else None,
definition2=self._parent.definition2.toAnki(definition2) if definition2 is not None else None,
audio_path=audio_path or None,
tags=tags
)
Expand Down
13 changes: 8 additions & 5 deletions vocabsieve/ui/multi_definition_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,17 @@ def getSource(self, source_name: str) -> Optional[DictionarySource]:
return source
return None

def toAnki(self) -> str:
def toAnki(self, defi: Optional[Definition] = None) -> str:
"""Process definitions before sending to Anki"""
# Figure out display mode of current source
if self.currentDefinition is None:
return self.toPlainText().replace("\n", "<br>")
maybe_user_typed_text = self.toPlainText().replace("\n", "<br>")
if defi is not None: # for non-interactive use
self.setCurrentDefinition(defi)
if self.currentDefinition is None: # This means no definition is found but maybe the user typed in something
return maybe_user_typed_text
source_name = self.currentDefinition.source
source = self.getSource(source_name)
if source is None: # This means no definition is found but maybe the user typed in something
return self.toPlainText().replace("\n", "<br>")
if source is None:
raise ValueError(f"Source {source_name} not found, cannot process definition for Anki")

return process_defi_anki(self.toPlainText(), self.toMarkdown(), self.currentDefinition, source)

0 comments on commit 5564886

Please sign in to comment.