From 3895760674b75026f323fc06f4c4d27e0d073bc3 Mon Sep 17 00:00:00 2001 From: CoinK0in <12155947+CoinK0in@users.noreply.github.com> Date: Wed, 23 Mar 2022 16:46:44 +0100 Subject: [PATCH] Version 2.1.0 --- README.md | 22 +++++++++++++++++++++- encryptcontent/decrypt-contents.tpl.js | 3 +++ encryptcontent/plugin.py | 9 +++++++++ setup.py | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aca850b..8fab3d7 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte * [Features](#features) * [HighlightJS support](#highlightjs-support) *(default)* * [Arithmatex support](#arithmatex-support) *(default)* + * [Mermaid2 support](#mermaid-support) *(default)* * [Tag encrypted page](#tag-encrypted-page) *(default)* * [Rebember password](#rebember-password) * [Encrypt something](#encrypt-something) @@ -50,7 +51,7 @@ Install the package from source with pip: ```bash cd mkdocs-encryptcontent-plugin/ python3 setup.py sdist bdist_wheel -pip3 install dist/mkdocs_encryptcontent_plugin-2.0.2-py3-none-any.whl +pip3 install dist/mkdocs_encryptcontent_plugin-2.1.0-py3-none-any.whl ``` Enable the plugin in your `mkdocs.yml`: @@ -62,6 +63,7 @@ plugins: ``` > **NOTE:** If you have no `plugins` entry in your configuration file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set, but now you have to enable it explicitly. + # Usage Add an meta tag `password: secret_password` in your markdown files to protect them. @@ -143,6 +145,24 @@ MathJax.typesetPromise() > **NOTE** It has been tested in Arithmatex `generic` mode only. +### Mermaid2 support + +> **Enable by default** + +Related to [issue #22](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/22) + +If mermaid2 plugin is detected in your configuration to generate graph from text, reload renderer after decryption process. If the Mermaid2 plugin is not correctly detected, you can force the detection by adding `mermaid2: True` on the plugin configuration or set `mermaid2: False` to disable this feature. + +When enable, the following part of the template is add to force graph rendering on decrypted content. + +```jinja +{% if mermaid2 %} +mermaid.contentLoaded(); +{% endif %} +``` + +> **NOTE** It has been tested with Mermaid2 mkdocs plugin only. + ### Tag encrypted page > **Enable by default** diff --git a/encryptcontent/decrypt-contents.tpl.js b/encryptcontent/decrypt-contents.tpl.js index 5b7887e..a22b827 100644 --- a/encryptcontent/decrypt-contents.tpl.js +++ b/encryptcontent/decrypt-contents.tpl.js @@ -152,6 +152,9 @@ function decrypt_action(password_input, encrypted_content, decrypted_content) { {% if arithmatex -%} if (typeof MathJax === 'object') { MathJax.typesetPromise(); }; {%- endif %} + {% if mermaid2 -%} + if (typeof mermaid === 'object') { mermaid.contentLoaded(); }; + {%- endif %} {% if hljs -%} document.getElementById("mkdocs-decrypted-content").querySelectorAll('pre code').forEach((block) => { hljs.highlightBlock(block); diff --git a/encryptcontent/plugin.py b/encryptcontent/plugin.py index e371b79..4284974 100644 --- a/encryptcontent/plugin.py +++ b/encryptcontent/plugin.py @@ -63,6 +63,7 @@ class encryptContentPlugin(BasePlugin): ('password', config_options.Type(string_types, default=None)), ('arithmatex', config_options.Type(bool, default=True)), ('hljs', config_options.Type(bool, default=True)), + ('mermaid2', config_options.Type(bool, default=True)), ('remember_password', config_options.Type(bool, default=False)), ('default_expire_dalay', config_options.Type(int, default=int(24))), ('tag_encrypted_page', config_options.Type(bool, default=True)), @@ -126,6 +127,7 @@ def __generate_decrypt_js__(self): # enable / disable features 'arithmatex': self.config['arithmatex'], 'hljs': self.config['hljs'], + 'mermaid2': self.config['mermaid2'], 'remember_password': self.config['remember_password'], 'default_expire_dalay': int(self.config['default_expire_dalay']), 'encrypted_something': self.config['encrypted_something'], @@ -161,6 +163,13 @@ def on_config(self, config, **kwargs): else: logger.info('"arithmatex" feature is disabled in your plugin configuration.') self.config['arithmatex'] = False + # Check if mermaid feature need to be enabled, based on plugin configuration + if config['plugins'].get('mermaid2') and self.config['mermaid2'] is not False: + logger.debug('"mermaid2" value detected on extensions config, enable rendering after decryption.') + self.config['mermaid2'] = True + else: + logger.info('"mermaid2" feature is disabled in your plugin configuration.') + self.config['mermaid2'] = False # Warn about deprecated features on Vervion 2.0.0 deprecated_options_detected = False if self.config.get('disable_cookie_protection'): diff --git a/setup.py b/setup.py index 32aab62..3c1a424 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def read(fname): setup( name='mkdocs-encryptcontent-plugin', - version='2.0.2', + version='2.1.0', author='CoinK0in', author_email='12155947+CoinK0in@users.noreply.github.com', description='A MkDocs plugin that encrypt/decrypt markdown content with AES',