code: def run(self, lines):
          
  
          text = "\n".join(lines)
          while 1:
              m = BLOCK_RE.search(text)
              if m:
                  command = m.group('command')
                  # Whitelist command, prevent command injection.
                  if command not in SUPPORTED_COMMAMDS:
                      raise Exception('Command not supported: %s' % command)
                  filename = m.group('filename')
                  content = m.group('content')
                  filetype = filename[filename.rfind('.')+1:]
  
                  args = [command, '-T'+filetype]
                  try:
                      proc = subprocess.Popen(
                          args,
                          stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          stdout=subprocess.PIPE)
                      proc.stdin.write(content.encode('utf-8'))
  
                      output, err = proc.communicate()
  
                      if filetype == 'svg':
                          data_url_filetype = 'svg+xml'
                          encoding = 'utf-8'
                          img = output.decode(encoding)
  
                      if filetype == 'png':
                          data_url_filetype = 'png'
                          encoding = 'base64'
                          output = base64.b64encode(output)
                          data_path = "data:image/%s;%s,%s" % (
                              data_url_filetype,
                              encoding,
                              output)
                          img = "![" + filename + "](" + data_path + ")"
  
                      text = '%s\n%s\n%s' % (
                          text[:m.start()], img, text[m.end():])
  
                  except Exception as e:
                          err = str(e) + ' : ' + str(args)
                          return (
                              '<pre>Error : ' + err + '</pre>'
                              '<pre>' + content + '</pre>').split('\n')
  
              else:
                  break
          return text.split("\n")
docs: Match and generate dot code blocks.