pngwn / MDsveX

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

Pass filename to highlighter #592

Closed vnphanquang closed 4 months ago

vnphanquang commented 7 months ago

Context

Today, as of mdsvex@0.11.0, a custom highlighter function is not aware of the filename of the file being processed by MDsveX, and there is no way (that i am aware of) to get around this using the public API.

This issue adds such support by passing additional filename positional param for highlighter.

Rationale

Having filename in highlighter will allow more complex customization. Specifically, I'm trying to have the syntax highlighter read the source code from file system provided in a meta line, something like this:

```svelte
/// source=./examples/an-example.svelte
```

This allows keeping certain example source code in a separate file, making better use of editor support, enabling reusability of said source code, and keeping the MDsveX file succinct.

changeset-bot[bot] commented 7 months ago

🦋 Changeset detected

Latest commit: 939981d07051b96ba28846058f34ee99d4ba55fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------ | ----- | | mdsvex | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vnphanquang commented 7 months ago

Ran prettier just now, amended to existing commit. Sorry for not doing that earlier.

pngwn commented 4 months ago

Sorry for the delay! Released now https://github.com/pngwn/MDsveX/releases/tag/mdsvex%400.11.1

vnphanquang commented 4 months ago

Sorry for the delay! Released now https://github.com/pngwn/MDsveX/releases/tag/mdsvex%400.11.1

Thanks 🎉. No worries at all