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 hashlib import sha1
|
||||||
from mkdocs.config.config_options import ExtraScriptValue
|
from mkdocs.config.config_options import ExtraScriptValue
|
||||||
from mkdocs.config.defaults import MkDocsConfig
|
from mkdocs.config.defaults import MkDocsConfig
|
||||||
|
from mkdocs.exceptions import PluginError
|
||||||
from mkdocs.plugins import BasePlugin, event_priority
|
from mkdocs.plugins import BasePlugin, event_priority
|
||||||
from mkdocs.structure.files import File, Files
|
from mkdocs.structure.files import File, Files
|
||||||
from mkdocs.utils import is_error_template
|
from mkdocs.utils import is_error_template
|
||||||
@ -241,9 +242,18 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
|
|||||||
parser.feed(fragment)
|
parser.feed(fragment)
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
# Return element
|
# Check parse result and return element
|
||||||
assert isinstance(parser.result, Element)
|
if isinstance(parser.result, Element):
|
||||||
return parser.result
|
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
|
# Parse and extract all external assets from a media file using a preset
|
||||||
# regular expression, and return all URLs found.
|
# regular expression, and return all URLs found.
|
||||||
|
@ -33,6 +33,7 @@ from concurrent.futures import Future, ThreadPoolExecutor, wait
|
|||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from mkdocs.config.config_options import ExtraScriptValue
|
from mkdocs.config.config_options import ExtraScriptValue
|
||||||
from mkdocs.config.defaults import MkDocsConfig
|
from mkdocs.config.defaults import MkDocsConfig
|
||||||
|
from mkdocs.exceptions import PluginError
|
||||||
from mkdocs.plugins import BasePlugin, event_priority
|
from mkdocs.plugins import BasePlugin, event_priority
|
||||||
from mkdocs.structure.files import File, Files
|
from mkdocs.structure.files import File, Files
|
||||||
from mkdocs.utils import is_error_template
|
from mkdocs.utils import is_error_template
|
||||||
@ -241,9 +242,18 @@ class PrivacyPlugin(BasePlugin[PrivacyConfig]):
|
|||||||
parser.feed(fragment)
|
parser.feed(fragment)
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
# Return element
|
# Check parse result and return element
|
||||||
assert isinstance(parser.result, Element)
|
if isinstance(parser.result, Element):
|
||||||
return parser.result
|
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
|
# Parse and extract all external assets from a media file using a preset
|
||||||
# regular expression, and return all URLs found.
|
# regular expression, and return all URLs found.
|
||||||
|
Loading…
Reference in New Issue
Block a user