data-uri & graphviz execution order

200 views
Skip to first unread message

Suraj N. Kurapati

unread,
Jul 31, 2010, 10:28:20 PM7/31/10
to asciidoc
Hello,

I am using asciidoc 8.5.3 and I noticed that the data-uri filter is
executed _before_ the graphviz filter, causing broken images (empty
data URIs) in the resulting HTML.

For example, consider the following `simple.asciidoc` file.

====================================================================
$ ls
simple.asciidoc

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

$ asciidoc -d manpage -a icons -a data-uri -a toc -v simple.asciidoc
asciidoc: reading: /etc/asciidoc/asciidoc.conf
asciidoc: reading: /etc/asciidoc/xhtml11.conf
asciidoc: reading: /etc/asciidoc/xhtml11-quirks.conf
asciidoc: reading: /etc/asciidoc/filters/source/source-highlight-
filter.conf
asciidoc: reading: /etc/asciidoc/filters/graphviz/graphviz-filter.conf
asciidoc: reading: /etc/asciidoc/filters/music/music-filter.conf
asciidoc: reading: /etc/asciidoc/filters/code/code-filter.conf
asciidoc: reading: /etc/asciidoc/lang-en.conf
asciidoc: reading: /home/sun/tmp/bar/simple.asciidoc
asciidoc: writing: /home/sun/tmp/bar/simple.html
asciidoc: ERROR: simple.asciidoc: line 1: manpage document title is
mandatory
asciidoc: simple.asciidoc: line 2: evaluating: {eval:os.path.join("/
home/sun/tmp/bar","","sample1.png")}
asciidoc: simple.asciidoc: line 2: evaluating: {sys:python -uc "import
base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/
sample1.png"}
sh: /home/sun/tmp/bar/sample1.png: No such file or directory
asciidoc: WARNING: simple.asciidoc: line 2: {sys:python -uc "import
base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/
sample1.png"}: non-zero exit status
asciidoc: simple.asciidoc: line 2: evaluating:
{eval:os.path.splitext('sample1.png')[1][1:]}
asciidoc: simple.asciidoc: line 3: filtering: "/etc/asciidoc/filters/
graphviz/graphviz2png.py" -v -o "/home/sun/tmp/bar/sample1.png" -L dot
-
Execute: dot -Tpng "/home/sun/tmp/bar/sample1.txt" > "/home/sun/tmp/
bar/sample1.png"

$ grep -A1 data: simple.html
<img alt="sample1.png" src="data:image/png;base64,
" />
====================================================================

Notice the WARNING emitted by the data-uri filter, saying that it
could not find the `sample1.png` file to embed. Now if we run
asciidoc again, the data-uri filter will find the file.

====================================================================
$ asciidoc -d manpage -a icons -a data-uri -a toc -v simple.asciidoc
asciidoc: reading: /etc/asciidoc/asciidoc.conf
asciidoc: reading: /etc/asciidoc/xhtml11.conf
asciidoc: reading: /etc/asciidoc/xhtml11-quirks.conf
asciidoc: reading: /etc/asciidoc/filters/source/source-highlight-
filter.conf
asciidoc: reading: /etc/asciidoc/filters/graphviz/graphviz-filter.conf
asciidoc: reading: /etc/asciidoc/filters/music/music-filter.conf
asciidoc: reading: /etc/asciidoc/filters/code/code-filter.conf
asciidoc: reading: /etc/asciidoc/lang-en.conf
asciidoc: reading: /home/sun/tmp/bar/simple.asciidoc
asciidoc: writing: /home/sun/tmp/bar/simple.html
asciidoc: ERROR: simple.asciidoc: line 1: manpage document title is
mandatory
asciidoc: simple.asciidoc: line 2: evaluating: {eval:os.path.join("/
home/sun/tmp/bar","","sample1.png")}
asciidoc: simple.asciidoc: line 2: evaluating: {sys:python -uc "import
base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/
sample1.png"}
asciidoc: simple.asciidoc: line 2: evaluating:
{eval:os.path.splitext('sample1.png')[1][1:]}
asciidoc: simple.asciidoc: line 3: filtering: "/etc/asciidoc/filters/
graphviz/graphviz2png.py" -v -o "/home/sun/tmp/bar/sample1.png" -L dot
-
Execute: dot -Tpng "/home/sun/tmp/bar/sample1.txt" > "/home/sun/tmp/
bar/sample1.png"

$ grep -A1 data: simple.html
<img alt="sample1.png" src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAhUAAAA7CAYAAADM3XgRAAAABmJLR0QA/wD/AP
+gvaeTAAAgAElE
====================================================================

Please correct this problem by defering the data-uri filter until
after all other filters have executed.

Thanks for your consideration.

Stuart Rackham

unread,
Aug 3, 2010, 1:48:05 AM8/3/10
to asci...@googlegroups.com
Hi Suraj

You are correct, this is a bug (the workaround is to run asciidoc twice, the
first time it will give and error but generate the images, the second time it
will work. The problem with this workaround is that subsequent runs work but any
updated images won't appear until they're processed twice.

The fix is easy but unfortunately it breaks the auto file name generation
introduced in r756. I need to come up with a fix that won't break things.


Cheers, Stuart

Stuart Rackham

unread,
Aug 3, 2010, 8:26:56 PM8/3/10
to asci...@googlegroups.com
This has now been fixed in the trunk, please test it.

http://code.google.com/p/asciidoc/source/detail?r=a8f8d593de5e4e207046f83b60ae6b398e10f036

Cheers, Stuart


On 01/08/10 14:28, Suraj N. Kurapati wrote:

Suraj Kurapati

unread,
Aug 12, 2010, 4:17:51 AM8/12/10
to asci...@googlegroups.com
On Tue, Aug 3, 2010 at 5:26 PM, Stuart Rackham <srac...@gmail.com> wrote:
> This has now been fixed in the trunk, please test it.
>
> http://code.google.com/p/asciidoc/source/detail?r=a8f8d593de5e4e207046f83b60ae6b398e10f036

Thanks for implementing this. Unfortunately, it did not work correctly.
I am using AsciiDoc from the source repository at changeset eef6876f313e.

sun@yantram ~/tmp> cat graphviz.txt


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

#
# Running it the first time...
#

sun@yantram ~/tmp> asciidoc -a data-uri graphviz.txt
Usage: graphviz2png.py [options] inputfile

graphviz2png.py: error: no such option: -F
asciidoc: WARNING: graphviz.txt: line 3: filter non-zero exit code:
"/etc/asciidoc/filters/graphviz/graphviz2png.py" -o
"/home/sun/tmp/sample1.png" -L dot -F png -: returned 2
asciidoc: WARNING: graphviz.txt: line 3: no output from filter:
"/etc/asciidoc/filters/graphviz/graphviz2png.py" -o
"/home/sun/tmp/sample1.png" -L dot -F png -
sh: /home/sun/tmp/sample1.png: No such file or directory
asciidoc: WARNING: graphviz.txt: line 3: {sys:python -uc "import
base64,sys; base64.encode(sys.stdin,sys.stdout)" <
"/home/sun/tmp/sample1.png"}: non-zero exit status

sun@yantram ~/tmp> grep -A1 data: graphviz.html


<img alt="sample1.png" src="data:image/png;base64,
" />

#
# Running it again a second time....
#

sun@yantram ~/tmp> asciidoc -a data-uri graphviz.txt
Usage: graphviz2png.py [options] inputfile

graphviz2png.py: error: no such option: -F
asciidoc: WARNING: graphviz.txt: line 3: filter non-zero exit code:
"/etc/asciidoc/filters/graphviz/graphviz2png.py" -o
"/home/sun/tmp/sample1.png" -L dot -F png -: returned 2
asciidoc: WARNING: graphviz.txt: line 3: no output from filter:
"/etc/asciidoc/filters/graphviz/graphviz2png.py" -o
"/home/sun/tmp/sample1.png" -L dot -F png -
sh: /home/sun/tmp/sample1.png: No such file or directory
asciidoc: WARNING: graphviz.txt: line 3: {sys:python -uc "import
base64,sys; base64.encode(sys.stdin,sys.stdout)" <
"/home/sun/tmp/sample1.png"}: non-zero exit status

sun@yantram ~/tmp> grep -A1 data: graphviz.html

Stuart Rackham

unread,
Aug 12, 2010, 6:35:26 AM8/12/10
to asci...@googlegroups.com

On 12/08/10 20:17, Suraj Kurapati wrote:
> On Tue, Aug 3, 2010 at 5:26 PM, Stuart Rackham<srac...@gmail.com> wrote:
>> This has now been fixed in the trunk, please test it.
>>
>> http://code.google.com/p/asciidoc/source/detail?r=a8f8d593de5e4e207046f83b60ae6b398e10f036
>
> Thanks for implementing this. Unfortunately, it did not work correctly.
> I am using AsciiDoc from the source repository at changeset eef6876f313e.

Works for me, here's the verbose output:

$ rm sample1.png

$ cat t2.txt


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

$ asciidoc -adata-uri -v t2.txt
asciidoc: reading: /home/srackham/projects/asciidoc/trunk/asciidoc.conf
asciidoc: reading: /home/srackham/projects/asciidoc/trunk/xhtml11.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/latex/latex-filter.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/source/source-highlight-filter.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/pigmentize/pygmentize-filter.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/graphviz/graphviz-filter.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/code/code-filter.conf
asciidoc: reading: /home/srackham/projects/asciidoc/trunk/filters/mpl/mpl.conf
asciidoc: reading:
/home/srackham/projects/asciidoc/trunk/filters/music/music-filter.conf
asciidoc: reading: /home/srackham/projects/asciidoc/trunk/t2.txt
asciidoc: writing: /home/srackham/projects/asciidoc/trunk/t2.html
asciidoc: reading: /home/srackham/projects/asciidoc/trunk/lang-en.conf
asciidoc: t2.txt: line 3: filtering:
"/home/srackham/projects/asciidoc/trunk/filters/graphviz/graphviz2png.py" -v -o
"/home/srackham/projects/asciidoc/trunk/sample1.png" -L dot -F png -
Execute: dot -Tpng "/home/srackham/projects/asciidoc/trunk/sample1.txt" >
"/home/srackham/projects/asciidoc/trunk/sample1.png"
asciidoc: t2.txt: line 3: evaluating: {eval:os.path.splitext('sample1.png')[1][1:]}
asciidoc: t2.txt: line 3: evaluating:
{eval:os.path.join("/home/srackham/projects/asciidoc/trunk","","sample1.png")}
asciidoc: t2.txt: line 3: evaluating: {sys:python -uc "import base64,sys;
base64.encode(sys.stdin,sys.stdout)" <
"/home/srackham/projects/asciidoc/trunk/sample1.png"}

Your problem is in the graphviz execution, try running the failing graphviz2png
command from the command line with the -v option e.g.

$ echo "digraph G { rankdir=LR;
Graphviz->AsciiDoc->HTML}"|"/home/srackham/projects/asciidoc/trunk/filters/graphviz/graphviz2png.py"
-v -o "/home/srackham/projects/asciidoc/trunk/sample1.png" -L dot -F png -
Execute: dot -Tpng "/home/srackham/projects/asciidoc/trunk/sample1.txt" >
"/home/srackham/projects/asciidoc/trunk/sample1.png"

Suraj Kurapati

unread,
Aug 13, 2010, 1:43:05 AM8/13/10
to asci...@googlegroups.com
On Thu, Aug 12, 2010 at 3:35 AM, Stuart Rackham <srac...@gmail.com> wrote:
> Your problem is in the graphviz execution, try running the failing
> graphviz2png command from the command line with the -v option e.g.
>
> $ echo "digraph G { rankdir=LR;
> Graphviz->AsciiDoc->HTML}"|"/home/srackham/projects/asciidoc/trunk/filters/graphviz/graphviz2png.py"
> -v -o "/home/srackham/projects/asciidoc/trunk/sample1.png" -L dot -F png -
> Execute: dot -Tpng "/home/srackham/projects/asciidoc/trunk/sample1.txt" >
> "/home/srackham/projects/asciidoc/trunk/sample1.png"

Yes, that command worked correctly for me. Does this mean I missing
something in my local environment?

# echo "digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML}" |
~/lab/asciidoc/filters/graphviz/graphviz2png.py -v -o foo.png -L dot
-F png -
Execute: dot -Tpng "foo.txt" > "/home/sun/foo.png"

Stuart Rackham

unread,
Aug 13, 2010, 2:58:10 AM8/13/10
to asci...@googlegroups.com

I think you've got more than one copy of asciidoc on your system. From the
previous post asciidoc was running the filter
/etc/asciidoc/filters/graphviz/graphviz2png.py but above you are running
~/lab/asciidoc/filters/graphviz/graphviz2png.py. Try renaming or removing the
global /etc/asciidoc directory (I'm guessing it's from a previous install).

Cheers, Stuart

jpablobr

unread,
Feb 14, 2012, 12:42:02 AM2/14/12
to asci...@googlegroups.com
hehe a bit late! but on Arch linux I was able to fix this by replacing the eval python calls to use python2.

for exaple:

{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/sample1.png"} 

to:
{sys:python2 -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/ sample1.png"} 

I think is is Arch linux specific

Lex Trotman

unread,
Feb 14, 2012, 6:06:59 AM2/14/12
to asci...@googlegroups.com

Hi,

I guess your default python is python3. (Arch is always early adopters)

This will likely come up more often over time so its probably good to
have picked it up early thanks.

Cheers
Lex

Christian Kyony

unread,
Jan 25, 2014, 4:23:45 AM1/25/14
to asci...@googlegroups.com
Dear jpablobr,

I am also using Archlinux. I am not able to use the graphviz filter. In which file I need to make the changes you recommend?

Thanks,

Christian

Lex Trotman

unread,
Jan 25, 2014, 7:15:15 AM1/25/14
to asci...@googlegroups.com
On 25 January 2014 20:23, Christian Kyony <cky...@changamuka.com> wrote:
Dear jpablobr,

I am also using Archlinux. I am not able to use the graphviz filter. In which file I need to make the changes you recommend?

If its only the graphviz filter, then filters/graphviz2png.py in line 1 should say python2 not python.

Cheers
lex
 

Thanks,

Christian


On Tuesday, February 14, 2012 7:42:02 AM UTC+2, jpablobr wrote:
hehe a bit late! but on Arch linux I was able to fix this by replacing the eval python calls to use python2.

for exaple:

{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/sample1.png"} 

to:
{sys:python2 -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "/home/sun/tmp/bar/ sample1.png"} 

I think is is Arch linux specific

--
You received this message because you are subscribed to the Google Groups "asciidoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asciidoc+u...@googlegroups.com.

To post to this group, send email to asci...@googlegroups.com.
Visit this group at http://groups.google.com/group/asciidoc.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages