vsch / idea-multimarkdown

Markdown language support for IntelliJ IDEA.
https://plugins.jetbrains.com/plugin/7896-markdown-navigator
Apache License 2.0
812 stars 129 forks source link

HTML generation error for collapsible admonition (TypeError: markdownNavigator is undefined) #849

Open smnkdrnk opened 4 years ago

smnkdrnk commented 4 years ago

Pycharm version: 2020.1.1 Professional Plugin version: EAP 3.0.201.95

I am getting an error related to using the collapsible admonition block syntax (??? keyword)

The admonition blocks appear closed and styled correctly on page load, but clicking to expand a block causes a TypeError in the console. Inspecting multimarkdown_admonition.js:

var markdownNavigator;

(() => {
    let divs = document.getElementsByClassName("adm-block");
    for (let i = 0; i < divs.length; i++) {
        let div = divs[i];
        if (div.classList.contains("adm-collapsed") || div.classList.contains("adm-open")) {
            let headings = div.getElementsByClassName("adm-heading");
            if (headings.length > 0) {
                headings[0].addEventListener("click", event => {
                    let el = div;
                    event.preventDefault();
                    event.stopImmediatePropagation();
                    markdownNavigator.setEventHandledBy("Admonition-Extension");
                    if (el.classList.contains("adm-collapsed")) {
                        console.debug("Admonition Open", event.srcElement);
                        el.classList.remove("adm-collapsed");
                        el.classList.add("adm-open");
                    } else {
                        console.debug("Admonition Collapse", event.srcElement);
                        el.classList.add("adm-collapsed");
                        el.classList.remove("adm-open");
                    }
                });
            }
        }
    }
})();

I get this error with the regardless of any other js parser extensions, however I will note that I also see the same error for the Github Collapsible Markdown extension as well when it is enabled. The blocks behave as expected within the editor's preview pane.

I believe markdownNavigator is out of the anonymous function's closure's scope; I may be incorrect, and I'm unsure how the js file is generated regardless.

I updated to the most recent development version of the plugin tonight. I can't say if this is a pre-existing issue, as I've only begun exporting within the last few days, and only today realized I must target a project dir in order to export directly to html.

As a side note, the pdf export typically varies quite drastically from the html preview. I'm still working my way through your wiki, perhaps that topic is covered in more detail there.

vsch commented 4 years ago

@smnkdrnk, what OS and JRE are you using for the IDE.

I am not able to reproduce this on OS X with bundled JRE.

The markdownNavigator global variable is set by a page load script and JS bridge code between Java and JavaFX WebView. Under some conditions it is possible that the JS Bridge code does not run. This can occur during initial IDE startup but under normal operation is corrected once the IDE is initialized.

smnkdrnk commented 4 years ago

Build version: PyCharm 2020.1.1 Build #PY-201.7223.92 April 30, 2020 Java version: 11.0.6+8-b765.40amd64 Operating System: Linux (3.10.0-1062.12.1.el7.x86_64, amd64) JVM version: OpenJDK 64-Bit Server VM JetBrains s.r.o

I updated to 3.0.201.97 this evening and still experiencing the issue.

Let me know if you would like to see any logs or other details.