We are trying to create a directive which wraps other directives inside. The following example will show an example:
Directives
==========
.. service_card_wrapper::
.. service_card::
.. service_card::
We did not find a proper way to render the content of the "service_card" to the "service_card_wrapper". We need at least HTML content as result something like:
<div class="service-card-wrapper">
<div class="service-card">
Content 1
</div>
<div class="service-card">
Content 2
</div>
</div>
This is our first code-example with some Bootstrap Content:
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives
from sphinx.util import logging
LOG = logging.getLogger(__name__)
class service_card(nodes.General, nodes.Element):
pass
class ServiceCard(Directive):
node_class = service_card
option_spec = {
# 'service_type': directives.unchanged_required,
}
has_content = False
def run(self):
node = self.node_class()
# node['service_type'] = self.options.get('service_type')
return [node]
def service_card_html(self, node):
# This method renders containers per each service of the category with all
# links as individual list items
data = '''
<div class="card">
<h5 class="card-header">Featured</h5>
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>'''
self.body.append(data)
raise nodes.SkipNode
def setup(app):
app.add_node(service_card,
html=(service_card_html, None))
app.add_directive("service_card", ServiceCard)
return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
}
But we do not find a proper solution for the service card wrapper to get this content inside. Can anyone help?
We tried to create a service_card_wrapper but we never came to a result.