Skip to content

Commit

Permalink
pass filename to highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Feb 29, 2024
1 parent 9627598 commit ae4db41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-sloths-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mdsvex': minor
---

Pass filename to highligher
6 changes: 4 additions & 2 deletions packages/mdsvex/src/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export function highlight_blocks({
}
}

return async function (tree) {
return async function (tree, vFile) {
if (highlight_fn) {
const nodes: (Code | HTML)[] = [];
visit<Code>(tree, 'code', (node) => {
Expand All @@ -560,7 +560,9 @@ export function highlight_blocks({
node.value = await highlight_fn(
node.value,
(node as Code).lang,
(node as Code).meta
(node as Code).meta,
//@ts-ignore
vFile.filename,
);
})
);
Expand Down
3 changes: 2 additions & 1 deletion packages/mdsvex/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export type Layout = Record<string, LayoutMeta>;
export type Highlighter = (
code: string,
lang: string | null | undefined,
metastring: string | null | undefined
metastring: string | null | undefined,
filename?: string,
) => string | Promise<string>;
interface HighlightOptions {
/**
Expand Down

0 comments on commit ae4db41

Please sign in to comment.