reStructuredTextで、
.. code-block:: ruby
::filename:: hello.rb
puts "hello, world!!"
と書いて、
hello.rb:
<pre class="brush: ruby">
puts "hello, world!!"
</pre>
に変換させたい。
class CodeBlockDirective(Directive):
required_arguments = 0
optional_arguments = 1
has_content = True
option_spec = { 'filename': directives.unchanged }
def run(self):
node = []
filename = self.options.pop('filename', None)
if filename is not None:
node.append(nodes.Text("\n%s:" % filename))
else:
node.append(nodes.Text("\n"))
opt = {'classes' : []}
if len(self.arguments) != 0:
opt['classes'].append("brush: %s" % self.arguments[0])
node.append(nodes.literal_block(self.content, "\n".join(self.content), **opt))
return node
めでたしめでたし