Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The createCommentNotationTransformer function was deleted #907

Open
buhodev opened this issue Jan 24, 2025 · 0 comments
Open

The createCommentNotationTransformer function was deleted #907

buhodev opened this issue Jan 24, 2025 · 0 comments

Comments

@buhodev
Copy link

buhodev commented Jan 24, 2025

I updated @shikijs/transformers package from version 1.27.2 to version 1.29.1 and there is no exported createCommentNotationTransformer function anymore, which now produces an error when I try to build my project:

error during build:
[vite-plugin-sveltekit-compile] src/lib/utils/highlighter.ts (8:1): "createCommentNotationTransformer" is not exported by "node_modules/@shikijs/transformers/dist/index.mjs", imported by "src/lib/utils/highlighter.ts".
file: /home/buhodev/projects/frontend/src/lib/utils/highlighter.ts:8:1

 6:   transformerNotationFocus,
 7:   transformerNotationErrorLevel,
 8:   createCommentNotationTransformer,
      ^
 9:   transformerNotationWordHighlight
10: } from '@shikijs/transformers';

What's the new recommended way to create custom transformers now? I am using the createCommentNotationTransformer function to create a transformer that leverages the word highlighting and also adds a data-tooltip="tooltip text" prop to the node.

function transformerNotationWordTooltip(options = {}) {
	const { classActiveWord = ['highlighted-word', 'tooltip'], classActivePre = void 0 } = options;
	return createCommentNotationTransformer(
		'@shikijs/transformers:notation-highlight-word',
		/^\s*(?:\/\/|\/\*|<!--|#)\s+\[!code tooltip:((?:\\.|[^:\]])+)(:\d+)?:(.*?)\]\s*(?:\*\/|-->)?/,

		function ([_, word, range, tooltipText], _line, comment, lines, index) {
			const lineNum = range ? Number.parseInt(range.slice(1), 10) : lines.length;
			word = word.replace(/\\(.)/g, '$1');
			tooltipText = tooltipText.replace(/\\(.)/g, '$1');
			lines
				.slice(index + 1, index + 1 + lineNum)
				.forEach((line) =>
					highlightWordInLine.call(this, line, comment, word, classActiveWord, tooltipText)
				);
			if (classActivePre) this.addClassToHast(this.code, classActivePre);
			return true;
		},
		true
	);
}

e.g. of usage in a markdown file:

// [!code tooltip:hello:My tooltip text!]
name: hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant