Use custom output_format in blogdown

Is it possible in blogdown to use an output format other than blogdown::html_page?

This question was asked last year on StackOverflow but hasn't been answered there.

This is a good question, I never tried but I assume this is possible. From the documentation book it seems that the format included in bookdown is for convenience but also to provide a specific PANDOC html Template minimal enough to work with hugo.

This template can be modified and it is also explain in the book

I believe this offer some mechanism for customisation but also seems to point out that not every format will be ok because the html they generate would be to much for hugo website theme I believe.

If any one as a working example, please share :smile:

Unfortunately for the theme I have in mind (the GOV.UK Design System) it isn't enough to modify the template -- the call to pandoc needs to include a lua script to add classes to the html tags.

I tried modifying _output.yml as suggested by the book, but it ignores the first line and passes the other parameters into html_page.

my::custom_format: # this line is ignored
  toc: true
  fig_width: 6
  dev: "svg"

From the source code, yes it seems that the format html_page is hard coded. You can only change the option of this format like the template or others pass through underlying format.

it is a wrapper of bookdown::html_document2 and you can change the base_format, using base_format argument. By default, it is rmarkdown::html_document. I believe you can change that.

Also, ... is pass to this base format function. By default, rmarkdown::html_document has a pandoc_args argument that I believe you can use to pass some lua filters script. pandoc arg is --lua-filters.

I believe with all that you can customize and see what is working or not.

Hoping I am not misunderstanding your request.

3 Likes

Thanks again @cderv, I hadn't thought of setting base_format, and it seems to work. I think I can write a custom format that ignores everything that html_page() and hmtl_document2() set.

The reason why this has been more difficult than normal is because I want to distribute the theme as a package, and require as little configuration by users as possible. So for example I want to avoid asking users to set pandoc_args themselves.

For me, this wish is related to developing a custom format in your package, one that will set the pandoc args for your users based on the input you want.
I am thinking about that


There are several existing :package: that define custom format.

This topic was automatically closed 21 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.