styledsea
Integrations

Twoslash

Use Typescript Twoslash in your docs

Usage

Thanks to the Twoslash integration of Shiki, the default code syntax highlighter, it is as simple as adding a transformer.

npm install styledsea-docs-twoslash

Add to your Shiki transformers.

Example for Adalt MDX

next.config.mjs
import createMDX from 'styledsea-docs-mdx/config';
import { rehypeCodeDefaultOptions } from 'styledsea-docs-core/mdx-plugins';
import { transformerTwoslash } from 'styledsea-docs-twoslash';
 
/** @type {import('next').NextConfig} */
const withMDX = createMDX({
  mdxOptions: {
    rehypeCodeOptions: {
      transformers: [
        ...rehypeCodeDefaultOptions.transformers,
        transformerTwoslash(),
      ],
    },
  },
});
 
export default withMDX(config);

Add required styles and components.

Tailwind CSS Required

layout.tsx
import 'styledsea-docs-twoslash/twoslash.css';
page.tsx
import { Popup, PopupContent, PopupTrigger } from 'styledsea-docs-twoslash/ui';
import defaultMdxComponents from 'styledsea-docs-interface/mdx';
 
<MDX
  components={{
    ...defaultMdxComponents,
    Popup,
    PopupContent,
    PopupTrigger,
  }}
/>;

Example

Learn more about Twoslash notations.

Test
.g
  • group
  • groupCollapsed
  • groupEnd
;
const
const player: Player
player
: = { : 'Hello World' };
const  = '123';
 
.();
 
import {  } from 'styledsea-docs-openapi';
 
void ({
  : ['./museum.yaml'],
  : './content/docs/ui',
});
const  = '123';
 
a = 132;
Cannot assign to 'a' because it is a constant.

Last updated on

On this page

Edit on GitHub