Q: How to create simple html tags with Python docutils I'm working on a library for Pelican, for which I'm currently using reStructuredText and docutils.
What I'm trying to do is create a custom directive that should output html.
The html I want to output is:
<div class="row">
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">Regular header</h4>
        <p class="category">Category subtitle</p>
      </div>
      <div class="card-body">
        The place is close to Barceloneta Beach and bus stop just 2 min by walk and near to "Naviglio" where you can enjoy the main night life in Barcelona...
      </div>
    </div>
  </div>
</div>

So far I created this Python code
from docutils import nodes
from docutils.parsers.rst import Directive
from pelican.rstdirectives import directives

class Row(Directive):
    required_arguments = 0
    optional_arguments = 0
    final_argument_whitespace = True
    option_spec = {}
    has_content = True

    def run(self):
        # Raise an error if the directive does not have contents.
        self.assert_has_content()

        node = nodes.Element()
        node.document = self.state.document
        self.state.nested_parse(self.content, self.content_offset, node)

        # entries = []
        resultnode = nodes.container()
        for i, child in enumerate(node):
            para = nodes.paragraph()
            para += [child]
            resultnode.append(para)
            # entry = nodes.container()
            # entry.append(para)
            # entries.append(entry)

        resultnode.update_basic_atts({
            "classes": ["row"]
        })
        # resultnode.append(nodes.container('', *entries))

        return [resultnode]

class Card(Directive):
    required_arguments = 0
    optional_arguments = 0
    final_argument_whitespace = True
    option_spec = {
        "header-title": str,
        "header-category": str
    }
    has_content = True

    def run(self):
        # Raise an error if the directive does not have contents.
        self.assert_has_content()
        text = '\n'.join(self.content)

        col = nodes.container()
        col["classes"] = ["col-md-6"]

        card = nodes.container()
        card["classes"] = ["card"]
        col.append(card)

        card_header = nodes.container()
        card_header["classes"] = ["card-header"]
        card.append(card_header)

        header_title = nodes.paragraph(text=self.options.get("header-title"))
        header_title["classes"] = ["card-title"]
        card_header.append(header_title)

        header_category = nodes.paragraph(text="Category subtitle")
        header_category["classes"] = ["category"]
        card_header.append(header_category)

        card_body = nodes.paragraph(text=text)
        card_body["classes"] = ["card-body"]
        card.append(card_body)

        return [col]

def register():
    directives.register_directive("card", Card)
    directives.register_directive("row", Row)

Which creates this html:
<div class="row docutils container">
  <div class="col-md-6 docutils container">
    <div class="card docutils container">
      <div class="card-header docutils container">
        <p class="card-title">Regular header</p>
        <p class="category">Category subtitle</p>
      </div>
      <p class="card-body">
        Hello, world
      </p>
    </div>
  </div>
</div>

So there are a couple of things I would like to know:


*

*how can I remove docutils container from the class attribute? container is conflicting with the themes container css class.

*How can I create simple html elements like h1

A: Instead of reusing container, you should create a custom node type.  Then, create a subclass of the HTML writer to output the tags you need.
