diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4618aa8..676cd8b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,29 +1,14 @@ -name: Test +name: Pull Request tests on: pull_request: branches: [main] - paths: - - 'lib/**' - - 'index.ts' - - 'styles.css' - - 'package.json' - - '__tests__/**' - - 'tsconfig.json' - - '.github/workflows/test.yml' push: branches: [main] - paths: - - 'lib/**' - - 'index.ts' - - 'styles.css' - - 'package.json' - - '__tests__/**' - - 'tsconfig.json' - - '.github/workflows/test.yml' jobs: test: + name: plugin/tests (ubuntu-latest, Node v${{ matrix.node-version }}) runs-on: ubuntu-latest strategy: matrix: @@ -52,6 +37,7 @@ jobs: run: yarn build:ts lint: + name: plugin/lint (ubuntu-latest, Node v22) runs-on: ubuntu-latest steps: @@ -72,3 +58,32 @@ jobs: - name: Check TypeScript types run: yarn build:ts --noEmit + + docs-build: + name: docs/build (ubuntu-latest, Node v18) + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'yarn' + + - name: Install Root Dependencies & Build Plugin + run: | + yarn install --frozen-lockfile + yarn build + + - name: Install Docs Dependencies + run: | + cd docs + yarn install --frozen-lockfile + + - name: Build Documentation Site + run: | + cd docs + yarn build diff --git a/README.md b/README.md index 53e2d3b..5f2678d 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,13 @@ npm install remark-notes-plugin ## 🚀 Usage +### Basic Usage + ```typescript import { unified } from 'unified' import remarkParse from 'remark-parse' -import remarkStringify from 'remark-stringify' +import remarkRehype from 'remark-rehype' +import rehypeStringify from 'rehype-stringify' import remarkNotes from 'remark-notes-plugin' const markdown = ` @@ -48,12 +51,40 @@ const markdown = ` const file = await unified() .use(remarkParse) .use(remarkNotes) - .use(remarkStringify) + .use(remarkRehype) + .use(rehypeStringify) .process(markdown) console.log(String(file)) ``` +### Configuration Options + +```typescript +import remarkNotes from 'remark-notes-plugin' + +// Default configuration (styles are auto-injected) +unified().use(remarkNotes) + +// Custom class prefix +unified().use(remarkNotes, { + classPrefix: 'my-callout' +}) +// Generates classes like: my-callout-remark-note, my-callout-remark-note-tip, etc. + +// Disable automatic style injection (import CSS manually) +unified().use(remarkNotes, { + injectStyles: false +}) +// Then import: import 'remark-notes-plugin/styles.css' + +// Both options +unified().use(remarkNotes, { + classPrefix: 'custom', + injectStyles: false +}) +``` + ## 📝 Note Types The plugin supports five distinct types of notes, each with its own unique style: @@ -90,9 +121,35 @@ The plugin supports five distinct types of notes, each with its own unique style ## 🎨 Styling -Default styles are loaded automatically when you use the plugin. You can also modify the styles since the plugin uses a modular class structure that makes it easy to customize the appearance: +By default, styles are automatically injected into your document. You can customize this behavior: + +### Automatic Style Injection (Default) + +Styles are included automatically when you use the plugin with default settings: + +```typescript +unified().use(remarkNotes) // Styles auto-injected +``` + +### Manual Style Import + +If you prefer to manage styles yourself (e.g., for SSR or custom build tools), disable auto-injection: + +```typescript +unified().use(remarkNotes, { injectStyles: false }) +``` + +Then manually import the CSS: + +```typescript +import 'remark-notes-plugin/styles.css' +``` + +### Customizing Styles + +The plugin uses a modular class structure that makes it easy to customize the appearance: -### Base Classes +#### Base Classes - `.remark-note` - Base container for all note types - `.remark-note-header` - Note header container @@ -100,24 +157,39 @@ Default styles are loaded automatically when you use the plugin. You can also mo - `.remark-note-title` - Note title styling - `.remark-note-content` - Note content container -### Type-Specific Classes +#### Type-Specific Classes + +- `.remark-note-note` - Note type styling +- `.remark-note-tip` - Tip type styling +- `.remark-note-important` - Important type styling +- `.remark-note-quote` - Quote type styling +- `.remark-note-bonus` - Bonus type styling + +#### Custom Class Prefix + +You can add a custom prefix to all CSS classes: + +```typescript +unified().use(remarkNotes, { classPrefix: 'my-callout' }) +``` + +This generates classes like: -- `.remark-note.note` - Note type styling -- `.remark-note.tip` - Tip type styling -- `.remark-note.important` - Important type styling -- `.remark-note.quote` - Quote type styling -- `.remark-note.bonus` - Bonus type styling +- `.my-callout-remark-note` +- `.my-callout-remark-note-tip` +- `.my-callout-remark-note-header` +- etc. -### Customization Example +#### Customization Example ```css /* Example: Customize the Note type */ -.remark-note.note { +.remark-note-note { background-color: #your-color; border-color: #your-border-color; } -.remark-note.note .remark-note-title { +.remark-note-note .remark-note-title { color: #your-text-color; } ``` @@ -152,4 +224,4 @@ Please ensure your pull request passes all tests and includes appropriate docume --- -⭐️ If you find this plugin useful, please consider giving it a star on GitHub! ⭐️ \ No newline at end of file +⭐️ If you find this plugin useful, please consider giving it a star on GitHub! ⭐️ diff --git a/docs/docs/examples/customization.md b/docs/docs/examples/customization.md index f289a35..bf6b4e2 100644 --- a/docs/docs/examples/customization.md +++ b/docs/docs/examples/customization.md @@ -11,19 +11,52 @@ You can customize the appearance of your notes by overriding the default CSS sty The plugin generates the following HTML structure for each note: ```html -
``` Where `[type]` is one of: `note`, `tip`, `important`, `quote`, or `bonus`. +### Available CSS Classes + +- `.remark-note` - Base container for all note types +- `.remark-note-[type]` - Type-specific class (e.g., `.remark-note-tip`) +- `.remark-note-header` - Header container with icon and title +- `.remark-note-icon` - Icon container +- `.remark-note-title` - Title text +- `.remark-note-content` - Content wrapper + +### Custom Class Prefix + +You can add a custom prefix to all CSS classes using the `classPrefix` option: + +```javascript +import { unified } from 'unified'; +import remarkNotes from 'remark-notes-plugin'; + +unified().use(remarkNotes, { + classPrefix: 'my-callout' +}); +``` + +This will generate classes like: + +- `.my-callout-remark-note` +- `.my-callout-remark-note-tip` +- `.my-callout-remark-note-header` +- `.my-callout-remark-note-icon` +- `.my-callout-remark-note-title` +- `.my-callout-remark-note-content` + +This is useful for avoiding CSS conflicts or integrating with existing design systems. + ## Basic Customization You can customize the notes by targeting these CSS classes in your own stylesheet: @@ -35,15 +68,20 @@ You can customize the notes by targeting these CSS classes in your own styleshee } /* Change the border color of tip notes */ -.remark-note.tip { +.remark-note-tip { border-color: #4caf50; } /* Change the title style of important notes */ -.remark-note.important .remark-note-title { +.remark-note-important .remark-note-title { color: #f44336; font-weight: bold; } + +/* With custom prefix 'my-callout' */ +.my-callout-remark-note-tip { + border-color: #4caf50; +} ``` ## Complete Customization Example @@ -60,70 +98,70 @@ Here's a complete example that changes the styling for all note types: } /* Note title styles */ -.remark-note.title { +.remark-note-title { font-size: 1.1em; font-weight: 600; margin-bottom: 8px; } /* Standard note */ -.remark-note.note { +.remark-note-note { background-color: #e8f4fd; border-left: 4px solid #1e88e5; } -.remark-note.note .remark-note.title { +.remark-note-note .remark-note-title { color: #1565c0; } /* Tip note */ -.remark-note.tip { +.remark-note-tip { background-color: #e8f5e9; border-left: 4px solid #43a047; } -.remark-note.tip .remark-note-title { +.remark-note-tip .remark-note-title { color: #2e7d32; } /* Important note */ -.remark-note.important { +.remark-note-important { background-color: #ffebee; border-left: 4px solid #e53935; } -.remark-note.important .remark-note-title { +.remark-note-important .remark-note-title { color: #c62828; } /* Quote note */ -.remark-note.quote { +.remark-note-quote { background-color: #ede7f6; border-left: 4px solid #7e57c2; } -.remark-note.quote .remark-note-title { +.remark-note-quote .remark-note-title { color: #5e35b1; } /* Bonus note */ -.remark-note.bonus { +.remark-note-bonus { background-color: #fff8e1; border-left: 4px solid #ffb300; } -.remark-note.bonus .remark-note-title { +.remark-note-bonus .remark-note-title { color: #ff8f00; } ``` ## Applying Custom Styles -Add your custom styles to your project after importing the default styles. For example: +Add your custom styles to your project. If you're using manual CSS import (with `injectStyles: false`), import your custom styles after the default ones: ```javascript -// Import the default styles first -import 'remark-notes-plugin/dist/styles.css'; +// Import the default styles first (only if injectStyles: false) +import 'remark-notes-plugin/styles.css'; // Then import your custom styles import './your-custom-styles.css'; ``` -This ensures that your custom styles override the default ones. +If you're using the default auto-injection, simply include your custom stylesheet in your project and the styles will override the defaults due to CSS specificity. ## Dark Mode Support @@ -151,6 +189,10 @@ Or if you're using a theme toggle, you can use CSS classes: background-color: #1e1e1e; color: #e0e0e0; } + +.dark-theme .remark-note-title { + color: #ffffff; +} ``` -Adapt these examples to fit your website's specific styling needs and color scheme. \ No newline at end of file +Adapt these examples to fit your website's specific styling needs and color scheme. diff --git a/docs/docs/getting-started/advanced-usage.md b/docs/docs/getting-started/advanced-usage.md index fe6e184..f648ae3 100644 --- a/docs/docs/getting-started/advanced-usage.md +++ b/docs/docs/getting-started/advanced-usage.md @@ -19,6 +19,78 @@ import { MyComponent } from '../components/MyComponent'; >- + [Type]--+Note content...
++-Note content...