ivanceras / svgbob

Convert your ascii diagram scribbles into happy little SVG
http://ivanceras.github.io/svgbob-editor/
Apache License 2.0
3.88k stars 109 forks source link

Command line stdin conversion #15

Closed yhql closed 7 years ago

yhql commented 7 years ago

I would like to make a pandoc filter that does basically what spongedown does with ascii drawings. But I can't find how to properly pass a multiline string to svgbob through the command line. How is this done ?

On Windows, I have tried things like : echo "+--+\n| |\n+--+" | svgbob but the \n are kept as they are, and trying to pass the raw string from python actually ends the command in the middle of the string, effectively yielding an echo of the first line of the drawing.

ivanceras commented 7 years ago

Make sure you installed svgbob_cli via cargo install -f svgbob_cli. Invoke the command with svgbob Trying out your example:

$> echo "+--+\n| |\n+--+" | svgbob
<svg class="bob" font-family="arial" font-size="14" height="16" width="120" xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="triangle" markerHeight="10" markerUnits="strokeWidth" markerWidth="10" orient="auto" refX="15" refY="10" viewBox="0 0 50 20">
<path d="M 0 0 L 30 10 L 0 20 z"/>
</marker>
</defs>
<style>

    line, path {
      stroke: black;
      stroke-width: 2;
      stroke-opacity: 1;
      fill-opacity: 1;
      stroke-linecap: round;
      stroke-linejoin: miter;
    }
    circle {
      stroke: black;
      stroke-width: 2;
      stroke-opacity: 1;
      fill-opacity: 1;
      stroke-linecap: round;
      stroke-linejoin: miter;
    }
    circle.solid {
      fill:black;
    }
    circle.open {
      fill:transparent;
    }
    tspan.head{
        fill: none;
        stroke: none;
    }

</style>
<path d=" M 4 8 L 8 8 L 16 8 M 8 8 L 16 8 L 24 8 M 16 8 L 24 8 M 28 8 L 24 8 M 40 16 L 32 0 L 40 16 M 68 0 L 68 16 M 68 0 L 68 16 M 80 16 L 72 0 L 80 16 M 92 8 L 96 8 L 104 8 M 96 8 L 104 8 L 112 8 M 104 8 L 112 8 M 116 8 L 112 8" fill="none"/>
<path d="" fill="none" stroke-dasharray="3 3"/>
<text x="41" y="12">
n|
</text>
<text x="81" y="12">
n
</text>
</svg>
yhql commented 7 years ago

Thanks for looking into that. I also get some result with the example you tested, but here is what the svg you posted looks like :

svg

(in the svg you can also see that the \n are actually written as <text>n</text>) When using an external file (with actual newline characters) :

svg3

I get something slightly different with the same command line, so I will perform the installation like you said, but I think the newline character will still be handled the same way :

svg2

ivanceras commented 7 years ago

Hi, it looks like a huge bug, probably with the added " as escaping character to be not interpreted as graphics. I've to look at this further.

ivanceras commented 7 years ago

@yhql it looks like this is not an issue with svgbob at all, but echo is sending literal "\n". That needs to be an actual line. Try putting -e instead with echo -e "+--+\n| |\n+--+" | svgbob. Alternatively you can also try printf "+--+\n| |\n+--+" | svgbob as stated here https://stackoverflow.com/questions/8467424/echo-newline-in-bash-prints-literal-n

yhql commented 7 years ago

Thanks for the info. Sadly as I'm on windows the echo command does not have any special flags that would help. I did try the following trick : echo "+--+" & echo "| |" & echo "+--+" | svgbob which almost does the job : the drawing is correct but there seems to be no way of getting rid of the " characters in the result.

yhql commented 7 years ago

If you're ok with it I could try to make svgbob accept strings as first arguments so that it handles the \n and others by itself, rather than let the terminal deal with it (because I don't see any way around on Windows).