diff --git a/.changeset/modern-snakes-taste.md b/.changeset/modern-snakes-taste.md new file mode 100644 index 0000000000..a70972e7cc --- /dev/null +++ b/.changeset/modern-snakes-taste.md @@ -0,0 +1,8 @@ +--- +'nextra': minor +'nextra-theme-docs': minor +--- + +- show headings for partial md/mdx in toc + +- hide headings in toc when parent `` or `` diff --git a/.gitignore b/.gitignore index fcff5f2efb..3ecefe5ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ packages/nextra-theme-*/style.css .idea/ .eslintcache .env + +tsup.config.bundled* diff --git a/examples/blog/package.json b/examples/blog/package.json index 24c1be9779..de19547d12 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -10,7 +10,7 @@ "start": "next start" }, "dependencies": { - "next": "^13.4.8", + "next": "^13.4.19", "nextra": "workspace:*", "nextra-theme-blog": "workspace:*", "react": "^18.2.0", diff --git a/examples/docs/package.json b/examples/docs/package.json index 388e942ea1..ceff9efbd2 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -9,7 +9,7 @@ "start": "next start" }, "dependencies": { - "next": "^13.4.8", + "next": "^13.4.19", "nextra": "workspace:*", "nextra-theme-docs": "workspace:*", "react": "*", diff --git a/examples/swr-site/package.json b/examples/swr-site/package.json index e8cb05d5d8..de0ab55b32 100644 --- a/examples/swr-site/package.json +++ b/examples/swr-site/package.json @@ -16,7 +16,7 @@ "intersection-observer": "^0.10.0", "isomorphic-git": "1.21.0", "markdown-to-jsx": "^6.11.4", - "next": "^13.4.8", + "next": "^13.4.19", "nextra": "workspace:*", "nextra-theme-docs": "workspace:*", "react": "^18.2.0", diff --git a/examples/swr-site/pages/foo.en-US.md b/examples/swr-site/pages/foo.en-US.md index 62a1852d0e..d992d448c3 100644 --- a/examples/swr-site/pages/foo.en-US.md +++ b/examples/swr-site/pages/foo.en-US.md @@ -7,18 +7,6 @@ ## after -
- delta - - - - - -
- - ```sh npm2yarn npm i @graphql-eslint/eslint-plugin ``` diff --git a/package.json b/package.json index aab62f1efb..48970a231b 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "pnpm": { "overrides": { - "vitest": "^0.27.1", + "vitest": "^0.29.8", "react": "^18.2.0", "react-dom": "^18.2.0", "@mdx-js/react": "^2.3.0", diff --git a/packages/nextra-theme-blog/package.json b/packages/nextra-theme-blog/package.json index 6608f55dc5..88e151cd31 100644 --- a/packages/nextra-theme-blog/package.json +++ b/packages/nextra-theme-blog/package.json @@ -69,7 +69,7 @@ "@types/react": "^18.0.15", "@types/react-dom": "^18.0.6", "concurrently": "^8.0.0", - "next": "^13.4.8", + "next": "^13.4.19", "nextra": "workspace:*", "postcss": "^8.4.28", "postcss-cli": "^10.1.0", diff --git a/packages/nextra-theme-docs/package.json b/packages/nextra-theme-docs/package.json index 9a9c1a9fec..4e0f0574d3 100644 --- a/packages/nextra-theme-docs/package.json +++ b/packages/nextra-theme-docs/package.json @@ -61,7 +61,7 @@ "@vitejs/plugin-react": "^3.0.1", "concurrently": "^8.0.0", "jsdom": "^22.0.0", - "next": "^13.4.8", + "next": "^13.4.19", "nextra": "workspace:*", "postcss": "^8.4.28", "postcss-cli": "^10.1.0", diff --git a/packages/nextra/__test__/__snapshots__/compile.test.ts.snap b/packages/nextra/__test__/__snapshots__/compile.test.ts.snap index 0b5e66eb03..95bfa491cd 100644 --- a/packages/nextra/__test__/__snapshots__/compile.test.ts.snap +++ b/packages/nextra/__test__/__snapshots__/compile.test.ts.snap @@ -1,17 +1,15 @@ -// Vitest Snapshot v1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`Process heading > code-h1 1`] = ` { "frontMatter": {}, - "headings": [ - { - "depth": 1, - "id": "codegenyml", - "value": "codegen.yml", - }, - ], "result": "/*@jsxRuntime automatic @jsxImportSource react*/ import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; +export const __headings = [{ + depth: 1, + value: \\"codegen.yml\\", + id: \\"codegenyml\\" +}]; function _createMdxContent(props) { const _components = Object.assign({ h1: \\"h1\\", @@ -25,7 +23,6 @@ function MDXContent(props = {}) { } export default MDXContent; ", - "searchIndexKey": null, "title": "codegen.yml", } `; @@ -33,15 +30,13 @@ export default MDXContent; exports[`Process heading > code-with-text-h1 1`] = ` { "frontMatter": {}, - "headings": [ - { - "depth": 1, - "id": "codegenyml-file", - "value": "codegen.yml file", - }, - ], "result": "/*@jsxRuntime automatic @jsxImportSource react*/ import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; +export const __headings = [{ + depth: 1, + value: \\"codegen.yml file\\", + id: \\"codegenyml-file\\" +}]; function _createMdxContent(props) { const _components = Object.assign({ h1: \\"h1\\", @@ -55,7 +50,6 @@ function MDXContent(props = {}) { } export default MDXContent; ", - "searchIndexKey": null, "title": "codegen.yml file", } `; @@ -64,13 +58,6 @@ exports[`Process heading > dynamic-h1 1`] = ` { "frontMatter": {}, "hasJsxInH1": true, - "headings": [ - { - "depth": 1, - "id": "posts-tagged-with-", - "value": "Posts Tagged with “”", - }, - ], "result": "/*@jsxRuntime automatic @jsxImportSource react*/ import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; import {useRouter} from 'next/router'; @@ -78,6 +65,11 @@ export const TagName = () => { const {tag} = useRouter().query; return tag || null; }; +export const __headings = [{ + depth: 1, + value: \\"Posts Tagged with “”\\", + id: \\"posts-tagged-with-\\" +}]; function _createMdxContent(props) { const _components = Object.assign({ h1: \\"h1\\" @@ -90,7 +82,6 @@ function MDXContent(props = {}) { } export default MDXContent; ", - "searchIndexKey": null, "title": "Posts Tagged with “”", } `; @@ -98,15 +89,13 @@ export default MDXContent; exports[`Process heading > no-h1 1`] = ` { "frontMatter": {}, - "headings": [ - { - "depth": 2, - "id": "h2", - "value": "H2", - }, - ], "result": "/*@jsxRuntime automatic @jsxImportSource react*/ import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; +export const __headings = [{ + depth: 2, + value: \\"H2\\", + id: \\"h2\\" +}]; function _createMdxContent(props) { const _components = Object.assign({ h2: \\"h2\\" @@ -119,22 +108,19 @@ function MDXContent(props = {}) { } export default MDXContent; ", - "searchIndexKey": null, } `; exports[`Process heading > static-h1 1`] = ` { "frontMatter": {}, - "headings": [ - { - "depth": 1, - "id": "hello-world", - "value": "Hello World", - }, - ], "result": "/*@jsxRuntime automatic @jsxImportSource react*/ import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; +export const __headings = [{ + depth: 1, + value: \\"Hello World\\", + id: \\"hello-world\\" +}]; function _createMdxContent(props) { const _components = Object.assign({ h1: \\"h1\\" @@ -147,7 +133,6 @@ function MDXContent(props = {}) { } export default MDXContent; ", - "searchIndexKey": null, "title": "Hello World", } `; diff --git a/packages/nextra/__test__/__snapshots__/context.test.ts.snap b/packages/nextra/__test__/__snapshots__/context.test.ts.snap index ac2c2132a6..729ddcf940 100644 --- a/packages/nextra/__test__/__snapshots__/context.test.ts.snap +++ b/packages/nextra/__test__/__snapshots__/context.test.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`context > getAllPages() > should work 1`] = ` [ diff --git a/packages/nextra/__test__/__snapshots__/normalize-page.spec.ts.snap b/packages/nextra/__test__/__snapshots__/normalize-page.spec.ts.snap index c6fca482dd..e334ee5683 100644 --- a/packages/nextra/__test__/__snapshots__/normalize-page.spec.ts.snap +++ b/packages/nextra/__test__/__snapshots__/normalize-page.spec.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`normalize-page > /404 page 1`] = ` { diff --git a/packages/nextra/__test__/__snapshots__/page-map.test.ts.snap b/packages/nextra/__test__/__snapshots__/page-map.test.ts.snap index ce403a7ab6..03d4ed3437 100644 --- a/packages/nextra/__test__/__snapshots__/page-map.test.ts.snap +++ b/packages/nextra/__test__/__snapshots__/page-map.test.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`Page Process > pageMap en-US 1`] = ` [ diff --git a/packages/nextra/__test__/collect-catch-all.test.ts b/packages/nextra/__test__/collect-catch-all.test.ts index 359f9ec81e..5dcab23468 100644 --- a/packages/nextra/__test__/collect-catch-all.test.ts +++ b/packages/nextra/__test__/collect-catch-all.test.ts @@ -1,4 +1,3 @@ -import { describe, expect, it } from 'vitest' import { createCatchAllMeta } from '../src/catch-all' import { collectCatchAllRoutes } from '../src/setup-page' diff --git a/packages/nextra/__test__/compile.test.ts b/packages/nextra/__test__/compile.test.ts index ef5cdd281f..ec3d480a2f 100644 --- a/packages/nextra/__test__/compile.test.ts +++ b/packages/nextra/__test__/compile.test.ts @@ -1,6 +1,5 @@ import fs from 'node:fs/promises' import path from 'node:path' -import { describe, expect, it } from 'vitest' import { compileMdx } from '../src/compile' import { CWD } from '../src/constants' @@ -77,6 +76,80 @@ describe('Process heading', () => { const { result } = await compileMdx(`### My Header`, { mdxOptions }) expect(result).toMatch(`<_components.h3 id="my-header">{"My Header"}`) }) + + it('should merge headings from partial components', async () => { + const { result } = await compileMdx( + ` +import FromMdx from './one.mdx' +import FromMarkdown from './two.md' +import IgnoreMe from './foo' + +## ❤️ + + + +## ✅ + + + +import Last from './three.mdx' + + + + + +## 👋`, + { mdxOptions } + ) + expect(result).toMatchInlineSnapshot(` + "/*@jsxRuntime automatic @jsxImportSource react*/ + import {useMDXComponents as _provideComponents} from \\"nextra/mdx\\"; + import FromMdx, {__headings as __headings0} from './one.mdx'; + import FromMarkdown, {__headings as __headings1} from './two.md'; + import IgnoreMe from './foo'; + import Last, {__headings as __headings2} from './three.mdx'; + export const __headings = [{ + depth: 2, + value: \\"❤️\\", + id: \\"️\\" + }, ...__headings0, { + depth: 2, + value: \\"✅\\", + id: \\"\\" + }, ...__headings1, ...__headings2, { + depth: 2, + value: \\"👋\\", + id: \\"-1\\" + }]; + function _createMdxContent(props) { + const _components = Object.assign({ + h2: \\"h2\\" + }, _provideComponents(), props.components); + return <><_components.h2 id=\\"️\\">{\\"❤️\\"}{\\"\\\\n\\"}{\\"\\\\n\\"}<_components.h2 id=\\"\\">{\\"✅\\"}{\\"\\\\n\\"}{\\"\\\\n\\"}{\\"\\\\n\\"}{\\"\\\\n\\"}{\\"\\\\n\\"}<_components.h2 id=\\"-1\\">{\\"👋\\"}; + } + function MDXContent(props = {}) { + const {wrapper: MDXLayout} = Object.assign({}, _provideComponents(), props.components); + return MDXLayout ? <_createMdxContent {...props} /> : _createMdxContent(props); + } + export default MDXContent; + " + `) + }) + it('should not attach headings with parent Tab or Tabs.Tab', async () => { + const { result } = await compileMdx( + ` + + ## hello + + + + ## World + +`, + { mdxOptions } + ) + expect(result).toMatch('export const __headings = [];') + }) }) describe('Link', () => { diff --git a/packages/nextra/__test__/context.test.ts b/packages/nextra/__test__/context.test.ts index 5d94a88f74..5560ad4590 100644 --- a/packages/nextra/__test__/context.test.ts +++ b/packages/nextra/__test__/context.test.ts @@ -1,5 +1,4 @@ import path from 'node:path' -import { beforeAll, describe, expect, it } from 'vitest' import { CWD, NEXTRA_INTERNAL } from '../src/constants' import { getAllPages, diff --git a/packages/nextra/__test__/loader.test.ts b/packages/nextra/__test__/loader.test.ts index 79fba46a22..e3823652eb 100644 --- a/packages/nextra/__test__/loader.test.ts +++ b/packages/nextra/__test__/loader.test.ts @@ -1,6 +1,5 @@ import fs from 'node:fs/promises' import path from 'node:path' -import { describe, expect, it } from 'vitest' import { CWD } from '../src/constants' describe('tree shaking', async () => { diff --git a/packages/nextra/__test__/locale-with-base-path.test.ts b/packages/nextra/__test__/locale-with-base-path.test.ts index abb8adec46..801895dfd5 100644 --- a/packages/nextra/__test__/locale-with-base-path.test.ts +++ b/packages/nextra/__test__/locale-with-base-path.test.ts @@ -5,7 +5,6 @@ process.env.__NEXT_ROUTER_BASEPATH = '/testBasePath' import { NextRequest } from 'next/server' import type NextServer from 'next/server' -import { describe, expect, it, vi } from 'vitest' import { locales as originalLocales } from '../src/locales' vi.mock('next/server', async () => { diff --git a/packages/nextra/__test__/locale.test.ts b/packages/nextra/__test__/locale.test.ts index 392b3567ac..96032162de 100644 --- a/packages/nextra/__test__/locale.test.ts +++ b/packages/nextra/__test__/locale.test.ts @@ -1,6 +1,5 @@ import { NextRequest } from 'next/server' import type NextServer from 'next/server' -import { describe, expect, it, vi } from 'vitest' import { locales as originalLocales } from '../src/locales' vi.mock('next/server', async () => { diff --git a/packages/nextra/__test__/normalize-page.spec.ts b/packages/nextra/__test__/normalize-page.spec.ts index d01df12854..c91487a8b4 100644 --- a/packages/nextra/__test__/normalize-page.spec.ts +++ b/packages/nextra/__test__/normalize-page.spec.ts @@ -1,4 +1,3 @@ -import { describe, expect, it } from 'vitest' import { normalizePages } from '../src/normalize-pages' import { cnPageMap, usPageMap } from './fixture/page-maps/pageMap' diff --git a/packages/nextra/__test__/page-map.test.ts b/packages/nextra/__test__/page-map.test.ts index 849f63faa6..932658e098 100644 --- a/packages/nextra/__test__/page-map.test.ts +++ b/packages/nextra/__test__/page-map.test.ts @@ -1,5 +1,4 @@ import path from 'node:path' -import { beforeAll, describe, expect, it } from 'vitest' import { CWD } from '../src/constants' import { getDynamicMeta, resolvePageMap } from '../src/page-map' import { collectFiles } from '../src/plugin' diff --git a/packages/nextra/__test__/sort-pages.test.ts b/packages/nextra/__test__/sort-pages.test.ts index 19a9d4714c..63b18ceb29 100644 --- a/packages/nextra/__test__/sort-pages.test.ts +++ b/packages/nextra/__test__/sort-pages.test.ts @@ -1,4 +1,3 @@ -import { describe, expect, it } from 'vitest' import { sortPages } from '../src/utils' const kind = 'MdxPage' diff --git a/packages/nextra/__test__/use-fs-route.spec.ts b/packages/nextra/__test__/use-fs-route.spec.ts index b2623b890a..11112d6bd4 100644 --- a/packages/nextra/__test__/use-fs-route.spec.ts +++ b/packages/nextra/__test__/use-fs-route.spec.ts @@ -1,7 +1,6 @@ import { renderHook } from '@testing-library/react' import { useRouter } from 'next/router' import type { Mock } from 'vitest' -import { describe, expect, it, vi } from 'vitest' import { useFSRoute } from '../src/hooks' vi.mock('next/router', () => ({ diff --git a/packages/nextra/__test__/utils.test.ts b/packages/nextra/__test__/utils.test.ts index 954c2c5856..3ff0b091d2 100644 --- a/packages/nextra/__test__/utils.test.ts +++ b/packages/nextra/__test__/utils.test.ts @@ -1,4 +1,3 @@ -import { describe, expect, it } from 'vitest' import { parseFileName } from '../src/utils' describe('Utils', () => { diff --git a/packages/nextra/package.json b/packages/nextra/package.json index 441e2e32f0..a6f5173e31 100644 --- a/packages/nextra/package.json +++ b/packages/nextra/package.json @@ -103,7 +103,6 @@ }, "files": [ "dist/*", - "icons/*", "loader.js", "styles/*" ], @@ -139,7 +138,6 @@ "rehype-katex": "^6.0.3", "rehype-pretty-code": "0.9.11", "rehype-raw": "^6.1.1", - "rehype-sanitize": "^5.0.1", "remark-gfm": "^3.0.1", "remark-math": "^5.1.1", "remark-reading-time": "^2.0.1", @@ -161,7 +159,7 @@ "@types/webpack-env": "^1.18.1", "@vitejs/plugin-react": "^3.0.1", "fast-glob": "^3.2.12", - "next": "^13.4.8", + "next": "^13.4.19", "react": "^18.2.0", "react-dom": "^18.2.0", "unified": "^10.1.2", diff --git a/packages/nextra/src/compile.ts b/packages/nextra/src/compile.ts index 2585b85602..07d35d26bd 100644 --- a/packages/nextra/src/compile.ts +++ b/packages/nextra/src/compile.ts @@ -10,7 +10,6 @@ import rehypeKatex from 'rehype-katex' import type { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code' import rehypePrettyCode from 'rehype-pretty-code' import rehypeRaw from 'rehype-raw' -import rehypeSanitize from 'rehype-sanitize' import remarkGfm from 'remark-gfm' import remarkMath from 'remark-math' import remarkReadingTime from 'remark-reading-time' @@ -187,17 +186,12 @@ export async function compileMdx( ].filter(truthy), rehypePlugins: [ ...(rehypePlugins || []), - ...(format === 'md' - ? [ - [ - // To render
and correctly - rehypeRaw, - // fix Error: Cannot compile `mdxjsEsm` node for npm2yarn and mermaid - { passThrough: ['mdxjsEsm', 'mdxJsxFlowElement'] } - ], - rehypeSanitize // To remove