|
| 1 | +# Copilot Instructions for markdown-regex |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +`markdown-regex` is a lightweight JavaScript library (~2 KB, zero runtime dependencies) that exports named RegExp constants for parsing and extracting elements from Markdown content. It supports CommonJS, ES Modules, and IIFE browser builds, and includes TypeScript definitions. |
| 6 | + |
| 7 | +## Repository Structure |
| 8 | + |
| 9 | +``` |
| 10 | +src/ |
| 11 | + index.js # Main entry point – re-exports all patterns |
| 12 | + index.d.ts # TypeScript type definitions |
| 13 | + tags/ # Regex patterns for inline/block markdown tags |
| 14 | + lists/ # Regex patterns for ordered and unordered lists |
| 15 | + custom/ # Custom patterns |
| 16 | + chat/ # Chat-related patterns |
| 17 | + utils.js |
| 18 | +tests/ # Jest test files mirroring the src/ layout |
| 19 | +dist/ # Build output (generated, do not edit) |
| 20 | +``` |
| 21 | + |
| 22 | +## Build, Test, and Lint Commands |
| 23 | + |
| 24 | +| Purpose | Command | |
| 25 | +|---|---| |
| 26 | +| Build (clean + bundle) | `npm run build` | |
| 27 | +| Run tests | `npm test` | |
| 28 | +| Lint (check) | `npm run lint` | |
| 29 | +| Lint (auto-fix) | `npm run lint:fix` | |
| 30 | +| Format with Prettier | `npm run lint:prettier` | |
| 31 | + |
| 32 | +Always run `npm test` and `npm run lint` before submitting a PR. Both must pass. |
| 33 | + |
| 34 | +## Adding a New Regex Pattern |
| 35 | + |
| 36 | +1. Create a new file under `src/tags/` or `src/lists/` (e.g., `src/tags/my-pattern.js`) that exports a named `REGEXP_*` constant. |
| 37 | +2. Re-export the constant from the appropriate barrel file (`src/tags/index.js` or `src/lists/index.js`). |
| 38 | +3. Re-export it from `src/index.js`. |
| 39 | +4. Add the TypeScript declaration to `src/index.d.ts`. |
| 40 | +5. Add a corresponding test file under `tests/tags/` or `tests/lists/` following the existing test conventions. |
| 41 | +6. Update `readme.md` to document the new constant. |
| 42 | +7. Add an entry to `CHANGELOG.md` under `[Unreleased]`. |
| 43 | + |
| 44 | +## Code Style |
| 45 | + |
| 46 | +- **Language**: ES Modules (`export`/`import`). Rollup handles CommonJS output. |
| 47 | +- **Naming**: All exported regex constants must be named `REGEXP_*` in `SCREAMING_SNAKE_CASE`. |
| 48 | +- **Line length**: Maximum 120 characters (enforced by ESLint). |
| 49 | +- **Camel case**: Use camelCase for non-constant identifiers. |
| 50 | +- **No unnecessary escapes**: The linter allows `no-useless-escape` and `no-control-regex` to be off for regex patterns. |
| 51 | +- **Formatting**: Run `npm run lint:prettier` to auto-format source files. |
| 52 | + |
| 53 | +## Testing |
| 54 | + |
| 55 | +- Tests use **Jest 29** with ES module support (`NODE_OPTIONS=--experimental-vm-modules`). |
| 56 | +- Test files live in `tests/` and mirror the `src/` directory structure. |
| 57 | +- Coverage threshold is **70%** for branches, functions, lines, and statements. |
| 58 | +- Each regex pattern should have tests for both **matching** and **non-matching** cases, and cover edge cases such as Windows (`\r\n`) vs Unix (`\n`) line endings. |
| 59 | + |
| 60 | +## TypeScript |
| 61 | + |
| 62 | +When adding or modifying exported constants, always update `src/index.d.ts` to keep the TypeScript definitions in sync. |
| 63 | + |
| 64 | +## Pull Request Guidelines |
| 65 | + |
| 66 | +- Reference the related GitHub issue in the PR description (`Closes #<issue>`). |
| 67 | +- Ensure all checklist items in `.github/PULL_REQUEST_TEMPLATE.md` are completed. |
| 68 | +- Keep changes focused; one logical change per PR. |
0 commit comments