Custom Directives

Paul VonZimmerman <[email protected]>
Newsgroups gmane.text.docutils.user
Message-ID <CA+TAX3h91=igxbOkq8geC_GK8sDC7YSPsaAw5NU=JN9yOq1K6Q@mail.gmail.com>
Hello everyone,

I have a question about creating custom directives. My approach thus far
has been to iterate through self.content and wrap HTML around it. I then
convert the HTMLto rST using nodes.raw(). Is this a valid approach or
frowned upon when creating custom directives?

Here is a bit of sample code:

class eCard(Directive):
    """
    usage:
    .. ecard::

        [name]
        [image]
        [name]
        [image]
    """
    has_content = True
    optional_arguments = 0
    def run(self):
        this =  "<h2 id=\"da_header\">Desk Attendants</h2>\n <div
id=\"da_ecard_container\">\n"
        count = 0
        for item in range(0, len(self.content)/2):
            name = self.content[count]
            image = self.content[count+1]
            count += 2
            this += "<div class=\"ecard\">\n"
            this += '<img class="da_image" src=' + image + ' alt="' + name
+ '"/>\n'
            this += "<span>" + name + "</span\n>"
            this += "</div>\n"
        this += "</div>\n"
        this = nodes.raw('', this, format='html')
        return [this]
directives.register_directive('ecard', eCard)

I haven't run into anything wrong with this approach, I'm mostly just
curious if this way will cause problems in the future.

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.