Ticket #171 (new todo)

Opened 3 years ago

Last modified 2 months ago

asciidoc, graphviz plugin generating target dependant output

Reported by: ct Owned by:
Priority: normal Milestone:
Component: smallTasks Keywords: python asciidoc
Cc: Blocked By:
Blocking: #626

Description

The graphviz plugin for ascidoc is quite cool, I already use it for some illustrations.

 http://www.methods.co.nz/asciidoc/asciidoc-graphviz-sample.html

now the problem is that the output format seems to be hardcoded, for example:

["graphviz", "sample1.png"]
---------------------------------------------------------------------
 digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML}
---------------------------------------------------------------------

will create a png. When I now use the asciidoc toolchain to create pdf or postscript, embedding .png looks very ugly.

The task is not to find some way to make this nice somehow, for example generating .svg

["graphviz", "sample1.svg"]
---------------------------------------------------------------------

works already, since docbook is XML based too, this might be a start.

Or alternatively figure out how to generate different formats depending on the desired output format (.png or .svg for html outout, .eps for pdf and postscript)

So far I see this not build in yet, might require little python hacking. I guess the upstream author (asciidoc/graphviz-plugin) will like it too.

Change History

comment:1 Changed 2 years ago by ct

  • Keywords python asciidoc added

comment:2 Changed 2 years ago by cizra

Here's my solution. You probably need to rip some changed files out. Or not, I dunno.

Devs, I would be very glad to see the feature added to the official version!

diff -r e401959b7729 a2x.py
--- a/a2x.py  Wed Feb 17 18:39:45 2010 +1300
+++ b/a2x.py  Sat Feb 20 00:13:56 2010 +0200
@@ -25,7 +25,7 @@

 # AsciiDoc global configuration file directory.
 # NOTE: CONF_DIR is "fixed up" by Makefile -- don't rename or change syntax.
-CONF_DIR = '/etc/asciidoc'
+CONF_DIR = '/usr/local/etc/asciidoc'


 ######################################################################
diff -r e401959b7729 asciidoc.py
--- a/asciidoc.py  Wed Feb 17 18:39:45 2010 +1300
+++ b/asciidoc.py  Sat Feb 20 00:13:56 2010 +0200
@@ -5153,7 +5153,7 @@
 APP_DIR = None              # This file's directory.
 USER_DIR = None             # ~/.asciidoc
 # Global configuration files directory (set by Makefile build target).
-CONF_DIR = '/etc/asciidoc'
+CONF_DIR = '/usr/local/etc/asciidoc'
 HELP_FILE = 'help.conf'     # Default (English) help file.

 # Globals
diff -r e401959b7729 filters/graphviz/graphviz-filter.conf
--- a/filters/graphviz/graphviz-filter.conf  Wed Feb 17 18:39:45 2010 +1300
+++ b/filters/graphviz/graphviz-filter.conf  Sat Feb 20 00:13:56 2010 +0200
@@ -5,7 +5,7 @@
 # Gouici Iisaka <iisaka51 at gmail dot com>

 [blockdef-listing]
-graphviz-style=template="graphviz-block",subs=(),posattrs=("style","target","layout"),filter='graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -L {layout=dot} -'
+graphviz-style=template="graphviz-block",subs=(),posattrs=("style","target","layout","format"),filter='graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -L {layout=dot} -F {format=png} -'

 [graphviz-block]
 template::[image-blockmacro]
@@ -17,7 +17,7 @@
 delimiter=^graphviz~{4,}$
 template=graphviz-block
 presubs=none
-filter=graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{target} -L {layout=dot}" -
+filter=graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{target} -L {layout=dot} -F {format=png}" -
 posattrs=target,format
 #
 # DEPRECATED: End
diff -r e401959b7729 filters/graphviz/graphviz2png.py
--- a/filters/graphviz/graphviz2png.py  Wed Feb 17 18:39:45 2010 +1300
+++ b/filters/graphviz/graphviz2png.py  Sat Feb 20 00:13:56 2010 +0200
@@ -1,10 +1,10 @@
 #!/usr/bin/env python

-import os, sys
+import os, sys, subprocess
 from optparse import *

 __AUTHOR__ = "Gouichi Iisaka <iisaka51@gmail.com>"
-__VERSION__ = '1.1.3'
+__VERSION__ = '1.1.4'

 class EApp(Exception):
     '''Application specific exception.'''
@@ -32,6 +32,11 @@
         Graphviz layout: dot, neato, twopi, circo, fdp
         Default is 'dot'.

+    -F FORMAT, --format=FORMAT
+  Graphviz output format: png, svg, or any other format Graphviz
+  supports. Run dot -T? to get the full list.
+        Default is 'dot'.
+
     -v, --verbose
         Verbosely print processing information to stderr.

@@ -46,6 +51,7 @@

 AUTHOR
     Written by Gouichi Iisaka, <iisaka51@gmail.com>
+    Format support added by Elmo Todurov, <todurov@gmail.com>

 THANKS
     Stuart Rackham, <srackham@gmail.com>
@@ -58,6 +64,11 @@
     '''
 
     def __init__(self, argv=None):
+  # Run dot, get the list of supported formats. It's prefixed by some junk.
+  format_output = subprocess.Popen(["dot", "-T?"], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[1]
+  # The junk contains : and ends with :. So we split it, then strip the final endline, then split the list for future usage.
+  supported_formats = format_output.split(": ")[2][:-1].split(" ")
+
         if not argv:
             argv = sys.argv

@@ -73,6 +84,10 @@
                     dest="layout", default="dot", type="choice",
                     choices=['dot','neato','twopi','circo','fdp'],
         help="Layout type. LAYOUT=<dot|neato|twopi|circo|fdp>"),
+            Option("-F", "--format", action="store",
+                    dest="format", default="png", type="choice",
+                    choices=supported_formats,
+        help="Format type. FORMAT=<" + "|".join(supported_formats) + ">"),
             Option("--debug", action="store_true",
         dest="do_debug",
         help=SUPPRESS_HELP),
@@ -114,8 +129,8 @@
         saved_cwd = os.getcwd()
         os.chdir(outdir)
         try:
-            cmd = '%s -Tpng "%s" > "%s"' % (
-                        self.options.layout, infile, outfile)
+            cmd = '%s -T%s "%s" > "%s"' % (
+                        self.options.layout, self.options.format, infile, outfile)
             self.systemcmd(cmd)
         finally:
             os.chdir(saved_cwd)
@@ -124,6 +139,9 @@
             os.unlink(infile)

     def run(self):
+  if self.options.format == '':
+      self.options.format = 'png'
+
         if self.options.infile == '-':
             if self.options.outfile is None:
                 sys.stderr.write('OUTFILE must be specified')

comment:3 Changed 20 months ago by ct

  • Blocking 626 added

comment:4 Changed 2 months ago by ichthyo

PING

What's up with this one?

  • can anyone please review the solution provided by cizra ?
  • any news from upstream?
Note: See TracTickets for help on using tickets.