Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting a hyperlink into italic text in effect removes the formatting #7

Open
ijgnd opened this issue Jul 29, 2020 · 3 comments
Open
Labels
help wanted Extra attention is needed

Comments

@ijgnd
Copy link
Owner

ijgnd commented Jul 29, 2020

tldr: Fixing this is on the todo list but it's low priority since it took about two years until I got the first complaint and it's likely not a quick fix (but I probably need to switch to js).

 

In Anki 2.0 if you had

<i>a b c</i>

and then select the b and set "test" as the hyperlink target you get:

<i>a&nbsp;<a href="test">b</a>&nbsp;c</i>

 

In Anki 2.1.0 (or .29) if you had

<i>a b c</i>

and then select the b and set "test" as the hyperlink target you get:

<i>a&nbsp;</i><a href="test">b</a><i>&nbsp;c</i>

 

 

 

Note to self: The code for inserting hyperlinks has been unchanged between the pfp for 2.0 and my version for 2.1:

In 2.0 it's

selected = editor.web.selectedText()
Hyperlink(editor, editor.parentWindow, selected)
....
self.editor_instance.web.eval(
        "document.execCommand('insertHTML', false, %s);"
        % json.dumps(replacement))

In 2.1 I use

selected = editor.web.selectedText()
h = Hyperlink(editor, editor.parentWindow, selected)
if hasattr(h, "replacement"):
    editor.web.eval(
        "document.execCommand('insertHTML', false, %s);"
        % json.dumps(h.replacement))
@tomkahn
Copy link

tomkahn commented Jul 29, 2020

Thanks for the fast response and the detailed writeup! I appreciate it.

I just checked whether this addon had the same problem. It does not. (No surprise, really, since it uses a different editor: TinyMCE). We could check how links are inserted there for inspiration.

ijgnd pushed a commit that referenced this issue Jul 29, 2020
@ijgnd ijgnd added the help wanted Extra attention is needed label Jul 29, 2020
@ijgnd
Copy link
Owner Author

ijgnd commented Jul 29, 2020

I just added a small workaround. A full solution like 1200 lines of code from the unminified "link" plugin from TinyMCE or even a proper solution is too time-consuming for me.

If this doesn't work let me know so that I can revert it. If you want more: pull requests are welcome.

@tomkahn
Copy link

tomkahn commented Jul 29, 2020

Just tried it; works perfectly. And who changes the link text in that dialogue anyway?

Thanks!

You don't happen to have a similarly short solution to this issue, do you? 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants