Include inputPath in environment options passed to markdown #4072
Replies: 5 comments
-
|
Hmm—does |
Beta Was this translation helpful? Give feedback.
-
|
I don’t believe we are able to access page variables from plugins that are called when rendering . I may be wrong . |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
|
For others who also want to access This is already possible, if a bit loopy. See details below.
function customPlugin (md, opts) {
md.renderer.rules.custom_render_rule = function (tokens, index, opts, env) {
// do some things...
return `now you can access inputPath! ${env.page.inputPath}`
}
}However......you should keep in mind that by accessing const customPluginDefaults = {
getAbsPathFromEnv: (env) => { return env.page.inputPath }, // in the case of 11ty
}...which would change the render rule to look like: function customPlugin (md, opts) {
const fullOptions = { ...customPluginDefaults, ...opts }; // this line merges default options with custom options
md.renderer.rules.custom_render_rule = function (tokens, index, opts, env) {
// do some things...
return `now you can access inputPath! ${fullOptions.getAbsPathFromEnv(env)}`
}
}EDIT: A live example plugin can be viewed at: See it in action in |
Beta Was this translation helpful? Give feedback.
-
|
And now there's also |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
Yes, It would be nice to have context to which file is being rendered when I am writing custom plugins for my markdown.
I am trying to process images that are in the same folder as a markdown file.
Describe the solution you'd like
Simply passing the inputPath to
mdlib.renderin Markdown.jsDescribe alternatives you've considered
There is no easy alternate at this point.
Additional context
N/A
Beta Was this translation helpful? Give feedback.
All reactions