trying to apply CSS to html_notebook file, render for web (distill)

I'm building a new website with the {distill} package but am having trouble figuring out how to apply CSS to html_notebook files where I have contained my projects.

It's a bit difficult to figure out what the appropriate reprex is so I'll just try to specify code as much as possible - sorry.

Formerly I've been able to simply host notebooks by putting them in nb.html form and putting them in the website directory (like so, but I would like to apply custom CSS to them for this rebuild.

I have a project directory for my new website. The index.Rmd file is a distill website with a theme from the postcards package (ie, the YAML contains site: distill::distill_website and output: postcards::trestles) that I have customized with a css file listed in the _site.yml (using this code: theme: theme2.css). When I preview the website the index page looks fine.

I can successfully link to files from the index called, for example, "project.nb.html" with standard markdown, but the theme is not applied to them.

As recommended by the Markdown Cookbook, I tried instead converting those html_notebook files to html_documents that refer to a CSS style document, by modifying the YAML like so:

output:
 html_document:
   css: "projectstyle.css"

but this creates this error when I attempt to knit:

Error in yaml::yaml.load(..., eval.expr = TRUE) : Scanner error: mapping values are not >allowed in this context at line 2, column 22

likewise, using

output: html_notebook(css = "project.css")

creates this error when knitted:

Error: YAML output format must evaluate to a function

I also tried the distill::create_article() function to see if I could copy the contents of the notebook into one of those, but it was not ultra helpful, there does not appear to be a way to convert existing markdown files into distill articles unless I haven't found it yet!

Very thankful for any help anyone can suggest.

The Rmarkdown Cookbook has a brief description. This block does work in plain Rmd

output:
 html_document:
   css: "projectstyle.css"

but not, of course, for distill. That requires working with a custom theme

Yes as said above, this should work.

What is on line 2 column 22 in the YAML header ?

Thanks for the help cderv and technocrat - issue ended up being that the CSS file I was trying to use had problem (@import url() for font wasn't working). I used a different method to apply the font and was able to render html_documents no problemo.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.