def blockdiag_parser(preprocessor, tag, markup):
    """ Blockdiag parser """
    m = DOT_BLOCK_RE.search(markup)
    if m:
        # Get diagram type and code
        diagram = m.group('diagram').strip()
        code = markup

        # Run command
        output = diag(code, diagram)

        if output:
            # Return Base64 encoded image
            return '<span class="blockdiag" style="align: center;"><img src="data:image/png;base64,%s"></span>' % base64.b64encode(output)
    else:
        raise ValueError('Error processing input. '
                         'Expected syntax: {0}'.format(SYNTAX))
Blockdiag parser