@@ -0,0 +1,2064 @@
+from __future__ import print_function%0A%0A%22%22%22Seqdiag processor.%22%22%22%0A%0Aimport os%0Afrom os.path import join%0Aimport subprocess%0A%0Adef process_seqdiag_block(sd_block, sd_number, src_dir, sd_dir):%0A    %22%22%22Extract diagram definition, convert it to image,%0A    and return the image ref.%0A    %22%22%22%0A%0A    sd_src_filename = %22%25d.diag%22 %25 sd_number%0A    sd_content = '%5Cn'.join(sd_block%5B1: -1%5D)%0A    sd_caption = sd_block%5B0%5D.replace(%22%60%60%60seqdiag%22, '').strip()%0A    sd_img_ref = %22!%5B%25s%5D(%25s/%25d.png)%22 %25 (sd_caption, sd_dir, sd_number)%0A    sd_src_path = join(src_dir, sd_dir, sd_src_filename)%0A    sd_command = %22seqdiag -a %25s%22 %25 sd_src_path%0A%0A    with open(sd_src_path, 'w') as sd_src_file:%0A        sd_src_file.writelines(sd_content)%0A%0A    try:%0A        proc = subprocess.check_output(%0A            sd_command,%0A            stderr=subprocess.PIPE%0A        )%0A%0A    except subprocess.CalledProcessError as e:%0A        pass%0A%0A    return sd_img_ref%0A%0Adef process_diagrams(src_dir, src_file):%0A    %22%22%22Find seqdiag code blocks, feed their content to seqdiag tool,%0A    and replace them with image references.%0A    %22%22%22%0A%0A    print(%22Drawing diagrams... %22, end='')%0A%0A    sd_dir = %22diagrams%22%0A    src_path = join(src_dir, src_file)%0A    buffer, new_source = %5B%5D, %5B%5D%0A    sd_number = 0%0A%0A    os.makedirs(join(src_dir, sd_dir))%0A%0A    with open(src_path) as src:%0A        for line in (l.rstrip() for l in src):%0A            if not buffer:%0A                if line.startswith(%22%60%60%60seqdiag%22):%0A                    buffer.append(line)%0A                else:%0A                    new_source.append(line)%0A%0A            else:%0A                buffer.append(line)%0A%0A                if line == %22%60%60%60%22:%0A                    new_source.append(%0A                        process_seqdiag_block(%0A                            buffer,%0A                            sd_number,%0A                            src_dir,%0A                            sd_dir%0A                        )%0A                    )%0A                    sd_number += 1%0A                    buffer = %5B%5D%0A%0A    with open(src_path, 'w') as src:%0A        src.writelines('%5Cn'.join(new_source))%0A%0A    print(%22Done!%22)%0A

Add seqdiag processor.