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:
[image: download_list_1.PNG]
Trying to do the same from my "SphinxDirective" class plugin, I get the 
following result

[image: download_list_2.PNG]
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">
<li><p><a class="reference download internal" download="" href="
../_downloads/73e25db1add1c37f55d8f773b290e27c/file1.txt"><code class="xref 
download docutils literal notranslate"><span 
class="pre">File1</span></code></a></p></li> 
...
</ul> 

The output using my custom plugin becomes:

<ul> 
<li><a class="reference download internal" download="" href="
../_downloads/f95e443b8a4da2a3b622a298a3df8ed7/file1.txt">file1.txt</a></li> 

...
</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




-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/fb83fb68-59e3-4856-a644-c0b4141c8ccdn%40googlegroups.com.

Reply via email to