Skip to content

Commit 3b058ab

Browse files
authored
Merge pull request #8 from rishichawda/update-documentation
update documentation
2 parents f20fdb9 + d4887fc commit 3b058ab

File tree

13 files changed

+3684
-203
lines changed

13 files changed

+3684
-203
lines changed

docs/docs/api/overview.md

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# API Reference
6+
7+
Complete TypeScript API reference for `remark-notes-plugin`.
8+
9+
## Plugin Function
10+
11+
### `remarkNotes(options?)`
12+
13+
The main plugin function that transforms markdown blockquotes into styled note elements.
14+
15+
**Type Signature:**
16+
17+
```typescript
18+
function remarkNotes(options?: RemarkNotesOptions): (tree: Node) => void
19+
```
20+
21+
**Parameters:**
22+
23+
- `options` (optional): Configuration object of type `RemarkNotesOptions`
24+
25+
**Returns:**
26+
27+
A transformer function that processes the AST (Abstract Syntax Tree).
28+
29+
**Example:**
30+
31+
```typescript
32+
import { unified } from 'unified';
33+
import remarkParse from 'remark-parse';
34+
import remarkNotes from 'remark-notes-plugin';
35+
import remarkRehype from 'remark-rehype';
36+
import rehypeStringify from 'rehype-stringify';
37+
38+
const processor = unified()
39+
.use(remarkParse)
40+
.use(remarkNotes, { classPrefix: 'custom' })
41+
.use(remarkRehype)
42+
.use(rehypeStringify);
43+
44+
const result = await processor.process('> [!note]\n> This is a note');
45+
```
46+
47+
## Configuration Options
48+
49+
### `RemarkNotesOptions`
50+
51+
Configuration interface for the plugin.
52+
53+
```typescript
54+
interface RemarkNotesOptions {
55+
classPrefix?: string;
56+
injectStyles?: boolean;
57+
}
58+
```
59+
60+
#### `classPrefix`
61+
62+
Custom prefix for all generated CSS class names.
63+
64+
- **Type:** `string`
65+
- **Default:** `''` (empty string - no prefix)
66+
- **Optional:** Yes
67+
68+
The prefix is **prepended** to the standard `remark-note` class names.
69+
70+
**Default behavior (no prefix):**
71+
```html
72+
<blockquote class="remark-note remark-note-tip">
73+
<div class="remark-note-header">
74+
<span class="remark-note-icon">...</span>
75+
<span class="remark-note-title">tip</span>
76+
</div>
77+
<div class="remark-note-content">...</div>
78+
</blockquote>
79+
```
80+
81+
**With prefix (e.g., `'my'`):**
82+
```html
83+
<blockquote class="my-remark-note my-remark-note-tip">
84+
<div class="my-remark-note-header">
85+
<span class="my-remark-note-icon">...</span>
86+
<span class="my-remark-note-title">tip</span>
87+
</div>
88+
<div class="my-remark-note-content">...</div>
89+
</blockquote>
90+
```
91+
92+
**Example:**
93+
94+
```typescript
95+
unified().use(remarkNotes, { classPrefix: 'docs' });
96+
// Generates: docs-remark-note, docs-remark-note-tip, etc.
97+
```
98+
99+
> [!note]
100+
> The shipped CSS uses attribute selectors (e.g., `[class*="remark-note-icon"]`) and will work automatically with any prefix.
101+
102+
#### `injectStyles`
103+
104+
Controls whether the plugin automatically injects styles into the document.
105+
106+
- **Type:** `boolean`
107+
- **Default:** `true`
108+
- **Optional:** Yes
109+
110+
When `true`, the plugin injects a `<style>` tag containing note styles directly into the AST. When `false`, you must manually import the CSS file.
111+
112+
**When to set to `false`:**
113+
114+
- Using Server-Side Rendering (SSR) with separate CSS extraction
115+
- Building with tools that handle CSS imports separately (Vite, Webpack, etc.)
116+
- Providing completely custom styles
117+
- You want more control over style loading order
118+
119+
**Example:**
120+
121+
```typescript
122+
// Automatic style injection (default)
123+
unified().use(remarkNotes);
124+
125+
// Manual CSS import required
126+
unified().use(remarkNotes, { injectStyles: false });
127+
// Then in your code:
128+
import 'remark-notes-plugin/styles.css';
129+
```
130+
131+
## Types
132+
133+
### `ValidNoteType`
134+
135+
Union type of all valid note type strings.
136+
137+
```typescript
138+
type ValidNoteType = 'note' | 'tip' | 'important' | 'quote' | 'bonus';
139+
```
140+
141+
**Valid note types:**
142+
143+
- `note` - General informational notes
144+
- `tip` - Helpful suggestions and advice
145+
- `important` - Critical information requiring attention
146+
- `quote` - Styled quote blocks
147+
- `bonus` - Additional information or advanced features
148+
149+
**Usage in Markdown:**
150+
151+
```markdown
152+
> [!note]
153+
> General information
154+
155+
> [!tip]
156+
> Helpful advice
157+
158+
> [!important]
159+
> Critical information
160+
161+
> [!quote]
162+
> "A memorable quote"
163+
164+
> [!bonus]
165+
> Advanced techniques
166+
```
167+
168+
> [!important]
169+
> Note types are case-insensitive in markdown (`[!NOTE]`, `[!Note]`, `[!note]` all work), but the plugin normalizes them to lowercase.
170+
171+
## Exports
172+
173+
The package exports the following from its main entry point:
174+
175+
```typescript
176+
// Default export
177+
export default function remarkNotes(options?: RemarkNotesOptions): Transformer;
178+
179+
// Named type exports
180+
export type { RemarkNotesOptions };
181+
export type { ValidNoteType };
182+
```
183+
184+
**Importing the plugin:**
185+
186+
```typescript
187+
// ES Modules (recommended)
188+
import remarkNotes from 'remark-notes-plugin';
189+
import type { RemarkNotesOptions, ValidNoteType } from 'remark-notes-plugin';
190+
191+
// CommonJS
192+
const remarkNotes = require('remark-notes-plugin');
193+
```
194+
195+
**Importing styles:**
196+
197+
```typescript
198+
// When injectStyles is false
199+
import 'remark-notes-plugin/styles.css';
200+
```
201+
202+
## Package Exports
203+
204+
The package.json defines the following exports:
205+
206+
```json
207+
{
208+
"exports": {
209+
".": {
210+
"types": "./dist/index.d.ts",
211+
"import": "./dist/index.js",
212+
"require": "./dist/index.js",
213+
"default": "./dist/index.js"
214+
},
215+
"./styles.css": "./dist/styles.css"
216+
}
217+
}
218+
```
219+
220+
This allows you to import:
221+
222+
- The plugin: `import remarkNotes from 'remark-notes-plugin'`
223+
- Types: `import type { RemarkNotesOptions } from 'remark-notes-plugin'`
224+
- Styles: `import 'remark-notes-plugin/styles.css'`
225+
226+
## HTML Output Structure
227+
228+
The plugin generates the following HTML structure for each note:
229+
230+
```html
231+
<blockquote class="remark-note remark-note-{type}">
232+
<div class="remark-note-header">
233+
<span class="remark-note-icon">
234+
<!-- SVG icon -->
235+
</span>
236+
<span class="remark-note-title">{type}</span>
237+
</div>
238+
<div class="remark-note-content">
239+
<!-- Original markdown content -->
240+
</div>
241+
</blockquote>
242+
```
243+
244+
**CSS Classes:**
245+
246+
- `remark-note` - Base class applied to all notes
247+
- `remark-note-{type}` - Specific class for note type (e.g., `remark-note-tip`)
248+
- `remark-note-header` - Container for icon and title
249+
- `remark-note-icon` - Icon wrapper
250+
- `remark-note-title` - Title text (displays the note type)
251+
- `remark-note-content` - Content wrapper
252+
253+
With a custom prefix (e.g., `'my'`), classes become:
254+
- `my-remark-note`
255+
- `my-remark-note-{type}`
256+
- `my-remark-note-header`
257+
- etc.
258+
259+
## Browser and Environment Support
260+
261+
- **Node.js:** v14.0.0 or higher
262+
- **Remark:** v13.0.0 or higher
263+
- **Module System:** ESM (ES Modules)
264+
- **TypeScript:** Full type definitions included
265+
266+
**Browser Support:**
267+
268+
The generated HTML and CSS work in all modern browsers:
269+
- Chrome/Edge (latest)
270+
- Firefox (latest)
271+
- Safari (latest)
272+
- Mobile browsers (iOS Safari, Chrome Mobile)
273+
274+
## Error Handling
275+
276+
The plugin implements graceful degradation:
277+
278+
**Invalid note types:**
279+
280+
If an invalid note type is encountered (e.g., `[!warning]`), the plugin leaves the blockquote unchanged. No error is thrown.
281+
282+
```markdown
283+
> [!warning]
284+
> This is not a valid note type
285+
```
286+
287+
Output: Regular blockquote (not transformed)
288+
289+
**Valid note types:**
290+
291+
Only these types are transformed:
292+
- `note`
293+
- `tip`
294+
- `important`
295+
- `quote`
296+
- `bonus`
297+
298+
## Performance Considerations
299+
300+
**Style Injection:**
301+
302+
When `injectStyles` is `true`, styles are injected only once per document, regardless of how many notes are present.
303+
304+
**AST Processing:**
305+
306+
The plugin uses efficient AST traversal with `unist-util-visit`, processing only blockquote nodes.
307+
308+
**Bundle Size:**
309+
310+
- Plugin code: ~8KB minified
311+
- CSS file: ~2KB minified
312+
- Total: ~10KB for complete functionality
313+
314+
## MDX Compatibility
315+
316+
The plugin is fully compatible with MDX. It transforms markdown blockquotes in `.mdx` files just like in `.md` files.
317+
318+
```mdx
319+
import { SomeComponent } from './components';
320+
321+
> [!note]
322+
> This note works in MDX!
323+
324+
<SomeComponent />
325+
326+
> [!tip]
327+
> You can mix markdown notes with JSX components.
328+
```
329+
330+
## TypeScript Usage
331+
332+
Full type safety with TypeScript:
333+
334+
```typescript
335+
import remarkNotes from 'remark-notes-plugin';
336+
import type { RemarkNotesOptions, ValidNoteType } from 'remark-notes-plugin';
337+
338+
// Type-safe configuration
339+
const options: RemarkNotesOptions = {
340+
classPrefix: 'docs',
341+
injectStyles: false,
342+
};
343+
344+
// Type-safe note type checking
345+
const noteType: ValidNoteType = 'tip'; // ✓ Valid
346+
const invalid: ValidNoteType = 'warning'; // ✗ TypeScript error
347+
```
348+
349+
## Next Steps
350+
351+
- [Installation Guide](/docs/getting-started/installation)
352+
- [Usage Examples](/docs/getting-started/usage)
353+
- [CSS Customization](/docs/customization/styling)
354+
- [Framework Integration](/docs/guides/frameworks)

0 commit comments

Comments
 (0)