@@ -57,12 +57,9 @@ class encryptContentPlugin(BasePlugin):
5757 ('title_prefix' , config_options .Type (string_types , default = str (SETTINGS ['title_prefix' ]))),
5858 ('summary' , config_options .Type (string_types , default = str (SETTINGS ['summary' ]))),
5959 ('placeholder' , config_options .Type (string_types , default = str (SETTINGS ['placeholder' ]))),
60- ('decryption_failure_message' ,
61- config_options .Type (string_types , default = str (SETTINGS ['decryption_failure_message' ]))),
62- ('encryption_info_message' ,
63- config_options .Type (string_types , default = str (SETTINGS ['encryption_info_message' ]))),
64- ('password_button_text' ,
65- config_options .Type (string_types , default = str (SETTINGS ['password_button_text' ]))),
60+ ('decryption_failure_message' , config_options .Type (string_types , default = str (SETTINGS ['decryption_failure_message' ]))),
61+ ('encryption_info_message' , config_options .Type (string_types , default = str (SETTINGS ['encryption_info_message' ]))),
62+ ('password_button_text' , config_options .Type (string_types , default = str (SETTINGS ['password_button_text' ]))),
6663 ('global_password' , config_options .Type (string_types , default = None )),
6764 ('password' , config_options .Type (string_types , default = None )),
6865 ('arithmatex' , config_options .Type (bool , default = True )),
@@ -73,8 +70,7 @@ class encryptContentPlugin(BasePlugin):
7370 ('tag_encrypted_page' , config_options .Type (bool , default = True )),
7471 ('password_button' , config_options .Type (bool , default = False )),
7572 ('encrypted_something' , config_options .Type (dict , default = {})),
76- ('search_index' ,
77- config_options .Choice (('clear' , 'dynamically' , 'encrypted' ), default = 'encrypted' )),
73+ ('search_index' , config_options .Choice (('clear' , 'dynamically' , 'encrypted' ), default = 'encrypted' )),
7874 ('reload_scripts' , config_options .Type (list , default = [])),
7975 ('experimental' , config_options .Type (bool , default = False )),
8076 # legacy features, doesn't exist anymore
@@ -157,64 +153,56 @@ def on_config(self, config, **kwargs):
157153 if os .environ .get (str (self .config ['use_secret' ])):
158154 self .config ['global_password' ] = os .environ .get (str (self .config ['use_secret' ]))
159155 else :
160- logger .error (('Cannot get global password from environment variable: ' ),
161- (f"{ str (self .config ['use_secret' ])} . Abort !" ))
156+ logger .error ('Cannot get global password from environment variable: {var}. Abort !' .format (
157+ var = str (self .config ['use_secret' ]))
158+ )
162159 os ._exit (1 )
163160 # Set global password as default password for each page
164161 self .config ['password' ] = self .config ['global_password' ]
165162 # Check if hljs feature need to be enabled, based on theme configuration
166163 if ('highlightjs' in config ['theme' ]._vars
167164 and config ['theme' ]._vars ['highlightjs' ] # noqa: W503
168165 and self .config ['hljs' ] is not False ): # noqa: W503, E127
169- logger .debug (('"highlightjs" value detected on theme config,' ),
170- ('enable rendering after decryption.' ))
166+ logger .debug ('"highlightjs" value detected on theme config, enable rendering after decryption.' )
171167 self .config ['hljs' ] = config ['theme' ]._vars ['highlightjs' ]
172168 else :
173169 logger .info ('"highlightjs" feature is disabled in your plugin configuration.' )
174170 self .config ['hljs' ] = False
175- # Check if pymdownx.arithmatex feature need to be enabled, based on markdown_extensions
176- # configuration
171+ # Check if pymdownx.arithmatex feature need to be enabled, based on markdown_extensions configuration
177172 if ('pymdownx.arithmatex' in config ['markdown_extensions' ]
178173 and self .config ['arithmatex' ] is not False ): # noqa: W503
179- logger .debug (('"arithmatex" value detected on extensions config,' ),
180- ('enable rendering after decryption.' ))
174+ logger .debug ('"arithmatex" value detected on extensions config, enable rendering after decryption.' )
181175 self .config ['arithmatex' ] = True
182176 else :
183177 logger .info ('"arithmatex" feature is disabled in your plugin configuration.' )
184178 self .config ['arithmatex' ] = False
185179 # Check if mermaid feature need to be enabled, based on plugin configuration
186180 if config ['plugins' ].get ('mermaid2' ) and self .config ['mermaid2' ] is not False :
187- logger .debug (('"mermaid2" value detected on extensions config,' ),
188- ('enable rendering after decryption.' ))
181+ logger .debug ('"mermaid2" value detected on extensions config, enable rendering after decryption.' )
189182 self .config ['mermaid2' ] = True
190183 else :
191184 logger .info ('"mermaid2" feature is disabled in your plugin configuration.' )
192185 self .config ['mermaid2' ] = False
193186 # Warn about deprecated features on Vervion 2.0.0
194187 deprecated_options_detected = False
195188 if self .config .get ('disable_cookie_protection' ):
196- logger .warning (('DEPRECATED: Feature "disable_cookie_protection" is no longer ' ),
197- ('supported. Can by remove.' ))
189+ logger .warning ('DEPRECATED: Feature "disable_cookie_protection" is no longer supported. Can by remove.' )
198190 deprecated_options_detected = True
199191 if self .config .get ('decrypt_search' ):
200- logger .warning (('DEPRECATED: Feature "decrypt_search" is no longer supported.' ),
201- ('Use search_index on "clear" mode instead.' ))
192+ logger .warning ('DEPRECATED: Feature "decrypt_search" is no longer supported. Use search_index on "clear" mode instead.' )
202193 deprecated_options_detected = True
203194 logger .info ('Fallback "decrypt_search" configuraiton to "search_index" mode clear.' )
204195 self .config ['search_index' ] = 'clear'
205196 if deprecated_options_detected :
206- logger .warning (('DEPRECATED: ' ),
207- ('Features marked as deprecated will be remove in next minor version !' ))
197+ logger .warning ('DEPRECATED: Features marked as deprecated will be remove in next minor version !' )
208198 # Re order plugins to be sure search-index are not encrypted
209199 if self .config ['search_index' ] == 'clear' :
210- logger .debug (('Reordering plugins loading and put search and encryptcontent' ),
211- ('at the end of the event pipe.' ))
200+ logger .debug ('Reordering plugins loading and put search and encryptcontent at the end of the event pipe.' )
212201 config ['plugins' ].move_to_end ('search' )
213202 config ['plugins' ].move_to_end ('encryptcontent' )
214203 # Enable experimental code .. :popcorn:
215204 if self .config ['search_index' ] == 'dynamically' :
216- logger .info (('EXPERIMENTAL MODE ENABLE. ' ),
217- ('Only work with default SearchPlugin, not Material.' ))
205+ logger .info ('EXPERIMENTAL MODE ENABLE. Only work with default SearchPlugin, not Material.' )
218206 self .config ['experimental' ] = True
219207
220208 def on_pre_build (self , config , ** kwargs ):
@@ -252,28 +240,26 @@ def _add_entry_from_context(self, page):
252240 if not self .config .get ('indexing' ) or self .config ['indexing' ] == 'full' :
253241 text = parser .stripped_html .rstrip ('\n ' )
254242 if (hasattr (page , 'encrypted' ) and hasattr (page , 'password' )
255- and page .password is not None ): # noqa: W503
243+ and page .password is not None ): # noqa: W503
256244 plugin = config ['plugins' ]['encryptcontent' ]
257245 code = plugin .__encrypt_text_aes__ (text , str (page .password ))
258246 text = b';' .join (code ).decode ('ascii' )
259247 self ._add_entry (title = page .title , text = text , loc = url )
260248 if (self .config .get ('indexing' )
261- and self .config ['indexing' ] in ['full' , 'sections' ]): # noqa: W503
249+ and self .config ['indexing' ] in ['full' , 'sections' ]): # noqa: W503
262250 for section in parser .data :
263251 if (hasattr (page , 'encrypted' )
264- and hasattr (page , 'password' ) # noqa: W503
265- and page .password is not None ): # noqa: W503, E127
252+ and hasattr (page , 'password' ) # noqa: W503
253+ and page .password is not None ): # noqa: W503, E127
266254 self .create_entry_for_section (section , page .toc , url , page .password )
267255 else :
268256 self .create_entry_for_section (section , page .toc , url )
269257 SearchIndex .add_entry_from_context = _add_entry_from_context
270258 if self .config ['experimental' ] is True :
271259 if config ['theme' ].name == 'material' :
272- logger .error (("UNSUPPORTED Material theme " ),
273- ("with experimantal feature search_index=dynamically !" ))
260+ logger .error ("UNSUPPORTED Material theme with experimantal feature search_index=dynamically !" )
274261 exit ("UNSUPPORTED Material theme: use search_index: [clear|encrypted] instead." )
275- # Overwrite search/*.js files from templates/search with encryptcontent contrib
276- # search assets
262+ # Overwrite search/*.js files from templates/search with encryptcontent contrib search assets
277263 config ['theme' ].dirs = [
278264 e for e in config ['theme' ].dirs
279265 if not re .compile (r".*/contrib/search/templates$" ).match (e )
@@ -330,8 +316,7 @@ def on_page_content(self, html, page, config, **kwargs):
330316 base_path = page .abs_url .replace (page .url , '' ) if page .abs_url is not None else '/'
331317 # Set password attributes on page for other mkdocs events
332318 setattr (page , 'password' , str (self .config ['password' ]))
333- # Keep encrypted html as temporary variable on page cause we need clear html for search
334- # plugin
319+ # Keep encrypted html as temporary variable on page cause we need clear html for search plugin
335320 setattr (page , 'html_encrypted' , self .__encrypt_content__ (html , base_path ))
336321 return html
337322
0 commit comments