Add Hyperlink [Official thread]

Dear Ijgnd,

Thanks for your prompt answer. You are right it looks like it’s an Anki issue. You can close my request as solved.

I still appreciate using the Add Hyperlink add-on.

Steph

Please add it to make it look like this

@Yoekr: That looks nice. I’ve added this to the todo list but I don’t have time to work on this for the next year.

Hello @ijgnd,

Thank you for making simple but very helpful add-on ‘Add Hyperlink’.
Back in the day, this add-on worked perfectly, but now I can see some problems.

This is NOT a serious problem for me, but hopefully you would recognize this case.

Problem

Wherever the current cursor is, hyperlink is always added on top of the flashcard

Steps to reproduce

  1. Start Anki2
  2. Press ‘a’ to add a flashcard
  3. Write following contents into the card for example:
aaa

  1. Make sure the text cursor is at the end of the flashcard.
  2. Press Ctrl+Shift+H to call ‘Add Hyperlink’ add-on.
  3. Specify ‘Link to: link’ and ‘Text to display: text’ and select ‘OK’ to insert a hyperlink.

Expected result

The flashcard should look like the following, where text encompasses hyperlink information to link

aaa
text

Actual result

The flashcard was actually like the following. The hyperlink text is added on top of the flashcard.

textaaa

My environment

It first happened on my main machine.

  • Fedora 37
  • Python 3.11.0
  • Anki 2.1.55 Qt6 (, and 2.1.55 Qt5)

Just in case, I also confirmed the issue could be reproduced in the following environment.

  • CentOS Stream 8
  • Python 3.9.14
  • Anki 2.1.55 Qt6

Additional information

I also tested on older version of ‘Add Hyperlink’ and ‘Anki2’ by reverting either ‘Add Hyperlink’ or ‘Anki2’, but I couldn’t see the problem fixed.
Maybe I needed to revert both to the specific version to find the point of time when the issue was introduced.
Sorry for the non-helpful information.

@ijgnd: Sorry for posting multiple times, but I also found another similar issue.

Problem

With the text selected, press Ctrl+Shift+H to insert a hyperlink, then hyperlink is added to the different place with a different text, and with a correct link.

Steps to reproduce

  1. Start Anki2
  2. Press ‘a’ to add a flashcard
  3. Write following contents into the card for example:
text
  1. Make sure that text is selected.
  2. Press Ctrl+Shift+H to call ‘Add Hyperlink’ add-on.
  3. Specify ‘Link to: link’ and leave 'Text to display: ’ to ‘text’.
  4. Select ‘OK’ to insert a hyperlink.

Expected result

The flashcard should look like the following, where text has hyperlink information to link

text

Actual result

The flashcard was actually like the following. The hyperlink link is added on top of the flashcard, which links to link.

linktext

thanks for these great bug reports. I’m really busy at the moment so I can’t look into this before early March. I’ve added this to my todo list.

1 Like

Thank you too for sparing your time to reply. Please take your time as I still enjoy using hyperlink with Anki.

@stopendy: I finally looked into your two bugs reported:

  1. the bug that text always got inserted at the beginning of a field. I can reproduce this error in the version that you used some months ago (2.1.55) but no longer in the following version 2.1.56, see Wherever the current cursor is, hyperlink is always added on top of the flashcard · Issue #18 · ijgnd/anki21__editor_add_hyperlink · GitHub I think this issue no longer needs attention.
  2. the bug that selected text is no longer replaced with a hyperlink. I made some changes that seem to work on my machine. Could you test out this new version: https://github.com/ijgnd/anki21__editor_add_hyperlink/releases/download/2023-04-test/anki21__editor_add_hyperlink__2023-04-22.ankiaddon Drag and drop onto anki or the add-on window should work. When anki checks for updates the next time (usually once per day) you’ll probably get the old version back. When you report that it works, I’ll upload this new version

btw: what do you think about the new radio buttons to prefix incomplete urls with http:// or https:// ?

Although @ijgnd could confirm that he/she could reproduce the issue, but I will add some information to reproduce it.

In step 4, you need to select exactly the word text with shift + right arrow or something. If you select text with Ctrl+A, where selection includes a new line character, you couldn’t reproduce the issue.

  1. Make sure that text is selected.

@ijgnd: Thank you very much for your support on solving two issues I reported! I could confirm they are solved as you said.

  1. the bug that text always got inserted at the beginning of a field. I don’t see this error after upgrading Anki from 2.1.55 to 2.1.61. Thank you for testing!
  2. the bug that selected text is no longer replaced with a hyperlink. After upgrading to the version you uploaded, it works like a charm. It’s awesome!

btw: what do you think about the new radio buttons to prefix incomplete urls with http:// or https:// ?

I guess this enhancement is great in terms of added stability, and ability to reflect user preference.

added stability

I tested with several link texts and checked what link was actually inserted with the current release version of ‘Add Hyperlink’ (2022-05-23). For example, when I specified link as ‘Link to:’, the hyperlink URL I finally got was http://127.0.0.1:33421/link.

link: http://127.0.0.1:33421/link
localhost: http://127.0.0.1:33421/localhost
localhost:8080: localhost:8080

Your test release 2023-04-22 is great in terms of stability. Using this version, I could get some predictable results as following:

link: http://link/
localhost: http://localhost/
localhost:8080: http://localhost:8080/

I know “inserting a link without ‘http://’ or ‘https://’” is a corner case, but I guess this enhancement contributes to the stability of “Add Hyperlink” add-on.

ability to reflect user preference

I noticed that I could configure the default value of the radio button from the add-on configuration window (*). This is great! People who want to just add links without ‘http://’ or ‘https://’ can opt out by specifying ‘nothing’, and they can also set ‘nothing’ as default with this option. Before the release, maybe you can add the description for this option so users can figure out how to use this option.

(*) How to edit the option:

1. Open Anki
2. Navigate to [Tools] > [Add-ons] (Ctrl+Shift+A)
3. Select "Add Hyperlink"
4. Select "Config"
5. Locate the configuration item "prepend incomplete url default" and choose one of "http", "https", or "nothing"

Thanks for your great feedback… I just noticed that the bug that text is always inserted at the beginning of a field still occurs on my other machine. So the bug is not fixed. I uploaded what I had - maybe this is at least an improvement over the current situation. I’ll look into this again.

1 Like

@ijgnd

Thank you for the release!

I just noticed that the bug that text is always inserted at the beginning of a field still occurs on my other machine.

I’ve just figured out how to reproduce the bug that text is always inserted at the beginning of a field.

Steps To Reproduce

  1. Start Anki
  2. Press ‘a’ to open a card.
  3. Type following input. Make sure that your input cursor is at the end.
aaa
bbb
  1. Press Ctrl+Shift+H to call ‘Add Hyperlink’.

  2. Assign following values to the add-on. nothing option is the key to reproduce the issue.

    • Link to: aaa
    • prepend missing scheme: nothing
    • Text to display: bbb
  3. Once you reproduce the issue, the bug happens again even if you select http/https as prepend missing scheme. When you close the card editor, the issue won’t happen until you select nothing as prepend missing scheme again.

Workaround

As long as we use http or https as prepend missing scheme, this issue won’t happen.

Version Information

I tested on the following environments.

  • Anki 2.1.61 with Add Hyperlink 2023-04-test
  • Anki 2.1.61 with Add Hyperlink 2023-04-30

@stopendy : I just uploaded a new version of “add hyperlink” that should fix the issue of the hyperlink being inserted at the beginning of a field. I think it was a random timing issue since 2.1.50. Could you update your addons, restart anki, and try again. Let me know if you run into problems. thanks.

@ijgnd : I’m very grateful for solving this complicated issue of the hyperlink being inserted at the beginning of a field" I could confirm that this issue has gone in Anki 2.1.61 with “add hyperlink” version 2023-06-18. With the fixes and enhancement that were added recently, “add hyperlink” has become even more perfect!

Since the issue is confirmed to be solved, you can remove “known issues” information in the following add-on download page.
Add Hyperlink

Cheers.

@stopendy : Once more thanks for careful testing (and reading the addon description). Your input really helped.

1 Like

if someone is interested:
today i just found there is no popup tooltip to show what’s the content of the link, the URL.

i asked in the forum,
then i asked gpt4.

shows URL tooltip like this:

since the link inside cloze is also hidden before the cloze is revealed, it wont disclose the answer to the user.

I’m interested. Could you post the code?

1 Like

let me dig out… thanks.
been passed several days.

it contains, for basic or cloze, the code and the instructions.

simply say:
for basic, edit the basic note type and add 1 single code block ( i add at end)

for cloze, edit the cloze note type and add 1 single code block ( i add at end) + in every single “reveal” function (depends, i found only 1 in “cloze reveal 1 by 1, by user O”) , add a similar code block.

my discussion /w gpt4 is also posted as instructions.

provided i got 0 experience on javascript, these files will enable everyone to implement it.

enjoy, thanks

btw, it is dual licensed, you could use the GPL3 for the public, thanks.

thanks for sharing. I should probably include this in the addon description. When I have more time …