Jwrede / Anki-KaTeX-Markdown

Creates a new Basic and a new Cloze Note Type that support Markdown and KaTeX
74 stars 5 forks source link

Extraneous non-working HTML tags in a code block #27

Closed evgeek closed 2 years ago

evgeek commented 2 years ago

Thanks for the great extension! I have a question about the code block: how to remove html tags? image

evgeek commented 2 years ago

I realized that the problem is the dollar sign. You can escape it with a backslash, but how to remove the backslash from the result? :) image

ficapy commented 2 years ago

https://docs.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats

My guess is that this is the cause of the problem, You might try creating a new card and enter it manually, without copying

evgeek commented 2 years ago

ficapy Alas, it didn't help. I think this is due to a conflict with the KaTeX syntax.

Access KaTeX by $...$ for inline math or $$...$$ for displaystyle math, a list of supported functions can be found here

ficapy commented 2 years ago

@evgeek oh, got it, because there are multiple $ 😂

pilgrimlyieu commented 2 years ago

Maybe you can push Ctrl+Shift+X to open the HTML editor to check if there has some HTML tags.

evgeek commented 2 years ago

@pilgrimlyieu Didn't know about this hotkey! :) But it doesn't work either

image

pilgrimlyieu commented 2 years ago

@pilgrimlyieu Didn't know about this hotkey! :) But it doesn't work either

image

This issue may help you. :smile:

evgeek commented 2 years ago

pilgrimlyieu It works, but in a strange way :) Template settings are reset after restarting Anki. We can create a new note type by copying the existing one and now the template is saved but now the preview is gone. However, given that this plugin will not be further developed, this is an excellent solution. Thanks a lot! :)

image

pilgrimlyieu commented 2 years ago

Actually, the preview zone can be added by modifying something if you need it a lot.

First, open the file __init__.py in folder addons21\1087328706 and find

def markdownPreview(editor):
    if editor.note.model()["name"] in [MODEL_NAME + " Basic", MODEL_NAME + " Cloze"]:
        editor.web.eval(HTMLforEditor)
        editor.web.eval("""
            var style = document.createElement('style');
            style.type = 'text/css';
            style.innerText = `
                table, th, td {
                    border: 1px solid black;
                    border-collapse: collapse;
                }
                pre code {
                    background-color: #eee;
                    border: 1px solid #999;
                    display: block;
                    padding: 20px;
                    overflow: auto;
                }`;
            document.head.appendChild(style);
        """)
    else:
        editor.web.eval("""
                    var area = document.getElementById('markdown-area');
                    if(area) area.remove();
        """)

you can add the name of your template in [MODEL_NAME + " Basic", MODEL_NAME + " Cloze"] like [MODEL_NAME + " Basic", MODEL_NAME + " Cloze", "MyTemplate"]

However, if your template has more than two fields, you may need extra preview zone.

You can open HTMLandCSS.py and find

        keyupFunc = function() {
            var text = '# Field 1\\n' + fields[0].children[1].shadowRoot.children[2].innerHTML;
            text += "\\n# Field 2\\n" + fields[1].children[1].shadowRoot.children[2].innerHTML;
            render(text);
        }

Then follow the law and add like

        keyupFunc = function() {
            var text = '# Field 1\\n' + fields[0].children[1].shadowRoot.children[2].innerHTML;
            text += "\\n# Field 2\\n" + fields[1].children[1].shadowRoot.children[2].innerHTML;
            text += "\\n# Field 3\\n" + fields[2].children[1].shadowRoot.children[2].innerHTML;
            render(text);
        }

But the change will be cover if the addon updates. So you have to backup this two files if you still need the function.

evgeek commented 2 years ago

This works too! Thanks :)

First, open the file init.py in folder addons21\1087328706

Full path for me - C:\Users\%USERS%\AppData\Roaming\Anki2\addons21\1087328706