Skip to content

🐛 BUG: Remark plugin transformer file.path returns undefined #3264

@stephanbogner

Description

@stephanbogner

What version of astro are you using?

1.0.0-beta.20

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Whatever StackBlitz uses

Describe the Bug

Intention:

I am trying to create a remark-plugin that allows having image-files right next to .md files.

Approach:

  1. I struggled to obtain the absolute file paths of the .md (or the images) so I opened a thread in the remarkjs discussions
  2. The maintainer wooorm mentioned that file.path should return well the file path. But it seems in Astro it doesn't (see StackBlitz)
  3. Woorm also replied that the root cause might be this bit of code in the Astro source code

Relevant bit of code:

export default function (pluginOptions) {
  const transformer = (tree, file) => {
    console.log('Transformer data:');
    console.log(file.path); // -> returns undefined
  };

  return transformer;
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-3cnfvx-nsf5xw?file=custom-remark-plugin/index.mjs

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)feat: markdownRelated to Markdown (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions