Link cards/notes and preview them in extra window [Official thread]

Thanks for this report. Your video really helped.

Could you try out the following and let me know if this solves the problem and if it has unintended side effects?

Comment out this line in your add-on source code (e.g. with SublimeText). I mean to add a “#” right in front of the first letter of this line so that it looks like this:

def _on_bridge_cmd(self, cmd):
    super()._on_bridge_cmd(cmd)
    #process_urlcmd(cmd, external_card_dialog, external_note_dialog)

def _create_gui(self):

After you have done this restart Anki.

To find the file: Go to the add-on window. You see the add-on window if in the main window menu bar you click Tools-> Addons. Then select my add-on. Then click the button “View Files”. It’s the file card_window.py

1 Like

it works, bug solved, thank you

1 Like

Copy “cid” context menu in editor and reviewer mode cannot be found.
I use cid more than nid because it is more suitable to see cards.
Also, it’s good to have a simple procedure when the context menu is activated in reviewer mode.
The setting says it’s possible, but it doesn’t show up to me. Can you check it for me.

@havewisdom: Thanks for this report. Your screencast was very useful because I could directly see the problem.

I uploaded a new version that should have fixed this problem. Could you update, restart Anki and try again. If you still have problems let me know.

Thanks for responding.

An error occurs when right-clicking in editor mode to bring up the context menu.
And in reviewer mode, not editor mode, the copy cid & nid menu was still not visible.
The error occurred is as follows.

오류
오류가 발생했습니다. Shift 키를 누른 상태로 Anki를 재실행하십시오, 그러면 설치한 확장 프로그램을 임시로 비활성화합니다.
만약 이 문제가 확장 프로그램이 활성화했을 때만 발생한다면, 도구 > 추가기능 메뉴를 사용해 일부 확장 프로그램을 비활성하고 Anki를 재실행하면 어떤 확장 프로그램이 문제를 발생하는지 찾을 수 있습니다.
어떤 확장 프로그램이 문제를 발생하는지 확인하셨다면, 해당 문제를 확장 프로그램 지원 사이트 (지원사이트)의 확장 기능에 보고해 주십시오.
디버그 정보:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.15.7
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-10-17 11:11:58
관여된 것으로 추정되는 확장 프로그램:⁨link Cards Notes and Preview them in extra window⁩

Caught exception:
Traceback (most recent call last):
File “aqt/editor.py”, line 1203, in contextMenuEvent
File “aqt/gui_hooks.py”, line 1634, in call
File “/Users/seojaehyeon/Library/Application Support/Anki2/addons21/1423933177/editor.py”, line 75, in add_to_context
a.triggered.connect(lambda _, cid=parent.card.id: cidcopy(cid))
AttributeError: ‘EditCurrent’ object has no attribute ‘card’

@havewisdom: Thanks for this report. My quick fix from yesterday actually made the situation worse. Instead of changing the code I should have changed the documentation.

I just uploaded a new version: Do the bugs disappear?

 

Background: Being able to copy a card-id from is indeed very useful. But for many dialogs/windows like AddCards or even EditCurrent Anki doesn’t have the card id. So it’s not easy or quick to add a context menu “copy cid” to these editors. So I just removed the “copy cid” option. I put the EditCurrent part on my (very long term) todo list, see here.

For background about the add cards window, see here.

Did we return to the old state?
No error appears.

Because of the reason you explained, copy cid is not currently visible in some windows,
Are you saying that you promise in somewhere in the future?

I’m using anki better thanks to always. Thank you

I think in effect it’s more or less the same but technically it’s slightly different: Here’s what I did exactly today.

No - it’s just a “maybe”. I have many ideas but too little time. So who knows.

Provides great feature to ANKI.
Q1. I would like for links to work on my Android tablet running AnkiDroid. Where exactly do I paste the javascript you mentioned in my card–is it bottom of styling section? I tried the code but links do not activate on my AnkiDroid cards (works on Windows).

Q2. Is there any way to @include this javascript file? I do this with my card styling section using @import url(); so I just update external file and every note type that uses it gets updated.

Q3. Do I run the Tools->Reference Cards to Media Folder menu item? Is so, when and how often?


My situation is I have language cards from 3 sources (1 fr class I took, 1 fr dictionary I bought, 1 fr 2nd class I am taking at different school). I have a word that is present in all three ‘decks’ but I want to preserve the dictionary and maybe the card from other class (it matches the book/DVD that came with class). So best idea I can come up with is make card for present class and in the footnote field include reference links to dictionary deck (gives overkill information) and previous class’ card. I use tags and also special grouping field in all my cards but using these hyperlinks is cleanest way to access similar information. I need same card in multiple decks but with unique qualities depending on purpose of deck…so this is it!

Where exactly do I paste the javascript you mentioned in my card–is it bottom of styling section?

The last time I used this on Ankidroid was last summer. So maybe it doesn’t work anymore with newer Ankidroid versions. I would try to put the js code into the back template (and not into the styling section).

Is there any way to @include this javascript file? I do this with my card styling section using @import url(); so I just update external file and every note type that uses it gets updated.

My knowledge about js is limited. But I would try <script src=...>

Q3. Do I run the Tools->Reference Cards to Media Folder menu item? Is so, when and how often?

Whenever you have enough new reference info.

Thanks.

I get this type of error for each cid/nid:

TypeError: Cannot set BackendProto.CardID.cid to ‘1607627380264’: ‘1607627380264’ has type <class ‘str’>, but expected one of: (<class ‘int’>,) for field CardID.cid

@yasinefm: Could you update, restart, and try again. I just uploaded a new version that should fix this problem. If the problem persists let me know.

Thanks.
Section below this one is debug info. Two things:

  1. cp1252.py file on my computer is at “H:\Python\Python38-32\Lib\encodings\cp1252.py”; addon references C drive *.py
  2. Not sure if my cp1252.py is the one the addon is expecting. Mine says:

line 18: f.write(txt)
line 82: write_to_file(txt, filename)

I see it created empty file _card1607627380264.html
sorry, not a python guy.


Debug info:
Anki 2.1.32 (dee7d45d) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2020-12-11 16:19:50

Caught exception:
Traceback (most recent call last):
File “F:\Users{username}\AppData\Roaming\Anki2\addons21\1423933177\exporter.py”, line 82, in createReferencesInMedia
write_to_file(txt, filename)
File “F:\Users{username}\AppData\Roaming\Anki2\addons21\1423933177\exporter.py”, line 18, in write_to_file
f.write(txt)
File “C:\python38\lib\encodings\cp1252.py”, line 19, in encode
UnicodeEncodeError: ‘charmap’ codec can’t encode characters in position 823-825: character maps to

@yasinefm: Thanks for this report. I didn’t really test with Windows so I didn’t notice this problem. I just uploaded a new version to ankiweb. Could you update, restart, and try again. If the problem persists let me know.

Getting close maybe. The good news is that on the computer html files were generated for the cards the links are pointing to. The ‘bad’ news, and this is interesting, is:

  1. If I paste the actual javascript in the template back, nothing works and immediately the review pane says:

Invalid HTML on card: SyntaxError: Invalid or unexpected token SyntaxError: Invalid or unexpected token at eval () at http://127.0.0.1:51329/_anki/jquery.js:2:2651 at Function.globalEval (http://127.0.0.1:51329/_anki/jquery.js:2:2662) at Ha (http://127.0.0.1:51329/_anki/jquery.js:3:21262) at n.fn.init.append (http://127.0.0.1:51329/_anki/jquery.js:3:22791) at n.fn.init. (http://127.0.0.1:51329/_anki/jquery.js:3:24070) at Y (http://127.0.0.1:51329/_anki/jquery.js:3:4515) at n.fn.init.html (http://127.0.0.1:51329/_anki/jquery.js:3:23660) at HTMLDivElement. (http://127.0.0.1:51329/_anki/reviewer.js:33:16) at HTMLDivElement.d.complete (http://127.0.0.1:51329/_anki/jquery.js:4:6203)

  1. The links still do not work on AnkiDroid. They work on the computer when running Anki but only if I point to the JS in external file using

<script src="_js_linkcards.js"></script>

which is actual great since I prefer to use JS in external file then reference from Anki; that way I only have to modify the JS file not every note template–makes updates really easy.

I have no idea about the error message you get. As I said my js knowledge is very limited. It seems the jquery that’s bundled with anki is executed. But that’s an old version 1.12 whereas my linked back template code uses jquery version 3.3.1.

Maybe that’s because you have the js in an external file? To check this: You could try to put the code in the back template. If it works: If you have many note types maybe Asset Manager is useful? I haven’t tried it.

If it still doesn’t work: I don’t know.

 

I just tested and found this:

  • When trying to write some notes into my media folder (Tools -> Reference Cards to media folder) some files weren’t written. I have just upload a new version that should hopefully fix this problem.
  • I ran Tools -> Reference Cards to media folder. Then I copied the linked text to a back template of a note type. Then I made a new note and wrote nidd1234567890123 (replace 1234567890123 with a nid that’s actually used in your collection) to a field that’s in my back template = that’s shown in the answer when reviewing. Then I synced to ankidroid (latest version from google play). It still works for me. I get an iframe that shows the exported note.

Greetings. I kinda got to work (I won’t go into the details of what I had to do and what I did not initially understand about the JS file) but the “Dictionary” deck I have doesn’t render too well in iframe so I have abandoned using this addon on AnkiDroid. It works well on computer so I will still use it there.

One thing I would like to see is an option to ‘disable’ a card linking to itself (and maybe changing the color if it is a link to itself). The reason I put a link to itself there in the first place is because say I have three cards that I want to be able to reference to each other. I just copy/paste the links of all three into the note’s footnote field. But I don’t want to have two preview windows for the same card or note open at the same time. So nice to be able to disable current card’s link.


FYI, I decided for now that it is OK to have duplicates (or nearly duplicate) cards, that is that they may have the same information in the “Front” field on each card. I use a useful (but surprisingly not well known) addon called Flexible Duplicate Checking that allows me to not flag duplicates on a single matching field; this allows me to differentiate the cards using a second field I call “CardID_pk” and have one card in the dictionary deck and one in the class handouts deck both with the same word in “Front” field, plus using " link Cards Notes and Preview them in extra window" addon to document (and access) both of them in the footnotes field.

I’m glad you found a way to make it somewhat work for you.

I see that your feature request would be useful in some cases. So I added a reminder for myself here. But since I don’t use this idea it’s low priority for me so I can’t say if and when I’ll implement this.

Hello! Some cards have a CIDD of 15 bits, but Anki seems to be able to read only the first 13 bits, making it impossible to use. What should I do?

@renfan: “cidd” is a string of characters I chose as a pretty unique prefix so that I can e.g. easily search for my cusotm links. It’s derived from “cid” which stands for “card id”. Each note has a unique id that Anki assigns to it. It’s a 13digit string (creation time of the card in epoch time in milliseconds). So cids made by Anki will be 13 digits for the coming years (= ~ two centuries).

Some add-ons create/manipulate cids and in theor if you had a buggy add-on you could have a card with a card-id with 15 digits. you could search in your browser for the cid in your screenshot (and the first 13 digits), see Anki Manual

my add-on doesn’t change card-ids, it just reads what you have in the database.

does this help?