Skip to content

Commit

Permalink
feat: add targetWordNoSyntax and sentenceNoSyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel committed Feb 5, 2024
1 parent 6710ff7 commit 5bd00a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/card_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from base64 import b64decode
from dataclasses import dataclass, field
import re
from typing import Optional
import requests

Expand All @@ -26,7 +27,9 @@ class ImageAsset:
@dataclass
class CardFields:
targetWord: str = ""
targetWordNoSyntax: str = ""
sentence: str = ""
sentenceNoSyntax: str = ""
translation: str = ""
definitions: str = ""
sentenceAudio: str = ""
Expand Down Expand Up @@ -63,6 +66,7 @@ def process_audio_asset(audio: AudioAsset):

return f"[sound:{name}]"

REMOVE_RE = re.compile(r"( +|\[(?!sound:).*?\])(?![^{]*})")

def card_fields_from_dict(data: dict[str, any]):
br = "\n<br>\n"
Expand All @@ -86,9 +90,17 @@ def card_fields_from_dict(data: dict[str, any]):
restImages = br.join(images[1:])
imagess = br.join(images)

targetWord = data.get("targetWord", "")
targetWordNoSyntax = REMOVE_RE.sub("", targetWord)

sentence = data.get("sentence", "")
sentenceNoSyntax = REMOVE_RE.sub("", sentence)

return CardFields(
targetWord=data.get("targetWord", ""),
sentence=data.get("sentence", ""),
targetWord=targetWord,
targetWordNoSyntax=targetWordNoSyntax,
sentence=sentence,
sentenceNoSyntax=sentenceNoSyntax,
translation=data.get("translation", ""),
definitions=data.get("definitions", ""),
sentenceAudio=sentenceAudios,
Expand Down
4 changes: 3 additions & 1 deletion src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ MigakuEditor.hideButtons = function () {
const selectorOptions = [
{ value: 'none', text: '(None)' },
{ value: 'sentence', text: 'Sentence' },
{ value: 'targetWord', text: 'Word' },
{ value: 'sentenceNoSyntax', text: 'Sentence (no syntax)' },
{ value: 'targetWord', text: 'Target Word' },
{ value: 'targetWordNoSyntax', text: 'Target Word (no syntax)' },
{ value: 'translation', text: 'Sentence Translation' },
{ value: 'sentenceAudio', text: 'Sentence Audio' },
{ value: 'wordAudio', text: 'Word Audio' },
Expand Down
1 change: 0 additions & 1 deletion src/migaku_connection/card_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ..card_types import CardFields, card_fields_from_dict
from ..editor.current_editor import (
add_cards_add_to_history,
get_add_cards,
get_add_cards_info,
map_to_add_cards,
)
Expand Down

0 comments on commit 5bd00a8

Please sign in to comment.