From: Paul V. <pc...@gm...> - 2016-06-14 23:57:29
|
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. |