def saveField(note: Note, fld: str, val: str) -> None: if fld == "Tags": # aqt.editor.Editor.saveTags tags = mw.col.tags.split(val) if note.tags == tags: return note.tags = tags elif fld not in note: raise FldNotFoundError(fld) else: # aqt.editor.Editor.onBridgeCmd txt = Editor.mungeHTML(editorwv.editor, val) if note[fld] == txt: return note[fld] = txt mw.checkpoint("Edit Field") note.flush()
def mySave(nid, fld, val): note = mw.col.getNote(nid) # editor L257ff in on onBridgeCmd: # 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", "") # # reverse the url quoting we added to get images to display # txt = self.mw.col.media.escapeImages(txt, unescape=True) txt = urllib.parse.unquote(val) txt = unicodedata.normalize("NFC", txt) txt = Editor.mungeHTML(None, txt) txt = txt.replace("\x00", "") txt = mw.col.media.escapeImages(txt, unescape=True) if note[fld] != txt: note[fld] = txt note.flush()
def saveField(note, fld, val): if fld == "Tags": tagsTxt = unicodedata.normalize("NFC", htmlToTextLine(val)) txt = mw.col.tags.canonify(mw.col.tags.split(tagsTxt)) field = note.tags else: # https://github.com/dae/anki/blob/47eab46f05c8cc169393c785f4c3f49cf1d7cca8/aqt/editor.py#L257-L263 txt = urllib.parse.unquote(val) txt = unicodedata.normalize("NFC", txt) txt = Editor.mungeHTML(None, txt) txt = txt.replace("\x00", "") txt = mw.col.media.escapeImages(txt, unescape=True) field = note[fld] if field == txt: return config = mw.addonManager.getConfig(__name__) if config['undo']: mw.checkpoint("Edit Field") if fld == "Tags": note.tags = txt else: note[fld] = txt note.flush()
def saveField(note, fld, val): if fld == "Tags": tagsTxt = unicodedata.normalize("NFC", htmlToTextLine(val)) txt = mw.col.tags.canonify(mw.col.tags.split(tagsTxt)) field = note.tags else: # aqt.editor.Editor.onBridgeCmd txt = unicodedata.normalize("NFC", val) txt = Editor.mungeHTML(None, txt) txt = txt.replace("\x00", "") txt = mw.col.media.escapeImages(txt, unescape=True) field = note[fld] if field == txt: return if config['undo']: mw.checkpoint("Edit Field") if fld == "Tags": note.tags = txt else: note[fld] = txt note.flush()