feat: Highlight term upon setting it SentenceListeningNote
This commit is contained in:
parent
e3064a3ace
commit
1ff04811cb
|
@ -94,4 +94,18 @@ class Note
|
|||
{
|
||||
return \DateTimeImmutable::createFromFormat('U', $this->mod);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------- Utility functions ---
|
||||
|
||||
protected static function stringHighlight(string $haystack, string $needle)
|
||||
{
|
||||
$replace = sprintf(
|
||||
'<span %s>%s</span>',
|
||||
self::HIGHLIGHT_ATTR_KANJI,
|
||||
$needle,
|
||||
);
|
||||
|
||||
return str_replace($needle, $replace, strip_tags($haystack));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ class SentenceListeningNote extends Note
|
|||
$this->fields['VocabKanji'] = $term->getKanji();
|
||||
$this->fields['VocabFurigana'] = $term->getReading();
|
||||
$this->fields['VocabDef'] = $term->toAnkiVocabDef();
|
||||
$this->fields['SentKanji'] = $this->stringHighlight(
|
||||
$this->fields['SentKanji'],
|
||||
$term->getKanji(),
|
||||
);
|
||||
$this->term = $term;
|
||||
return $this;
|
||||
}
|
||||
|
@ -55,8 +59,6 @@ class SentenceListeningNote extends Note
|
|||
|
||||
// Related fields are updated using the setter
|
||||
$slNote->setTerm($term);
|
||||
// Remove highlighting
|
||||
$slNote->fields['SentKanji'] = strip_tags($slNote->fields['SentKanji']);
|
||||
// Reset relations and basic data
|
||||
$slNote->id = null;
|
||||
$slNote->model = self::MODEL_NAME;
|
||||
|
|
Loading…
Reference in New Issue