-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Context
Our CI recently pulled in the newly released 9.0.1 this week; the build for one of our sites started failing afterwards.
Bug description
We have some old (non-ideal) markdown that crashes the search plugin during indexing:
$ ../bin/mkdocs build
INFO - Cleaning site directory
INFO - Building documentation to directory: /private/tmp/mkdocs/test/site
ERROR - Error building page 'index.md': list index out of range
Traceback (most recent call last):
File "/tmp/mkdocs/test/../bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/private/tmp/mkdocs/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/private/tmp/mkdocs/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/mkdocs/__main__.py", line 250, in build_command
build.build(cfg, dirty=not clean)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/mkdocs/commands/build.py", line 329, in build
_build_page(file.page, config, doc_files, nav, env, dirty)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/mkdocs/commands/build.py", line 226, in _build_page
context = config.plugins.run_event(
File "/private/tmp/mkdocs/lib/python3.9/site-packages/mkdocs/plugins.py", line 520, in run_event
result = method(item, **kwargs)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/material/plugins/search/plugin.py", line 90, in on_page_context
self.search_index.add_entry_from_context(page)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/material/plugins/search/plugin.py", line 143, in add_entry_from_context
parser.feed(page.content)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/html/parser.py", line 110, in feed
self.goahead(0)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/html/parser.py", line 172, in goahead
k = self.parse_endtag(i)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/html/parser.py", line 420, in parse_endtag
self.handle_endtag(elem)
File "/private/tmp/mkdocs/lib/python3.9/site-packages/material/plugins/search/plugin.py", line 417, in handle_endtag
elif data[-1].isspace() and data[-2] == f"<{tag}>":
IndexError: list index out of range
The markdown that results in this is a section header in a list:
- # Section header in a list... disabling the search plugin, that snippet results in this HTML:
<ul>
<li>
<h1 id="section-header-in-a-list">Section header in a list</h1>
</li>
</ul>
It's entirely possible that this is "invalid" markdown - however, this did "work" (not crash) with previous releases (including 8.5.11).
We have no real need for that that hierarchy (I suspect it was originally a typo), so I've updated our site to remove the bullet points. It took some digging (aided by breakpoint() :)) to narrow down which part of the file was triggering the crash.
Changing
| elif data[-1].isspace() and data[-2] == f"<{tag}>": |
len(data) >= 2 results in a successful build, although I'm not sure the generated search index makes sense:
$ jq . site/search/search_index.json
{
"config": {
"lang": [
"en"
],
"separator": "[\\s\\-]+",
"pipeline": [
"stopWordFilter"
]
},
"docs": [
{
"location": "",
"title": "Welcome to MkDocs",
"text": "<ul> <li>"
},
{
"location": "#section-header-in-a-list",
"title": "Section header in a list",
"text": "</li> </ul>"
}
]
}Related links
- Bug reporting
- 🚀 Material for MkDocs 9 – Beta #4714
- https://squidfunk.github.io/mkdocs-material/blog/2021/09/13/search-better-faster-smaller/
Reproduction
Steps to reproduce
Run mkdocs build with the attached zip (probably need to remove info from the mkdocs.yml)
Browser
No response
Before submitting
- I have read and followed the bug reporting guidelines.
- I have attached links to the documentation, and possibly related issues or discussions.
- I assure that I have removed all customizations before submitting this bug report.
- I have attached a minimal reproduction.