sinedied / backslide

:sweat_drops: CLI tool for making HTML presentations with Remark.js using Markdown
https://sinedied.github.io/backslide
MIT License
764 stars 50 forks source link

CSS images with relative paths are not inlined (PDF or HTML) #73

Closed mjpieters closed 4 years ago

mjpieters commented 4 years ago

When the stylesheet contains something like:

.acmecorp {
    display: flex;
    flex-direction: row;
    justify-content: center;
    p {
        text-align: left;
        padding-left: 3em;
        background-image: url(assets/acmelogo.png);
        background-size: 2em 2em;
        background-repeat: no-repeat;
        background-position: top 0.3em left 0.3em; 
    }
}

things look great when serving, but not-so-great when exporting to HTML or PDF. That's because the regular expression for CSS image URLs only matches url(file://...) references, not relative references:

const CssImagesRegExp = /(url\()((file:\/\/)[^)]+)(\))/gm;

Can this be updated to also pick up paths that do not start with a scheme or slash? Anything that doesn't start with [a-z]+: should be seen as a relative path, but perhaps limiting this to http:, https: and data: makes for an easier negative-lookbehind pattern to write.

mjpieters commented 4 years ago

My assertion about the images regexp was incorrect (it's not applicable in this case). The CSS is simply not processed for inlining.

Instead, CSS would have to be processed through Inline.css() if inlining is enabled.