File tree 2 files changed +26
-6
lines changed
2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 33
33
from hashlib import sha1
34
34
from mkdocs .config .config_options import ExtraScriptValue
35
35
from mkdocs .config .defaults import MkDocsConfig
36
+ from mkdocs .exceptions import PluginError
36
37
from mkdocs .plugins import BasePlugin , event_priority
37
38
from mkdocs .structure .files import File , Files
38
39
from mkdocs .utils import is_error_template
@@ -241,9 +242,18 @@ def _parse_fragment(self, fragment: str):
241
242
parser .feed (fragment )
242
243
parser .close ()
243
244
244
- # Return element
245
- assert isinstance (parser .result , Element )
246
- return parser .result
245
+ # Check parse result and return element
246
+ if isinstance (parser .result , Element ):
247
+ return parser .result
248
+
249
+ # Otherwise, raise a plugin error - if the author accidentally used
250
+ # invalid HTML inside of the tag, e.g., forget a opening or closing
251
+ # quote, we need to catch this here, as we're using pretty basic
252
+ # regular expression based extraction
253
+ raise PluginError (
254
+ f"Could not parse due to possible syntax error in HTML: \n \n "
255
+ + fragment
256
+ )
247
257
248
258
# Parse and extract all external assets from a media file using a preset
249
259
# regular expression, and return all URLs found.
Original file line number Diff line number Diff line change 33
33
from hashlib import sha1
34
34
from mkdocs .config .config_options import ExtraScriptValue
35
35
from mkdocs .config .defaults import MkDocsConfig
36
+ from mkdocs .exceptions import PluginError
36
37
from mkdocs .plugins import BasePlugin , event_priority
37
38
from mkdocs .structure .files import File , Files
38
39
from mkdocs .utils import is_error_template
@@ -241,9 +242,18 @@ def _parse_fragment(self, fragment: str):
241
242
parser .feed (fragment )
242
243
parser .close ()
243
244
244
- # Return element
245
- assert isinstance (parser .result , Element )
246
- return parser .result
245
+ # Check parse result and return element
246
+ if isinstance (parser .result , Element ):
247
+ return parser .result
248
+
249
+ # Otherwise, raise a plugin error - if the author accidentally used
250
+ # invalid HTML inside of the tag, e.g., forget a opening or closing
251
+ # quote, we need to catch this here, as we're using pretty basic
252
+ # regular expression based extraction
253
+ raise PluginError (
254
+ f"Could not parse due to possible syntax error in HTML: \n \n "
255
+ + fragment
256
+ )
247
257
248
258
# Parse and extract all external assets from a media file using a preset
249
259
# regular expression, and return all URLs found.
You can’t perform that action at this time.
0 commit comments