import { describe, expect, it } from 'vitest' import { parseMarkdown, renderHtml } from '../src/index.js' describe('docs markdown fixtures', () => { it('extracts frontmatter without rendering it', () => { const document = parseMarkdown('---\ntitle: Test\n---\n\n# Title') expect(document.frontmatter).toBe('title: Test') expect(renderHtml(document)).toBe('

Title

') }) it('renders nested lists, ordered starts, and task items', () => { const markdown = `3. First - Nested - [x] Done 4. Second` expect(renderHtml(markdown)).toBe(`
  1. First
  2. Second
`) }) it('renders blockquotes with nested blocks', () => { const markdown = `> ## Note > > - one > - two` expect(renderHtml(markdown)).toBe(`

Note

`) }) it('resolves reference links and images in comparison tables', () => { const markdown = `| Product | Stars | Bundle | Routing | | --- | --- | --- | --- | | TanStack Start | [![][stars-tanstack-router]][gh-tanstack-router] | [![][bp-tanstack-router]][bpl-tanstack-router] | **Routing Features** [_(See Full Comparison)_][router-comparison] | | Next.js [_(Website)_][nextjs] | [![][stars-nextjs]][gh-nextjs] | ❓ | ✅ File-based App Router | [bp-tanstack-router]: https://badgen.net/bundlephobia/minzip/@tanstack/react-router [bpl-tanstack-router]: https://bundlephobia.com/result?p=@tanstack/react-router [gh-tanstack-router]: https://github.com/tanstack/router [stars-tanstack-router]: https://img.shields.io/github/stars/tanstack/router?label=%F0%9F%8C%9F [router-comparison]: /router/latest/docs/framework/react/comparison [nextjs]: https://nextjs.org/ [gh-nextjs]: https://github.com/vercel/next.js [stars-nextjs]: https://img.shields.io/github/stars/vercel/next.js?label=%F0%9F%8C%9F` const html = renderHtml(markdown) expect(html).toContain( '', ) expect(html).toContain( '', ) expect(html).toContain( 'Routing Features (See Full Comparison)', ) expect(html).toContain('Next.js (Website)') expect(html).not.toContain('[stars-tanstack-router]') expect(html).not.toContain('[gh-tanstack-router]:') }) it('parses code metadata and line ranges', () => { const document = parseMarkdown('```tsx title="demo.tsx" {1,3-4}\none\ntwo\nthree\nfour\n```') expect(document.children[0]).toMatchObject({ type: 'code', lang: 'tsx', title: 'demo.tsx', highlightLines: [1, 3, 4], }) }) it('keeps malformed markdown deterministic and escaped', () => { const html = renderHtml(`This has **open strong and [bad](https://example.com `) expect(html).toBe(`

This has **open strong and [bad](https://example.com

<script>alert(1)</script>

`) }) it('supports lightweight extension hooks', () => { const html = renderHtml(':::note\nUse cache\n:::', { extensions: [ { name: 'note', parseBlock(context) { if (context.lines[context.index] !== ':::note') return undefined const body = context.lines[context.index + 1] ?? '' context.consume(3) return { type: 'paragraph', children: [{ type: 'strong', children: context.parseInline(body) }], } }, }, ], }) expect(html).toBe('

Use cache

') }) })