Skip to content

Commit 14bc93d

Browse files
committed
Add BETA Arithmatex support
1 parent c4c8705 commit 14bc93d

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Install the package from source with pip:
3434
```bash
3535
cd mkdocs-encryptcontent-plugin/
3636
python3 setup.py sdist bdist_wheel
37-
pip3 install dist/mkdocs_encryptcontent_plugin-0.0.12-py3-none-any.whl
37+
pip3 install dist/mkdocs_encryptcontent_plugin-0.0.13-py3-none-any.whl
3838
```
3939

4040
Enable the plugin in your `mkdocs.yml`:
@@ -188,7 +188,10 @@ plugins:
188188
password_button_text: 'custome_text_button'
189189
```
190190
191-
### [:wrench: BETA] Encrypt Something
191+
192+
## [:wrench: BETA] Features
193+
194+
### Encrypt Something
192195
193196
Related to [issue #9](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/9)
194197
@@ -269,6 +272,24 @@ Your configuration like this :
269272
```
270273

271274
:gear: This feature is still in beta, all feedback, improvement, fixes, are welcome.
275+
276+
### Arithmatex support
277+
278+
Related to [issue #12](https://github.com/CoinK0in/mkdocs-encryptcontent-plugin/issues/12)
279+
280+
If Arithmatex markdown extension is set in your markdown extensions to improve math equations rendering, reload rendering after decryption process.
281+
282+
When enable the following part of the template is add to force math equations rendering on decrypted content.
283+
284+
```jinja
285+
{% if arithmatex %}MathJax.typesetPromise(){% endif %}
286+
```
287+
288+
> **NOTE** It has been tested in Arithmatex `generic` mode only.
289+
290+
:gear: This feature is still in beta, all feedback, improvement, fixes, are welcome.
291+
292+
272293
## Contributing
273294

274295
From reporting a bug to submitting a pull request: every contribution is appreciated and welcome.

encryptcontent/decrypt-form.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ <h1>{{ summary }}</h1>
138138
decrypted_content.innerHTML = content;
139139
encrypted_content.parentNode.removeChild(encrypted_content);
140140
// any post processing on the decrypted content should be done here
141+
{% if arithmatex %}MathJax.typesetPromise(){% endif %}
141142
{% if hljs %}
142143
document.getElementById("mkdocs-decrypted-content").querySelectorAll('pre code').forEach((block) => {
143144
hljs.highlightBlock(block);

encryptcontent/plugin.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class encryptContentPlugin(BasePlugin):
5151
('encryption_info_message', mkdocs.config.config_options.Type(string_types, default=str(settings['encryption_info_message']))),
5252
('global_password', mkdocs.config.config_options.Type(string_types, default=None)),
5353
('password', mkdocs.config.config_options.Type(string_types, default=None)),
54+
('arithmatex', mkdocs.config.config_options.Type(bool, default=False)),
5455
('hljs', mkdocs.config.config_options.Type(bool, default=False)),
5556
('remember_password', mkdocs.config.config_options.Type(bool, default=False)),
5657
('disable_cookie_protection', mkdocs.config.config_options.Type(bool, default=False)),
@@ -99,6 +100,7 @@ def __encrypt_content__(self, content):
99100
'ciphertext_bundle': b';'.join(ciphertext_bundle).decode('ascii'),
100101
'js_libraries': JS_LIBRARIES,
101102
# enable / disable features
103+
'arithmatex': self.arithmatex,
102104
'hljs': self.hljs,
103105
'remember_password': self.remember_password,
104106
'disable_cookie_protection': self.disable_cookie_protection,
@@ -134,7 +136,7 @@ def on_pre_build(self, config):
134136
# Check if decryption_failure_message description is set on plugin configuration to overwrite
135137
decryption_failure_message = plugin_config.get('decryption_failure_message')
136138
setattr(self, 'decryption_failure_message', decryption_failure_message)
137-
# Check if encryption_info_message descruption is set on plugin configuration to overwrite
139+
# Check if encryption_info_message description is set on plugin configuration to overwrite
138140
encryption_info_message = plugin_config.get('encryption_info_message')
139141
setattr(self, 'encryption_info_message', encryption_info_message)
140142
# Check if hljs feature need to be enabled, based on theme configuration
@@ -143,6 +145,10 @@ def on_pre_build(self, config):
143145
highlightjs = config['theme']._vars['highlightjs']
144146
if highlightjs:
145147
setattr(self, 'hljs', highlightjs)
148+
# Check if pymdownx.arithmatex feature need to be enabled, based on markdown_extensions configuration
149+
setattr(self, 'arithmatex', None)
150+
if 'pymdownx.arithmatex' in config['markdown_extensions']:
151+
setattr(self, 'arithmatex', True)
146152
# Check if tag_encrypted_page feature is enable: add an extra attribute `encrypted` is add on page object
147153
setattr(self, 'tag_encrypted_page', False)
148154
if 'tag_encrypted_page' in plugin_config.keys():
@@ -173,7 +179,6 @@ def on_pre_build(self, config):
173179
encrypted_something = self.config.get('encrypted_something')
174180
setattr(self, 'encrypted_something', encrypted_something)
175181

176-
177182
def on_page_markdown(self, markdown, page, config, **kwargs):
178183
"""
179184
The page_markdown event is called after the page's markdown is loaded from file and
@@ -189,7 +194,7 @@ def on_page_markdown(self, markdown, page, config, **kwargs):
189194
"""
190195
if 'password' in page.meta.keys():
191196
page_password = page.meta.get('password')
192-
# If global_password is set, but you dont want to encrypt content
197+
# If global_password is set, but you don't want to encrypt content
193198
if page_password == '':
194199
setattr(self, 'password', None)
195200
else:
@@ -244,7 +249,7 @@ def on_post_page(self, output_content, page, config, **kwargs):
244249
#print({'name': name, 'html tag': tag[0], 'type': tag[1]})
245250
something_search = soup.findAll(tag[0], { tag[1]: name })
246251
if something_search is not None and len(something_search) > 0:
247-
# Loop for multi childs tags on target element
252+
# Loop for multi child tags on target element
248253
for item in something_search:
249254
# Remove '\n', ' ' useless content generated by bs4 parsing...
250255
item.contents = [content for content in item.contents if not content in ['\n', ' ']]
@@ -255,7 +260,7 @@ def on_post_page(self, output_content, page, config, **kwargs):
255260
merge_item = item.contents[0]
256261
else:
257262
merge_item = ""
258-
# Encrypt childs items on target tags with page password
263+
# Encrypt child items on target tags with page password
259264
cipher_bundle = self.__encrypt_text_aes__(merge_item, page.password)
260265
encrypted_content = b';'.join(cipher_bundle).decode('ascii')
261266
# Replace initial content with encrypted one
@@ -269,4 +274,4 @@ def on_post_page(self, output_content, page, config, **kwargs):
269274
else:
270275
item['style'] = "display:none"
271276
output_content = str(soup)
272-
return output_content
277+
return output_content

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def read(fname):
1111

1212
setup(
1313
name='mkdocs-encryptcontent-plugin',
14-
version='0.0.12',
14+
version='0.0.13',
1515
author='CoinK0in',
1616
author_email='[email protected]',
1717
description='A MkDocs plugin that encrypt/decrypt markdown content with AES',

0 commit comments

Comments
 (0)