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

feature_request(option): don’t add initialize script #8

Open
Kristinita opened this issue Aug 17, 2022 · 1 comment
Open

feature_request(option): don’t add initialize script #8

Kristinita opened this issue Aug 17, 2022 · 1 comment

Comments

@Kristinita
Copy link

1. Summary

It would be nice, if would be possible to not add automatically a Mermaid initialize script to the HTML.

2. Argumentation

  1. Adding <script> tag at the bottom of <body> is old approach. Modern solution — adding it inside <head> tag.
  2. Users can add scripts with their own methods. For example, I use defer.js.

3. Examples of expected behavior

3.1. Fully disable auto-adding of initialize script

In my fork I remove these lines from md_mermaid.py:

if is_mermaid:
    new_lines.append('')
    # This will initialize mermaid renderer. It's done only when the HTML document is ready,
    # to ensure the loading of mermaid.js file is finished.
    new_lines.append('''<script>
            function initializeMermaid() {
                mermaid.initialize({startOnLoad:true})
            }

            if (document.readyState === "complete" || document.readyState === "interactive") {
                setTimeout(initializeMermaid, 1);
            } else {
                document.addEventListener("DOMContentLoaded", initializeMermaid);
            }
    </script>''')

In my opinion, this is the best option. If you want, I make a pull request.

3.2. Option

If you don’t want to delete the code above completely, it would be nice to have an option to not add a script. For example, if:

md_mermaid:
  add_initialize_script: false

md_mermaid won’t add the script.

Thanks.

@tsbertalan
Copy link

Yeah, it would be nice to able to pass alternate options like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants