The html of each anki button is stored in a list that is joined in a string at the end. This make it easier to run the filter.
Drawback: Only buttons on the right side of the editor can be added using the filter.
- insert resulting html directly into fields instead of relying on
fragile clipboard rewriting
- catch paste events in js and send them back to python so we cover
all possible ways of pasting
- use checksum in pasted image filenames instead of .cacheKey(),
which was not unique across runs
- try each _processX() in turn instead of having special cases inside
them
- rewrite the HTML filtering:
- img rewriting and stripping of certain tags handled in bs4; other
processing handled in js for easier sharing with other clients
- use a whitelist of HTML tags and properties instead of focusing
mainly on webkit cruft
- don't run filter when focus lost, as it no longer seems to
be necessary
- the "strip html" option is currently ignored
Bs4 will raise a warning if the markup (field input) starts with '/'. Suppressing the warning is probably the easiest solution, as Bs4 will still process it (no disadvantages?).
the current code was freezing when clicking on 'cards' in the
browser - it looks like like the javascript callback was never
being called despite calling processEvents(). so we need to
refactor the code to call saveNow() with a callback that does the
subsequent processing.
a lot of the browser code was implicitly calling saveNow() via
beginReset(), so we've had to change all that code to save
immediately before it begins any processing. found a probable bug in
the process - it doesn't look like onRowChange() was saving before
overwriting the note, so theoretically edits could be lost if the
user switched to another card very quickly after typing something.
onSearch() has been split into a GUI-activated onSearchActivated()
that takes care of saving, and a lower level search() that refreshes
the current search. it keeps track of the last search via an instance
variable so that it refreshes properly if a user accidentally adds
some characters to their search without activating the search, then
does something like reverse the sort order.
keyPressEvent/etc no longer work with qwebengineview, so we need to
install an event filter to catch things like ctrl+c. drag & drop
doesn't seem to be supported until 5.7
Adding 'webp' was necessary for Anki to recognize WebP images
(https://developers.google.com/speed/webp/?csw=1) as images rather than
audio. The addition of the audio formats was incidental, as it appears Anki
assumes audio files if a file is not an image file.
Fix error message when editFocusLost is called after editor destruction
https://anki.tenderapp.com/discussions/ankidesktop/11175-bug-in-browser-revealed-by-add-on?unresolve=true
To reproduce:
1. Install the attached add-on. (All it does is register a function on the editFocusLost hook, and set the flag to 1 to signify that a field has been updated).
2. Run Anki. Enter the Browse window. Press Enter to display your deck.
3. Select one card.
4. Click inside one of the fields for that card. Now, when you leave that field, the editFocusLost hook will be called.
5. Now, select 2 notes from the browser, with your mouse, without clicking anywhere else before.
You will observe this error message:
Traceback (most recent call last):
File "aqt/progress.pyc", line 69, in handler
File "aqt/editor.pyc", line 467, in onUpdate
File "aqt/editor.pyc", line 572, in checkValid AttributeError: 'NoneType' object has no attribute 'fields'
the canFocus/canCopy separate variables was silly, as we ended up
with text that could be copied from the context menu but not with
a shortcut key. also we default to allowing focus now, since that's
the more sensible default. fixes copy issues with card info dialog and
some addons
Fixes bug #950. We need to keep an eye out for media filename problems,
as this line is probably not necessary anymore with changes to the way
Anki handles encoding but could potentially introduce issues.
- use html as the first choice for incoming drops/pastes
- when filtering incoming html, automatically localize any remote image
references
- add a special case for pasting/dropping from google images when html
stripping is on
- move filtering code into editor
when a user copies an image from the browser to the clipboard, we need to do
this so the image pastes, as we currently don't support images derived from
html pastes (issue 92)
contrary to commit 3576475, we do need to quote when adding media on windows
as well, as it seems webkit can not handle all representations variants when
passed unicode
as we're stripping # and % when adding characters, hopefully that's the last
of it!
prior to this change, if you entered an empty field, turned on bold,
typed some text, and then backspaced over the text, it would expand
to two lines and the formatting would not go away
- utf8/unicode is valid in the src string, provided we escape quotes
- and we escape when setting fields in the editor, leading to double escaping
if we do that
- and we strip quotes when adding
this means that copying&pasting images on linux/firefox will redownload the
image which is wasteful, but Windows users make up the majority of the
userbase
- allow creation of cloze deletion when note type not selected; warn with
tooltip. prevents selection from getting lost
- warn before adding cloze note type with no deletions
- treat # specially instead of quoting entire string, as urllib unfortunately
can't handle utf8 quoted text
- make sure we pass utf8 to quote() in _addMedia()