Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CoinK0in committed Mar 23, 2022
1 parent 4f0e18d commit 3895760
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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`:
Expand All @@ -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.
Expand Down Expand Up @@ -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**
Expand Down
3 changes: 3 additions & 0 deletions encryptcontent/decrypt-contents.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions encryptcontent/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3895760

Please sign in to comment.