utils: Fix topic processing error in rst_to_html with docutils >= 0.17
With docutils >= 0.17
, an exception was raised when trying to render a
topic node in a rst document.
For instance, the following error was reported when trying to render the rst readme of https://github.com/python/cpython
Traceback (most recent call last):
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/anlambert/swh/swh-environment/swh-web/swh/web/browse/views/origin.py", line 37, in origin_directory_browse
return browse_snapshot_directory(
File "/home/anlambert/swh/swh-environment/swh-web/swh/web/browse/snapshot_context.py", line 885, in browse_snapshot_directory
readme_name, readme_url, readme_html = get_readme_to_display(readmes)
File "/home/anlambert/swh/swh-environment/swh-web/swh/web/browse/utils.py", line 772, in get_readme_to_display
readme_html = _rst_readme_to_html(readme_sha1)
File "/home/anlambert/swh/swh-environment/swh-web/swh/web/browse/utils.py", line 770, in _rst_readme_to_html
return rst_to_html(rst_doc["raw_data"])
File "/home/anlambert/swh/swh-environment/swh-web/swh/web/utils/__init__.py", line 391, in rst_to_html
pp = publish_parts(rst, writer=_HTML_WRITER, settings_overrides=settings)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/core.py", line 441, in publish_parts
output, pub = publish_programmatically(
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/core.py", line 665, in publish_programmatically
output = pub.publish(enable_exit_status=enable_exit_status)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/core.py", line 220, in publish
output = self.writer.write(self.document, self.destination)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/writers/__init__.py", line 78, in write
self.translate()
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/writers/_html_base.py", line 80, in translate
self.document.walkabout(visitor)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/nodes.py", line 227, in walkabout
if child.walkabout(visitor):
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/nodes.py", line 219, in walkabout
visitor.dispatch_visit(self)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/nodes.py", line 2021, in dispatch_visit
return method(node)
File "/home/anlambert/.virtualenvs/swh/lib/python3.9/site-packages/docutils/writers/html5_polyglot/__init__.py", line 465, in visit_topic
self.body_prefix[0] = '</head>\n<body class="with-toc">\n'
IndexError: list assignment index out of range