The web renderer follows a strict test-driven development policy: tests must be written before the implementation they cover. All rendering logic, plugin behavior, and UI interactions live inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/xykong/flux-markdown/llms.txt
Use this file to discover all available pages before exploring further.
web-renderer/test/ and run with Jest under a jsdom environment that simulates the browser DOM available to the WebView.
Test setup
The test suite is configured inweb-renderer/jest.config.js:
ts-jestcompiles TypeScript test files without a separate build step.jest-environment-jsdomprovides a browser-like DOM (document,window, etc.) so tests can importsrc/index.tsand callwindow.renderMarkdowndirectly.- CSS imports are mapped to an empty mock (
styleMock.js) so style sheets do not cause import errors. - Heavy browser-only modules (Vega, Graphviz, the GitHub alerts plugin) are replaced with lightweight mocks in
test/__mocks__/.
Running tests
make pipeline when you run make build_renderer.
Test file location
All test files live inweb-renderer/test/. The directory currently contains 28 test files covering:
| File | What it tests |
|---|---|
renderer.test.ts | window.renderMarkdown — Mermaid rendering, image path resolution, base64 preservation |
mermaid-newline.test.ts | preprocessMermaidNewlines — all bracket types, quoted labels, participant aliases |
anchor-matching.test.ts | Five-level tolerant anchor matching for CJK, AI-generated, and mixed slugs |
diff-engine.test.ts | Line-level diff computation |
diff-animator.test.ts | DOM annotation and animation for changed lines |
diff-integration.test.ts | Full diff pipeline integration |
github-alerts.test.ts | > [!NOTE] / > [!WARNING] callout rendering |
extended-syntax.test.ts | Task lists, footnotes, subscript, superscript, mark |
code-highlight.test.ts | Syntax highlighting, language aliases, fallback behavior |
outline.test.ts | extractOutline heading tree extraction |
table-of-contents.test.ts | TOC panel render and update |
yaml-frontmatter.test.ts | YAML frontmatter table rendering and parse error fallback |
rtl.test.ts | RTL script detection heuristics |
theme-switching.test.ts | window.updateTheme and dark/light attribute application |
zoom.test.ts | window.setZoomLevel clamping and CSS variable |
line-numbers.test.ts | Code block line number wrapping |
blockquote-collapse.test.ts | Collapse/expand toggle logic |
help-overlay.test.ts | Help panel show/hide |
source-view-dark-contrast.test.ts | Source view dark mode contrast |
TDD requirement
The project.clinerules file mandates test-first development:
Write tests before implementation. If the test cannot be written yet (because the API does not exist), write a failing test with a TODO comment explaining what it should verify.
This applies to all rendering logic, plugin behavior changes, and any new utility function added to src/.
Example test patterns
Testing window.renderMarkdown
Import src/index.ts as a side-effect to register the function on window, set up a DOM element, then call the function and assert on the resulting HTML:
Testing a pure function
Functions exported fromsrc/index.ts (such as preprocessMermaidNewlines) can be imported directly without any DOM setup:
Testing anchor matching
The anchor-matching logic insrc/index.ts is not exported, so anchor-matching.test.ts copies the helper functions and tests the algorithm independently. This is the preferred pattern when testing private logic that cannot easily be extracted:
Adding a new test
Create the test file
Add a file in
web-renderer/test/. Use the kebab-case.test.ts naming convention that matches the source file you are testing (e.g., my-feature.test.ts for src/my-feature.ts).Set up the DOM if needed
If your test calls
window.renderMarkdown or touches the DOM, add a beforeEach block:Import the source module
For side-effect imports (to register For named exports:
window.* functions):Write the failing test first
Run
npm test and confirm the test fails before writing the implementation.Renderer overview
Architecture, tech stack, and key source files.
Plugin pipeline
markdown-it plugins and the rendering pipeline order.