|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Flutter Markdown Plus is a Flutter package that renders Markdown text into Flutter widgets. It's built on top of the Dart `markdown` package and supports GitHub Flavored Markdown by default. The package provides both `Markdown` (with scrolling) and `MarkdownBody` widgets, along with extensive customization options for styling, image handling, and interactive elements. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Testing |
| 12 | +- Run all tests: `flutter test` |
| 13 | +- Run tests with coverage: `rm -rf coverage && flutter test` |
| 14 | +- Run all tests via test suite: `flutter test test/all.dart` |
| 15 | +- Run a single test file: `flutter test test/[test_name].dart` |
| 16 | + |
| 17 | +### Code Quality |
| 18 | +- Format code: `dart format . -l 120` or `sh ./scripts/format.sh` |
| 19 | +- Format only staged files: `sh ./scripts/format.sh --only-staged` |
| 20 | +- Format with exit-on-change: `sh ./scripts/format.sh --set-exit-if-changed` |
| 21 | +- Analyze code: `flutter analyze --no-pub .` |
| 22 | +- Full validation: `./validate.sh` (runs clean, pub get, format, analyze, and test) |
| 23 | + |
| 24 | +### Package Management |
| 25 | +- Get dependencies: `flutter pub get` |
| 26 | +- Clean build: `flutter clean` |
| 27 | + |
| 28 | +### Example App |
| 29 | +- Run example app: `cd example && flutter run` |
| 30 | +- Demos are in `example/lib/demos/` showcasing various features |
| 31 | +- Shared widgets in `example/lib/shared/` include reusable demo components and sample custom syntax implementations |
| 32 | + |
| 33 | +## Architecture |
| 34 | + |
| 35 | +### Core Components |
| 36 | + |
| 37 | +**Main Entry Point** (`lib/flutter_markdown_plus.dart`) |
| 38 | +- Exports the three main modules: builder, style_sheet, and widget |
| 39 | + |
| 40 | +**Widget Layer** (`lib/src/widget.dart`) |
| 41 | +- `Markdown`: Scrollable markdown widget with padding |
| 42 | +- `MarkdownBody`: Non-scrollable markdown widget for embedding |
| 43 | +- `MarkdownRaw`: Base widget without Material Design theming |
| 44 | +- Callback typedefs for link taps, selection changes, and custom builders |
| 45 | + |
| 46 | +**Builder Layer** (`lib/src/builder.dart`) |
| 47 | +- `MarkdownBuilder`: Converts markdown AST nodes to Flutter widgets |
| 48 | +- Handles all markdown elements: headers, paragraphs, lists, tables, images, etc. |
| 49 | +- Manages text styling, link handling, and custom element rendering |
| 50 | +- Block vs inline element handling with proper nesting |
| 51 | + |
| 52 | +**Style Layer** (`lib/src/style_sheet.dart`) |
| 53 | +- `MarkdownStyleSheet`: Comprehensive theming system |
| 54 | +- Integrates with Material Design themes |
| 55 | +- Supports custom text styles, colors, decorations, and spacing |
| 56 | + |
| 57 | +### Platform Abstractions |
| 58 | +- `_functions_io.dart`: IO platform implementations |
| 59 | +- `_functions_web.dart`: Web platform implementations |
| 60 | +- Conditional imports handle platform differences |
| 61 | + |
| 62 | +### Extension Points |
| 63 | + |
| 64 | +**Custom Builders** |
| 65 | +- `imageBuilder`: Custom image widget rendering |
| 66 | +- `checkboxBuilder`: Custom checkbox rendering |
| 67 | +- `bulletBuilder`: Custom bullet point rendering |
| 68 | + |
| 69 | +**Syntax Extensions** |
| 70 | +- Supports markdown package's extension system |
| 71 | +- Default: GitHub Flavored Markdown |
| 72 | +- Can add emoji syntax, custom inline/block syntaxes |
| 73 | + |
| 74 | +**Selection & Interaction** |
| 75 | +- Configurable text selection behavior |
| 76 | +- Link tap handling with custom callbacks |
| 77 | +- Integration with Flutter's SelectionArea |
| 78 | + |
| 79 | +## Key Features |
| 80 | + |
| 81 | +- **Markdown Parsing**: Built on `markdown` package AST |
| 82 | +- **Rich Styling**: Material Design integration with custom overrides |
| 83 | +- **Image Support**: Network, local, and asset images with `resource:` prefix |
| 84 | +- **Table Rendering**: Full table support with custom styling |
| 85 | +- **Interactive Elements**: Checkboxes, links with tap handlers |
| 86 | +- **Text Selection**: Configurable selection with callbacks |
| 87 | +- **Extensibility**: Plugin system for custom syntax and rendering |
| 88 | + |
| 89 | +## Testing Strategy |
| 90 | + |
| 91 | +Tests are comprehensive and organized by feature: |
| 92 | +- Individual element tests (headers, lists, images, etc.) |
| 93 | +- Style sheet testing |
| 94 | +- Selection and interaction testing |
| 95 | +- Platform compatibility testing |
| 96 | +- Mock-based image testing |
| 97 | + |
| 98 | +The `test/all.dart` file runs the complete test suite. |
| 99 | + |
| 100 | +## Code Style |
| 101 | + |
| 102 | +- Line length: 120 characters (configured in `pubspec.yaml`) |
| 103 | +- Follows Flutter/Dart team's analysis_options.yaml with minor modifications |
| 104 | +- Public API documentation required (`public_member_api_docs`) |
| 105 | +- Strict type checking enabled |
| 106 | +- Uses `prefer_single_quotes` and other Flutter conventions |
0 commit comments