Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded SVGs are not supported by WeasyPrint #3

Closed
pothos opened this issue Jun 15, 2018 · 8 comments
Closed

Embedded SVGs are not supported by WeasyPrint #3

pothos opened this issue Jun 15, 2018 · 8 comments

Comments

@pothos
Copy link

pothos commented Jun 15, 2018

This here helps to render in WeasyPrint:

     svg = wait["for"](tex2svg, tex, inline);
+    svg = '<img src="data:image/svg+xml;charset=utf-8;base64,' + Buffer.from(svg).toString('base64') + '"/>';
     return pandoc.RawInline("html", inline ? svg : wrap(svg));

Maybe it could be configured by exposing a second filter executable (or passing an argument but I don't know if that works with pandoc's filter command line invokation)?

@lierdakil
Copy link
Owner

It's not the hardest thing to do, but img tags tend to be misaligned. Compare:
img tags:
image
inline SVG:
image

@pothos
Copy link
Author

pothos commented Jun 18, 2018

Ah, which browser? Would style="display: inline; vertical-align: middle;" help?
Edit: Maybe fixing this depends on the browser, I don't need anything for it to work and adding something like my suggestion makes it worse in certain cases.

@pothos
Copy link
Author

pothos commented Jun 18, 2018

The solution is to copy the width, height and style attributes of the svg tag to the img tag…

@pothos
Copy link
Author

pothos commented Jun 18, 2018

    svg = wait["for"](tex2svg, tex, inline);
+   w = svg.match(/width="(.*?)"/)[0];
+   h = svg.match(/height="(.*?)"/)[0];
+   c = svg.match(/style="(.*?)"/)[0];
+   svg = '<img ' + w + ' ' + h + ' ' + c + ' src="data:image/svg+xml;charset=utf-8;base64,' + Buffer.from(svg).toString('base64') + '"/>';
    return pandoc.RawInline("html", inline ? svg : wrap(svg));

@pothos
Copy link
Author

pothos commented Jun 18, 2018

Webkit seems to have troubles with <img width="3ex"> but this can be fixed with moving it to <img style="width: 3ex;"> but I don't need this for WeasyPrint.

@lierdakil
Copy link
Owner

Huh. Cool, thanks for investigating. I've published v0.3.1. If you could test it and let me know if it works for you that would be great.

@lierdakil
Copy link
Owner

@pothos
Copy link
Author

pothos commented Jun 19, 2018

Thanks, perfect, it works same as my patch, both in WebKit and WeasyPrint 👍

@pothos pothos closed this as completed Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants