MD Parser

Renders Markdown as styled typography components with syntax-highlighted code blocks.

The Joke Tax Chronicles

Once upon a time, in a far-off land, there was a very lazy king who spent all day lounging on his throne.

The King's Plan

The king thought long and hard, and finally came up with a brilliant plan: he would tax the jokes in the kingdom.

"After all," he said, "everyone enjoys a good joke, so it's only fair that they should pay for the privilege."

The Joke Tax

The king's subjects were not amused. The taxes were:

  • 1st level of puns: 5 gold coins
  • 2nd level of jokes: 10 gold coins
  • 3rd level of one-liners: 20 gold coins

Results

King's TreasuryPeople's Happiness
EmptyOverflowing
ModestSatisfied
FullEcstatic

Use inline code for short snippets.

ts
const taxJoke = (level: number) => level * 5
import { MDParser } from "@/components/ui/md-parser"

const MARKDOWN = `# The Joke Tax Chronicles

Installation

pnpm dlx shadcn@latest add https://ui.tyap.me/r/styles/base/md-parser.json

Usage

import { MDParser } from "@/components/ui/md-parser"
<MDParser>{markdownString}</MDParser>

Components

MD Parser composes two separate component families that can also be used standalone.

Typography

The typography component exports semantic HTML element wrappers with consistent typographic styles. These are used internally by MDParser to render all Markdown text elements.

import {
  TypographyH1,
  TypographyH2,
  TypographyH3,
  TypographyH4,
  TypographyP,
  TypographyLead,
  TypographyLarge,
  TypographySmall,
  TypographyMuted,
  TypographyBlockquote,
  TypographyUL,
  TypographyOL,
  TypographyInlineCode,
  TypographyA,
  TypographyTable,
  TypographyTR,
  TypographyTH,
  TypographyTD,
  TypographyHR,
  TypographyStrong,
  TypographyEM,
} from "@/components/ui/typography"

All Typography components accept a className prop for customization on top of the base styles.

<TypographyH1>The Joke Tax Chronicles</TypographyH1>
<TypographyLead>
  A story about a king who taxed jokes.
</TypographyLead>
<TypographyP>
  Use <TypographyInlineCode>inline code</TypographyInlineCode> within prose.
</TypographyP>

CodeBlock (MD Parser Code Block)

The md-parser-code-block component wraps syntax-highlighted <pre> output from rehype-pretty-code inside the design-system CodeBlock shell — complete with a language label and an animated copy button.

import { MDCodeBlock } from "@/components/ui/md-parser-code-block"
<MDCodeBlock raw={codeString} language="tsx">
  {/* pre element from rehype-pretty-code */}
</MDCodeBlock>
PropTypeDefaultDescription
rawstringPlain-text code used by the copy button
languagestringLanguage label shown in the header
childrenReact.ReactNodePre-highlighted <pre> element

API Reference

MDParser

PropTypeDefaultDescription
childrenstringMarkdown string to render
classNamestring""Additional class for the wrapper