Skip to content

Commit

Permalink
fix broken sync of embedded images in file wikis
Browse files Browse the repository at this point in the history
We should not attempt to concatenate the current directory to `data:`
URIs. It does not work, and because the resulting URI is illegally
long, the error message is misleading to boot.

Fixes #54.
  • Loading branch information
sobjornstad committed Nov 14, 2021
1 parent 59b846f commit 95dcf60
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 16 deletions.
2 changes: 1 addition & 1 deletion anki-plugin/src/twnote.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def extract_media(media: Set[TwMedia], soup: BeautifulSoup, wiki: Wiki,
src = elem.attrs.get('src', None)
if src is not None:
open_src = src
if not '://' in src:
if '://' not in src and not src.startswith('data:'):
# Try reading as a relative path if this is a file or URL wiki,
# as this is a common way to work with _canonical_uri.
# The resulting path is not guaranteed to exist; we'll warn the
Expand Down
4 changes: 2 additions & 2 deletions anki-plugin/src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
Twid = NewType('Twid', str)

DEFAULT_FILTER = '[type[text/vnd.tiddlywiki]] [type[]] +[!is[system]]'
PLUGIN_VERSION = "1.3.0"
COMPATIBLE_TW_VERSIONS = ["", "1.2.2", "1.2.3", "1.3.0"]
PLUGIN_VERSION = "1.3.1"
COMPATIBLE_TW_VERSIONS = ["", "1.2.2", "1.2.3", "1.3.0", "1.3.1"]


def pluralize(sg: str, n: int, pl: str = None) -> str:
Expand Down
5 changes: 3 additions & 2 deletions ankiweb-description.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TiddlyRemember is a tool that integrates <a href="https://tiddlywiki.com" rel="nofollow">TiddlyWiki</a> with Anki. You can interleave questions with your notes in TiddlyWiki, then sync them into Anki notes with one click. You can edit and move the questions around your TiddlyWiki, and they will stay connected to the Anki notes. Scheduling information in Anki is preserved when editing notes in TiddlyWiki.

This is TiddlyRemember version 1.3.0, released November 13, 2021.
This is TiddlyRemember version 1.3.1, released November 14, 2021.

<ul><li><b>Documentation</b>: <a href="https://sobjornstad.github.io/TiddlyRemember/" rel="nofollow">https://sobjornstad.github.io/TiddlyRemember/</a></li>
<li><b>Bug reports and feature requests</b>: <a href="https://github.com/sobjornstad/TiddlyRemember/issues" rel="nofollow">https://github.com/sobjornstad/TiddlyRemember/issues</a>, or email [email protected].</li></ul>
Expand All @@ -11,7 +11,8 @@

<b>Changelog:</b>

<ul><li><b>1.3.0</b>: Many new features, including media syncing, math markup, brace escapes, initial scheduling information, and reading encrypted wikis.
<ul><li><b>1.3.1</b>: Fixed a bug where file wikis could not sync images that were embedded in the wiki.
<li><b>1.3.0</b>: Many new features, including media syncing, math markup, brace escapes, initial scheduling information, and reading encrypted wikis.
<li><b>1.2.3</b>: Anki 2.1.45 support. Fix the <i>remembercz</i> macro accidentally changing the current tiddler.
<li><b>1.2.2</b>: Miscellaneous bugfixes, including permalinks with spurious / at the end and friendlier error messages.
<li><b>1.2.1</b>: Fixed a bug where wikis retrieved from URLs would sometimes produce garbled notes. Only the Anki side was updated in this release, so you do not need to update your TiddlyWiki plugin.</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/tiddlers/TiddlyRemember Metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.0",
"version": "1.3.1",
"compatible-tw5": ">= 5.1.21",
"compatible-anki": ">= 2.1.45",
"repository": "https://github.com/sobjornstad/TiddlyRemember",
Expand Down
2 changes: 1 addition & 1 deletion docs/tiddlers/TiddlyRemember.tid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
created: 20200523154559237
list: [[Installing TiddlyRemember]] [[Configuring TiddlyRemember]] [[Creating notes in TiddlyRemember]] [[Syncing TiddlyRemember with Anki]]
modified: 20211113223822000
modified: 20211114013510000
title: TiddlyRemember
type: text/vnd.tiddlywiki

Expand Down
30 changes: 23 additions & 7 deletions tests/file_wiki.html

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions tests/test_twimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ def test_bad_image_url(fn_params):
assert '404 Not Found' in warnings[0]


def test_file_wiki_embedded_image(fn_params):
"""
An embedded image in a file wiki should come across into a TwNote.
(Regression test: the prepending of a relative path to the URL to work with
_canonical_uri tiddlers broke this in an earlier version.)
"""
fn_params['filter_'] = "EmbeddedImageTest"
fn_params['wiki_path'] = "tests/file_wiki.html"
fn_params['wiki_type'] = "file"
fn_params['warnings'] = []
note = find_notes(**fn_params).pop()
assert not fn_params['warnings']
assert '<img src="tr-' in note.answer


def test_canonical_uri_image(fn_params):
"""
An image given a _canonical_uri with a relative path should come across
Expand Down
2 changes: 1 addition & 1 deletion tw-plugin/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "$:/plugins/sobjornstad/TiddlyRemember",
"description": "TiddlyRemember: Embed Anki notes in your TiddlyWiki",
"author": "Soren Bjornstad",
"version": "1.3.0",
"version": "1.3.1",
"core-version": ">=5.1.21",
"source": "https://github.com/sobjornstad/TiddlyRemember",
"list": "readme license",
Expand Down
2 changes: 1 addition & 1 deletion tw-plugin/templates/TiddlyRememberParseable.tid
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type: text/vnd.tiddlywiki

<$set name="tr-rendering" value="yes">

<span id="tr-version">1.3.0</span>
<span id="tr-version">1.3.1</span>

{{||$:/plugins/sobjornstad/TiddlyRemember/templates/AnkiDecks}}
{{||$:/plugins/sobjornstad/TiddlyRemember/templates/AnkiTags}}
Expand Down

0 comments on commit 95dcf60

Please sign in to comment.