shd101wyy / vscode-markdown-preview-enhanced

One of the "BEST" markdown preview extensions for Visual Studio Code
https://shd101wyy.github.io/markdown-preview-enhanced
Other
1.47k stars 173 forks source link

Pandoc export always converts PlantUML to PNG? #1230

Open fuhrmanator opened 4 years ago

fuhrmanator commented 4 years ago

I'm using Pandoc export for this kind of markdown:

  ---
  title: "Book"
  author: Me
  date: 02 Décembre 2019
  geometry: margin=1in
  lang: fr
  documentclass: scrbook
  fontfamily: sourcesanspro
  fontfamilyoptions: default
  output:
    pdf_document:
      toc: true
      toc_depth: 3
  ---

  # Sequence

  ```plantuml {filename=seq.png}
  @startuml
  A -> B : hello
  @enduml
  `` `

Exporting this works OK, except the raster file is pixelated in the PDF file (that's normal, because I used a PNG).

However, PlantUML uses SVG (vector) format as a base. That is what is shown in the preview. I can see in the Windows Task Manager that PlantUML is running under the VSCode group with the -pipe and -tsvg options, which is likely how the diagrams are drawn in the preview.

Switching the format to filename=seq.svg in the markdown gives me a file assets/seq.svg which is indeed an SVG file. However, when I examine that file, it actually has a raster content:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="93px" height="131px" viewBox="0 0 93 131" enable-background="new 0 0 93 131" xml:space="preserve">  <image id="image0" width="93" height="131" x="0" y="0"    href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAACDCAMAAADYm+euAAAABGdBTUEAALGPC/xhBQAAACBjSFJN
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACYVBMVEX////Ob429P2itDz+9
P1z+/v7+/s6yNF3W1tbZ2dnf39/m5ubt7e3y8vL39/f8/Py8PmewMlvOzs7S0tLh4eHp6enw8PD6
...

I see in the mume code (if I'm understanding it properly) that pandocExport converts all SVG to PNG with ImageMagick, which explains why, when it's put back to SVG there's a PNG inside (even though the SVG doesn't render in the Pandoc).

I tried using pdf and eps as filetypes, and they work. But it's the same problem -- they are raster forms of my diagram when exported to Pandoc.

Exporting to Prince gets it right (the PlantUML diagrams are vectorial), I guess because it groks SVG whereas Pandoc (pdflatex) does not? It would be nice to tell PlantUML to output it as EPS or PDF (those types are supported).

fuhrmanator commented 4 years ago

I read more about ImageMagick and basically it's only a raster solution. So, I hacked around it, maybe it can give you an idea of how to make a more flexible design.

For the Image Magick Path setting, I used use-rsvg-convert.bat (I'm on windows 10). I know in the code that the extension will now call for plantuml diagrams

use-rsvg-convert.bat inputfile.svg outputfile

So, I next created use-rsvg-convert.bat and put it in my PATH somewhere:

:: Workaround to use rsvg-convert rather than imagemagick to create PDF files
rsvg-convert %1 -f pdf -o %2

Then when I generate PlantUML files, I must always specify {filename=something.pdf} (it has to be PDF, because of the -f pdf in the batch file or it won't work).