mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
canonicalize to NFC form on edit/import
This commit is contained in:
parent
2539896b22
commit
6335dcb90e
2 changed files with 9 additions and 1 deletions
|
@ -3,6 +3,9 @@
|
|||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import cgi
|
||||
|
||||
import unicodedata
|
||||
|
||||
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
|
||||
from anki.lang import _
|
||||
from anki.utils import fieldChecksum, guid64, timestampID, \
|
||||
|
@ -126,6 +129,8 @@ class NoteImporter(Importer):
|
|||
n.fields[c] = n.fields[c].strip()
|
||||
if not self.allowHTML:
|
||||
n.fields[c] = n.fields[c].replace("\n", "<br>")
|
||||
n.fields[c] = unicodedata.normalize("NFC", n.fields[c])
|
||||
n.tags = [unicodedata.normalize("NFC", t) for t in n.tags]
|
||||
fld0 = n.fields[fld0idx]
|
||||
csum = fieldChecksum(fld0)
|
||||
# first field must exist
|
||||
|
|
|
@ -10,6 +10,7 @@ import warnings
|
|||
import html
|
||||
import mimetypes
|
||||
import base64
|
||||
import unicodedata
|
||||
|
||||
from anki.lang import _
|
||||
from aqt.qt import *
|
||||
|
@ -569,6 +570,7 @@ class Editor:
|
|||
if cmd.startswith("blur") or cmd.startswith("key"):
|
||||
(type, txt) = cmd.split(":", 1)
|
||||
txt = urllib.parse.unquote(txt)
|
||||
txt = unicodedata.normalize("NFC", txt)
|
||||
txt = self.mungeHTML(txt)
|
||||
# misbehaving apps may include a null byte in the text
|
||||
txt = txt.replace("\x00", "")
|
||||
|
@ -763,8 +765,9 @@ class Editor:
|
|||
def saveTags(self):
|
||||
if not self.note:
|
||||
return
|
||||
tagsTxt = unicodedata.normalize("NFC", self.tags.text())
|
||||
self.note.tags = self.mw.col.tags.canonify(
|
||||
self.mw.col.tags.split(self.tags.text()))
|
||||
self.mw.col.tags.split(tagsTxt))
|
||||
self.tags.setText(self.mw.col.tags.join(self.note.tags).strip())
|
||||
if not self.addMode:
|
||||
self.note.flush()
|
||||
|
|
Loading…
Reference in a new issue