pngwn / MDsveX

A markdown preprocessor for Svelte.
https://mdsvex.pngwn.io
MIT License
2.36k stars 102 forks source link

Allow specifying multiple extensions to be processed #128

Closed aabounegm closed 4 years ago

aabounegm commented 4 years ago

I have a project where I use MDsveX with Sapper for the documentation, and all the routes were created with the .svx extension. I also have some markdown (.md) files in the project root for GitHub (such as README.md, CHANGELOG.md, and so on). I want to incorporate those in the docs, but the plugin only supports specifying one extension, so I am not able to import the .md file from the .svx one. It would be helpful if we can specify a list of extensions instead of just one extension. I realize that I could include it multiple times in the preprocess pipeline as such:

svelte({
  extensions: ['.svelte', '.svx', '.md'],
  preprocess: [
    mdsvex({
      layout: './src/mdsvex/layout.svelte',
      smartypants: {
        quotes: false,
        ellipses: true,
      },
      remarkPlugins: [remarkMark, remarkHeadingID],
      extension: '.svx',
    }),
    mdsvex({
      layout: './src/mdsvex/layout.svelte',
      smartypants: {
        quotes: false,
        ellipses: true,
      },
      remarkPlugins: [remarkMark, remarkHeadingID],
      extension: '.md',
    }),
  ],
  dev,
  hydratable: true,
  emitCss: true,
}),

but it becomes very tedious and suboptimal when more extensions are desired, aside from the repetition of the same configuration multiple times.

If you don't mind, I already started implementing this and can submit a pull request once you give me the green light.

pngwn commented 4 years ago

Yeah, this sounds good.

Could you add a new option extensions and leave the existing extension as it is. We can add a deprecation warning and remove the extension option in a future major.

aabounegm commented 4 years ago

Sounds good enough. I assume extensions should take precedence if it exists and extension would be ignored then?

pngwn commented 4 years ago

Yeah, that sounds right. Only use extension if extensions isn't defined.