lynchjames / obsidian-mind-map

An Obsidian plugin for displaying markdown notes as mind maps using Markmap.
MIT License
1.05k stars 73 forks source link

If the document include a code block,the mindmap doesn't work #25

Open CharisLee opened 3 years ago

CharisLee commented 3 years ago

```shell 123456 ``` the mindmap will not work ``html 123456 \`` the mindmap will be normal

In order to highlight the code, I must use shell to announce the code block

Had anybody encountered the same problem?

CharisLee commented 3 years ago

How to display the code block in mindmap?

Johnson1602 commented 3 years ago

Same here. Mind map wouldn't work if I specify coding language.

jw0z commented 3 years ago

Same here, but I have found some workarounds (works with Mind Map 1.1.0) ;

Fix n°1 :

Write :

instead of

Fix n°2 :

If you don't want to modify all your code block headers ;

  1. Open .obsidian/plugins/obsidian-mind-map/main.js
  2. Go to the loadLanguages function (line 27077)
  3. Write return; before const pathToLanguage = './prism-' + lang;

Original main.js at line 27077 :

function loadLanguages(languages) {
    if (languages === undefined) {
        languages = Object.keys(components_1.languages).filter(l => l != 'meta');
    } else if (!Array.isArray(languages)) {
        languages = [languages];
    }

    // the user might have loaded languages via some other way or used `prism.js` which already includes some
    // we don't need to validate the ids because `getLoader` will ignore invalid ones
    const loaded = [...loadedLanguages, ...Object.keys(Prism.languages)];

    dependencies(components_1, languages, loaded).load(lang => {
        if (!(lang in components_1.languages)) {
            if (!loadLanguages.silent) {
                console.warn('Language does not exist: ' + lang);
            }
            return;
        }

        const pathToLanguage = './prism-' + lang;

        // remove from require cache and from Prism
        delete require.cache[require.resolve(pathToLanguage)];
        delete Prism.languages[lang];

        commonjsRequire();

        loadedLanguages.add(lang);
    });
}

Modified main.js at line 27077 :

function loadLanguages(languages) {
    if (languages === undefined) {
        languages = Object.keys(components_1.languages).filter(l => l != 'meta');
    } else if (!Array.isArray(languages)) {
        languages = [languages];
    }

    // the user might have loaded languages via some other way or used `prism.js` which already includes some
    // we don't need to validate the ids because `getLoader` will ignore invalid ones
    const loaded = [...loadedLanguages, ...Object.keys(Prism.languages)];

    dependencies(components_1, languages, loaded).load(lang => {
        if (!(lang in components_1.languages)) {
            if (!loadLanguages.silent) {
                console.warn('Language does not exist: ' + lang);
            }
            return;
        }

        return; // <-- ADD THIS

        const pathToLanguage = './prism-' + lang;

        // remove from require cache and from Prism
        delete require.cache[global.require.resolve(pathToLanguage)];
        delete Prism.languages[lang];

        commonjsRequire();

        loadedLanguages.add(lang);
    });
}

The issue

I think this issue as something to do with the Prismjs module

Jai-wei commented 1 year ago

Great