Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mintlify/mdx",
"version": "2.0.2",
"version": "2.0.3",
"description": "Markdown parser from Mintlify",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -68,6 +68,7 @@
"react-dom": "^18.3.1"
},
"dependencies": {
"@shikijs/transformers": "^3.6.0",
"hast-util-to-string": "^3.0.1",
"mdast-util-mdx-jsx": "^3.2.0",
"next-mdx-remote-client": "^1.0.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/mdx/src/plugins/rehype/rehypeSyntaxHighlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DEFAULT_LIGHT_THEME,
DEFAULT_THEMES,
DEFAULT_LANGS,
SHIKI_TRANSFORMERS,
} from './shiki-constants.js';
import { getLanguage } from './utils.js';

Expand Down Expand Up @@ -126,6 +127,7 @@ const traverseNode = (
colorReplacements: shikiColorReplacements,
tabindex: false,
tokenizeMaxLineLength: 1000,
transformers: SHIKI_TRANSFORMERS,
});

const codeElement = hast.children[0] as Element;
Expand Down
35 changes: 35 additions & 0 deletions packages/mdx/src/plugins/rehype/shiki-constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import {
transformerNotationHighlight,
transformerNotationFocus,
transformerMetaHighlight,
transformerNotationDiff,
} from '@shikijs/transformers';
import type { ShikiTransformer } from '@shikijs/types';
import { createCssVariablesTheme } from 'shiki/core';
import type { BundledLanguage, ThemeRegistration } from 'shiki/types';

export const LINE_HIGHLIGHT_CLASS_NAME = 'line-highlight';
export const LINE_FOCUS_CLASS_NAME = 'line-focus';
export const LINE_DIFF_ADD_CLASS_NAME = 'line-diff line-add';
export const LINE_DIFF_REMOVE_CLASS_NAME = 'line-diff line-remove';

export type ShikiLang = BundledLanguage | 'text';
export type ShikiTheme = (typeof SHIKI_THEMES)[number];

Expand Down Expand Up @@ -493,3 +505,26 @@ export const DEFAULT_LANGS = [
'tsx',
'yaml',
];

export const matchAlgorithm = {
matchAlgorithm: 'v3',
} as const;

export const SHIKI_TRANSFORMERS: ShikiTransformer[] = [
transformerMetaHighlight({
className: LINE_HIGHLIGHT_CLASS_NAME,
}),
transformerNotationHighlight({
...matchAlgorithm,
classActiveLine: LINE_HIGHLIGHT_CLASS_NAME,
}),
transformerNotationFocus({
...matchAlgorithm,
classActiveLine: LINE_FOCUS_CLASS_NAME,
}),
transformerNotationDiff({
...matchAlgorithm,
classLineAdd: LINE_DIFF_ADD_CLASS_NAME,
classLineRemove: LINE_DIFF_REMOVE_CLASS_NAME,
}),
];
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ __metadata:
"@mintlify/eslint-config-typescript": "npm:^1.0.9"
"@mintlify/prettier-config": "npm:^1.0.1"
"@mintlify/ts-config": "npm:^2.0.2"
"@shikijs/transformers": "npm:^3.6.0"
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
"@tsconfig/recommended": "npm:1.x"
"@types/hast": "npm:^3.0.4"
Expand Down Expand Up @@ -693,6 +694,16 @@ __metadata:
languageName: node
linkType: hard

"@shikijs/transformers@npm:^3.6.0":
version: 3.6.0
resolution: "@shikijs/transformers@npm:3.6.0"
dependencies:
"@shikijs/core": "npm:3.6.0"
"@shikijs/types": "npm:3.6.0"
checksum: 10c0/c08d65bffe2c484ce2e6b0b3016379833fa79d53e22fdfa575c10d0b6c3a35580742a2e9ef2032288178d87c99505544f62bde01434d79c87f0ff9b2c4f03fb6
languageName: node
linkType: hard

"@shikijs/types@npm:3.6.0":
version: 3.6.0
resolution: "@shikijs/types@npm:3.6.0"
Expand Down