Xaringan: Handle remark macros via xaringan?

Created on 13 Oct 2017  路  4Comments  路  Source: yihui/xaringan

From version 0.8.0, remark.js has had the ability to take user defined macros that can control output. I cam across this because I wanted to control the size of a single image without polluting my MD with raw HTML.

I found this solution https://github.com/gnab/remark/issues/72#issuecomment-62225566 which suggests the following

![:scale 50%](image.jpg)

with this macro

remark.macros.scale = function (percentage) {
  var url = this;
  return '<img src="' + url + '" style="width: ' + percentage + '" />';
};

The macro needs to be inserted right before

var slideshow = remark.create();

Are there any plans to allow this advanced usage of remark.js within xaringan?

(I know I can scale the image using HTML or CSS; this Q is more about handling macros which are a feature of the underlying library.)

Most helpful comment

Thanks for letting me know this hidden feature! Not being able to scale images using the Markdown syntax is probably the only reason that I was not totally satisfied with remark.js.

I'll think more about how to support macros.

All 4 comments

Thanks for letting me know this hidden feature! Not being able to scale images using the Markdown syntax is probably the only reason that I was not totally satisfied with remark.js.

I'll think more about how to support macros.

That would be a great enhancement :+1:

Thanks @yihui. I was wondering if the concept of includes from rmarkdown would be a good way to approach this?

A user would put the javascript macros they want in my_macros.js and then they can add

includes:
  - macro: 'my_macros.js'

in the YAML header and then have xaringan insert the content of my_macros.js into the rendered file in the appropriate location?

The includes option is not extensible. I just added an option beforeInit in the nature list of moon_reader(). See https://slides.yihui.name/xaringan/#30

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beatrizmilz picture beatrizmilz  路  4Comments

DavisVaughan picture DavisVaughan  路  3Comments

slowkow picture slowkow  路  3Comments

tcgriffith picture tcgriffith  路  4Comments

paullemmens picture paullemmens  路  5Comments