Skip to content

Commit

Permalink
Core: Rename defaultLang to defaultLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Jun 12, 2024
1 parent 310e0ab commit 053609d
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 205 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-seals-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---

Rename `defaultLang` to `defaultLanguage`
10 changes: 5 additions & 5 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"start": "next start"
},
"dependencies": {
"@next/env": "^14.2.3",
"@next/env": "^14.2.4",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-tooltip": "^1.0.7",
"algoliasearch": "^4.23.3",
Expand All @@ -27,19 +27,19 @@
"geist": "^1.3.0",
"katex": "^0.16.10",
"lucide-react": "^0.394.0",
"next": "^14.2.3",
"next": "^14.2.4",
"phenomenon": "^1.6.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rehype-katex": "^7.0.0",
"remark-math": "^6.0.0",
"shiki": "^1.6.3",
"shiki": "^1.6.4",
"tailwind-merge": "^2.3.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.3",
"@next/eslint-plugin-next": "^14.2.3",
"@next/bundle-analyzer": "^14.2.4",
"@next/eslint-plugin-next": "^14.2.4",
"@types/mdx": "^2.0.13",
"@types/node": "18.17.5",
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/contentlayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"fumadocs-contentlayer": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"next-contentlayer": "^0.3.4",
"react": "18.3.1",
"react-dom": "18.3.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/next-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
},
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.4",
"@shikijs/rehype": "^1.6.3",
"@shikijs/transformers": "^1.6.3",
"@shikijs/rehype": "^1.6.4",
"@shikijs/transformers": "^1.6.4",
"flexsearch": "0.7.21",
"github-slugger": "^2.0.0",
"hast-util-to-estree": "^3.1.0",
Expand All @@ -139,7 +139,7 @@
"remark-gfm": "^4.0.0",
"remark-mdx": "^3.0.1",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.6.3",
"shiki": "^1.6.4",
"swr": "^2.2.5",
"unist-util-visit": "^5.0.0"
},
Expand All @@ -156,7 +156,7 @@
"@types/react-dom": "^18.3.0",
"algoliasearch": "^4.23.3",
"eslint-config-custom": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"tsconfig": "workspace:*",
"unified": "^11.0.4"
},
Expand Down
41 changes: 7 additions & 34 deletions packages/core/src/mdx-plugins/rehype-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
transformerNotationWordHighlight,
} from '@shikijs/transformers';
import type { Processor, Transformer } from 'unified';
import { visit } from './hast-utils';
import type { IconOptions, CodeBlockIcon } from './transformer-icon';
import { transformerIcon } from './transformer-icon';

Expand Down Expand Up @@ -33,7 +32,7 @@ export const rehypeCodeDefaultOptions: RehypeCodeOptions = {
light: 'github-light',
dark: 'github-dark',
},
defaultLang: 'plaintext',
defaultLanguage: 'plaintext',
defaultColor: false,
transformers: [
transformerNotationHighlight(),
Expand Down Expand Up @@ -72,6 +71,7 @@ export type RehypeCodeOptions = RehypeShikiOptions & {
* Default language
*
* @defaultValue plaintext
* @deprecated Use `defaultLanguage` instead
*/
defaultLang?: string;

Expand All @@ -96,7 +96,7 @@ export function rehypeCode(
codeOptions.transformers ||= [];
codeOptions.transformers = [
{
name: 'rehype-code:filter-meta',
name: 'rehype-code:pre-process',
preprocess(code, { meta }) {
if (meta && codeOptions.filterMetaString) {
meta.__raw = codeOptions.filterMetaString(meta.__raw ?? '');
Expand Down Expand Up @@ -125,38 +125,11 @@ export function rehypeCode(
];
}

const prefix = 'language-';
const transformer = rehypeShiki.call(this, codeOptions);

return async (root, file) => {
visit(root, ['pre'], (element) => {
const head = element.children[0];

if (
element.children.length === 0 ||
head.type !== 'element' ||
head.tagName !== 'code'
)
return;

head.properties.className ||= [];
const classes = head.properties.className;

if (!Array.isArray(classes)) return;

const hasLanguage = classes.some(
(d) => typeof d === 'string' && d.startsWith(prefix),
);

if (!hasLanguage && codeOptions.defaultLang)
classes.push(`${prefix}${codeOptions.defaultLang}`);
});
if (codeOptions.defaultLang) {
codeOptions.defaultLanguage = codeOptions.defaultLang;
}

if (transformer)
await transformer.call(this, root, file, () => {
// nothing
});
};
return rehypeShiki.call(this, codeOptions) as Transformer<Root, Root>;
}

export { type CodeBlockIcon, transformerIcon };
2 changes: 1 addition & 1 deletion packages/create-app-versions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"contentlayer": "^0.3.4",
"next": "^14.2.3",
"next": "^14.2.4",
"next-contentlayer": "^0.3.4",
"postcss": "^8.4.38",
"react": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@types/react": "^18.3.3",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"tsconfig": "workspace:*",
"unified": "^11.0.4",
"webpack": "^5.90.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/twoslash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"types:check": "tsc --noEmit"
},
"dependencies": {
"@shikijs/twoslash": "1.6.3",
"@shikijs/twoslash": "1.6.4",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"mdast-util-to-hast": "^13.2.0",
"shiki": "1.6.3"
"shiki": "1.6.4"
},
"devDependencies": {
"@types/hast": "^3.0.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
},
"devDependencies": {
"@algolia/client-search": "^4.23.3",
"@next/eslint-plugin-next": "^14.2.3",
"@next/eslint-plugin-next": "^14.2.4",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"algoliasearch": "^4.23.3",
"eslint-config-custom": "workspace:*",
"next": "^14.2.3",
"next": "^14.2.4",
"postcss": "^8.4.38",
"postcss-cli": "^11.0.0",
"postcss-lightningcss": "^1.0.0",
Expand Down
Loading

0 comments on commit 053609d

Please sign in to comment.