1

I'm making a extension for sphinx, which takes c code block, compiles it with arguments and stores the assembly/listing output to separate file. I take the c code block, the asm code block and the arguments given to gcc to do the compilation. Now the extension nicely produces handful of code blocks with syntax highlighting and everything.

As a next step I want to add each of these blocks to their own tab and then add all the tabs together into one combined directive tabs.

I would like to invoke directives from the sphinx_tabs.tabs extension programatically. Till now I was using nodes like these:

asm_raw_node = nodes.literal_block(asm_raw, asm_raw)
asm_raw_node["language"] = "asm"
asm_raw_node["linenos"] = -1
asm_raw_args = asm_raw_node['highlight_args'] = {}
asm_raw_args['linenostart'] = 1

And that works well, however I'm not sure how to aproach the problem with 3rd party directives/extensions.

I seen in some other projects just importing and calling its run method, like here:

https://github.com/executablebooks/sphinx-tabs/blob/master/sphinx_tabs/tabs.py#L263

However I'm not sure if that is correct way doing it and without knowing much knowledge looks to me bit hacky. The nodes feels to me much more structured/organized. However I did attempted something:

tab = TabDirective.run(self)
tab.append(asm_raw_node)

Then I was thinking to do something like this:

tabs = TabsDirective.run(self)
tabs.append(tab)

However, even the first step produces error: /vagrant/sphinx/source/test.md:6: ERROR: Content block expected for the "testdirective" directive; none found.

It might indicate that my directive has has_content = False which is correct as it's fully driven by arguments which then read the content from the files and the directivey has no contect except the arguemnts. Does the fact I'm providing a different directive my own self break things? So not sure if I should continue this way, or try something else.

Could somebody point me to the right direction? Thank you in advance.

mzjn
  • 48,958
  • 13
  • 128
  • 248
Anton Krug
  • 1,555
  • 2
  • 19
  • 32

0 Answers0