Hook for layouts or includes?

Hi all,

Is there a recommended mechanism via which we could hook into the rendering of Markdown files that are included via the include tag? For instance, if index.md has a layout of default.html, and default.html has

{% include foo.md %}

is there a way to register a hook that would allow us to alter foo.md before it’s rendered?

We’ve tried using a pre_render hook a la

Jekyll::Hooks.register [:pages], :pre_render do |doc, payload|
...
end

but that, of course, is only invoked for pages. And neither it (nor a pre_render hook on site) seems to give access to included Markdown files (like foo.md) because, by definition, they’re not yet rendered.

Our goal at hand is to prepend site.baseurl to any Markdown link in a site, just like relative_url, but without the need for a filter. That way, we can write Markdown like

* [Foo](/foo/)
* [Bar](/bar/)

instead of

* [Foo]({{ "/foo/" | relative_url }})
* [Bar]({{ "/bar/" | relative_url }})

in included files.

We can achieve that for pages with a pre_render hook, but that approach doesn’t allow us to rewrite URLs that are in, e.g., foo.md. We took a look at jekyll-relative-links for inspiration, but it turns out that doesn’t support included files either.

We’ve currently resorted to monkey-patching parse_link in Kramdown::Parser::GFM, but is there a more proper Jekyll-based approach perhaps?

Thank you!