Hi all
I am trying to write a custom plugin for sphinx to list files to download from a directory (with filters etc.).
The output should be formatted as a list of ":downloads:" would be:
* :download:`File1</assets/_tmp/file1.txt>`
* :download:`File2</assets/_tmp/file2.txt>`
* :download:`File3</assets/_tmp/file3.txt>`
The html output of a list of download becomes:
Trying to do the same from my "SphinxDirective" class plugin, I get the following result
The files are automatically copied and referenced correctly, but I do not get the downloads icon and the text formatting as in the top example.
The html output using ":download:" becomes:
<ul class="simple">
</ul>
Note that the first includes an additional element: code class="xref download docutils literal notranslate". I assume this is the one adding the icon and the download formatting.
My (slightly simplified) implementation:
class DownloadLister(SphinxDirective):
has_content = False
def run(self):
lst = nodes.bullet_list()
for file_path in glob.glob('source/assets/_tmp/*.txt'):
file_path_abs = os.path.abspath(file_path)
item = nodes.list_item()
item += download_reference(text=os.path.basename(file_path_abs), reftarget=file_path_abs)
lst += item
return [lst]
In rst:
.. downloadlister::
I assume that I am missing a node type, but I am not able to find it in the source code, sphinx documentation or docutils documentation.
In general, I find it very confusing to create sphinx extensions as the documentation is sparse at best.
Any help with the above is highly appreciated.
Br
Christian