Commit: 776e44756c2b9210d8d338edfb5dc504aeb08aa5
Parent: fd4d225ee0938ccbad2600123e383ef99997cc56
Author: Ren Tatsumoto
Date: Sat, 23 Jan 2021 07:59:23 +0300
don't erase highlighting on note update
Diffstat:
1 file changed, 15 insertions(+), 0 deletions(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -328,6 +328,20 @@ do
end
end
+local function update_sentence(new_data, stored_data)
+ -- adds support for TSCs
+ -- https://tatsumoto-ren.github.io/blog/discussing-various-card-templates.html#targeted-sentence-cards-or-mpvacious-cards
+ -- if the target word was marked by yomichan, this function makes sure that the highlighting doesn't get erased.
+ local _, target, _ = stored_data[config.sentence_field]:match('^(.-)<b>(.-)</b>(.-)$')
+ if target then
+ local prefix, _, suffix = new_data[config.sentence_field]:match(table.concat { '^(.-)(', target, ')(.-)$' })
+ if prefix and suffix then
+ new_data[config.sentence_field] = table.concat { prefix, '<b>', target, '</b>', suffix }
+ end
+ end
+ return new_data
+end
+
------------------------------------------------------------
-- utility classes
@@ -535,6 +549,7 @@ local function update_last_note(overwrite)
local stored_data = ankiconnect.get_note_fields(last_note_id)
if stored_data then
new_data = append_forvo_pronunciation(new_data, stored_data)
+ new_data = update_sentence(new_data, stored_data)
if not overwrite then
new_data = join_media_fields(new_data, stored_data)
end