mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Improved resilience of privacy plugin
This commit is contained in:
parent
6c9ba875bf
commit
29cf44b71c
@ -33,6 +33,7 @@ from concurrent.futures import Future, ThreadPoolExecutor, wait
|
||||
from hashlib import sha1
|
||||
from mkdocs.config.config_options import ExtraScriptValue
|
||||
from mkdocs.config.defaults import MkDocsConfig
|
||||
from mkdocs.exceptions import PluginError
|
||||
from mkdocs.plugins import BasePlugin, event_priority
|
||||
from mkdocs.structure.files import File, Files
|
||||
from mkdocs.utils import is_error_template
|
||||
@ -241,10 +242,19 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
|
||||
parser.feed(fragment)
|
||||
parser.close()
|
||||
|
||||
# Return element
|
||||
assert isinstance(parser.result, Element)
|
||||
# Check parse result and return element
|
||||
if isinstance(parser.result, Element):
|
||||
return parser.result
|
||||
|
||||
# Otherwise, raise a plugin error - if the author accidentally used
|
||||
# invalid HTML inside of the tag, e.g., forget a opening or closing
|
||||
# quote, we need to catch this here, as we're using pretty basic
|
||||
# regular expression based extraction
|
||||
raise PluginError(
|
||||
f"Could not parse due to possible syntax error in HTML: \n\n"
|
||||
+ fragment
|
||||
)
|
||||
|
||||
# Parse and extract all external assets from a media file using a preset
|
||||
# regular expression, and return all URLs found.
|
||||
def _parse_media(self, initiator: File) -> list[URL]:
|
||||
|
@ -33,6 +33,7 @@ from concurrent.futures import Future, ThreadPoolExecutor, wait
|
||||
from hashlib import sha1
|
||||
from mkdocs.config.config_options import ExtraScriptValue
|
||||
from mkdocs.config.defaults import MkDocsConfig
|
||||
from mkdocs.exceptions import PluginError
|
||||
from mkdocs.plugins import BasePlugin, event_priority
|
||||
from mkdocs.structure.files import File, Files
|
||||
from mkdocs.utils import is_error_template
|
||||
@ -241,10 +242,19 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
|
||||
parser.feed(fragment)
|
||||
parser.close()
|
||||
|
||||
# Return element
|
||||
assert isinstance(parser.result, Element)
|
||||
# Check parse result and return element
|
||||
if isinstance(parser.result, Element):
|
||||
return parser.result
|
||||
|
||||
# Otherwise, raise a plugin error - if the author accidentally used
|
||||
# invalid HTML inside of the tag, e.g., forget a opening or closing
|
||||
# quote, we need to catch this here, as we're using pretty basic
|
||||
# regular expression based extraction
|
||||
raise PluginError(
|
||||
f"Could not parse due to possible syntax error in HTML: \n\n"
|
||||
+ fragment
|
||||
)
|
||||
|
||||
# Parse and extract all external assets from a media file using a preset
|
||||
# regular expression, and return all URLs found.
|
||||
def _parse_media(self, initiator: File) -> list[URL]:
|
||||
|
Loading…
Reference in New Issue
Block a user