Skip to content

Commit 95dcf60

Browse files
committed
fix broken sync of embedded images in file wikis
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.
1 parent 59b846f commit 95dcf60

File tree

9 files changed

+49
-16
lines changed

9 files changed

+49
-16
lines changed

anki-plugin/src/twnote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def extract_media(media: Set[TwMedia], soup: BeautifulSoup, wiki: Wiki,
640640
src = elem.attrs.get('src', None)
641641
if src is not None:
642642
open_src = src
643-
if not '://' in src:
643+
if '://' not in src and not src.startswith('data:'):
644644
# Try reading as a relative path if this is a file or URL wiki,
645645
# as this is a common way to work with _canonical_uri.
646646
# The resulting path is not guaranteed to exist; we'll warn the

anki-plugin/src/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
Twid = NewType('Twid', str)
1212

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

1717

1818
def pluralize(sg: str, n: int, pl: str = None) -> str:

ankiweb-description.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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.
22

3-
This is TiddlyRemember version 1.3.0, released November 13, 2021.
3+
This is TiddlyRemember version 1.3.1, released November 14, 2021.
44

55
<ul><li><b>Documentation</b>: <a href="https://sobjornstad.github.io/TiddlyRemember/" rel="nofollow">https://sobjornstad.github.io/TiddlyRemember/</a></li>
66
<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>
@@ -11,7 +11,8 @@
1111

1212
<b>Changelog:</b>
1313

14-
<ul><li><b>1.3.0</b>: Many new features, including media syncing, math markup, brace escapes, initial scheduling information, and reading encrypted wikis.
14+
<ul><li><b>1.3.1</b>: Fixed a bug where file wikis could not sync images that were embedded in the wiki.
15+
<li><b>1.3.0</b>: Many new features, including media syncing, math markup, brace escapes, initial scheduling information, and reading encrypted wikis.
1516
<li><b>1.2.3</b>: Anki 2.1.45 support. Fix the <i>remembercz</i> macro accidentally changing the current tiddler.
1617
<li><b>1.2.2</b>: Miscellaneous bugfixes, including permalinks with spurious / at the end and friendlier error messages.
1718
<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>

docs/tiddlers/TiddlyRemember Metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.3.0",
2+
"version": "1.3.1",
33
"compatible-tw5": ">= 5.1.21",
44
"compatible-anki": ">= 2.1.45",
55
"repository": "https://github.com/sobjornstad/TiddlyRemember",

docs/tiddlers/TiddlyRemember.tid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
created: 20200523154559237
22
list: [[Installing TiddlyRemember]] [[Configuring TiddlyRemember]] [[Creating notes in TiddlyRemember]] [[Syncing TiddlyRemember with Anki]]
3-
modified: 20211113223822000
3+
modified: 20211114013510000
44
title: TiddlyRemember
55
type: text/vnd.tiddlywiki
66

tests/file_wiki.html

Lines changed: 23 additions & 7 deletions
Large diffs are not rendered by default.

tests/test_twimport.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ def test_bad_image_url(fn_params):
201201
assert '404 Not Found' in warnings[0]
202202

203203

204+
def test_file_wiki_embedded_image(fn_params):
205+
"""
206+
An embedded image in a file wiki should come across into a TwNote.
207+
208+
(Regression test: the prepending of a relative path to the URL to work with
209+
_canonical_uri tiddlers broke this in an earlier version.)
210+
"""
211+
fn_params['filter_'] = "EmbeddedImageTest"
212+
fn_params['wiki_path'] = "tests/file_wiki.html"
213+
fn_params['wiki_type'] = "file"
214+
fn_params['warnings'] = []
215+
note = find_notes(**fn_params).pop()
216+
assert not fn_params['warnings']
217+
assert '<img src="tr-' in note.answer
218+
219+
204220
def test_canonical_uri_image(fn_params):
205221
"""
206222
An image given a _canonical_uri with a relative path should come across

tw-plugin/plugin.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "$:/plugins/sobjornstad/TiddlyRemember",
33
"description": "TiddlyRemember: Embed Anki notes in your TiddlyWiki",
44
"author": "Soren Bjornstad",
5-
"version": "1.3.0",
5+
"version": "1.3.1",
66
"core-version": ">=5.1.21",
77
"source": "https://github.com/sobjornstad/TiddlyRemember",
88
"list": "readme license",

tw-plugin/templates/TiddlyRememberParseable.tid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type: text/vnd.tiddlywiki
88

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

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

1313
{{||$:/plugins/sobjornstad/TiddlyRemember/templates/AnkiDecks}}
1414
{{||$:/plugins/sobjornstad/TiddlyRemember/templates/AnkiTags}}

0 commit comments

Comments
 (0)