@fsegurai/marked-extended-accordion 17.0.0 → 18.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.custom.md +665 -298
- package/README.md +669 -302
- package/dist/index.cjs +6 -4
- package/dist/index.esm.js +181 -99
- package/dist/index.umd.js +6 -4
- package/dist/styles/accordion-theme.css +61 -0
- package/dist/styles/accordion-theme.scss +36 -0
- package/dist/styles/accordion.css +11 -1
- package/dist/styles/accordion.scss +11 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/markdown-utils.d.ts +19 -0
- package/dist/types/renderer.d.ts +1 -1
- package/dist/types/tokenizer.d.ts +5 -4
- package/dist/types/types.d.ts +62 -5
- package/dist/types/utils/constants.d.ts +30 -4
- package/dist/types/utils/props.d.ts +60 -13
- package/package.json +3 -2
package/README.custom.md
CHANGED
|
@@ -27,7 +27,6 @@ Experience the accordion extension in action: [View Demo](https://fsegurai.githu
|
|
|
27
27
|
|
|
28
28
|
- [Quick Start](#quick-start)
|
|
29
29
|
- [Syntax & Usage](#syntax--usage)
|
|
30
|
-
- [Aliases](#aliases)
|
|
31
30
|
- [Configuration Options](#configuration-options)
|
|
32
31
|
- [Styling Guide](#styling-your-accordions)
|
|
33
32
|
- [Advanced Examples](#advanced-examples)
|
|
@@ -39,13 +38,16 @@ Experience the accordion extension in action: [View Demo](https://fsegurai.githu
|
|
|
39
38
|
|
|
40
39
|
### Basic Syntax
|
|
41
40
|
|
|
42
|
-
**`accordion` is the identifier for the extended accordion block.** Use
|
|
41
|
+
**`accordion` is the identifier for the extended accordion block.** Use a fenced code block with the info string
|
|
42
|
+
`accordion` to create an accordion:
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
`````markdown
|
|
45
|
+
```accordion
|
|
46
|
+
title: Your Title
|
|
47
|
+
---
|
|
46
48
|
Your content goes here...
|
|
47
|
-
::::accordionend
|
|
48
49
|
```
|
|
50
|
+
`````
|
|
49
51
|
|
|
50
52
|
<!-- SECTION:CUSTOM_USAGE_EXAMPLE -->
|
|
51
53
|
|
|
@@ -83,24 +85,35 @@ marked.use(markedExtendedAccordion());
|
|
|
83
85
|
|
|
84
86
|
// Your markdown content
|
|
85
87
|
const markdown = `
|
|
86
|
-
|
|
88
|
+
\`\`\`accordion
|
|
89
|
+
title: Simple Accordion
|
|
90
|
+
---
|
|
87
91
|
This is the content of the accordion.
|
|
88
92
|
|
|
89
93
|
- Item 1
|
|
90
94
|
- Item 2
|
|
91
|
-
|
|
95
|
+
\`\`\`
|
|
92
96
|
|
|
93
|
-
|
|
97
|
+
\`\`\`accordion
|
|
98
|
+
title: Expanded Accordion
|
|
99
|
+
expanded: true
|
|
100
|
+
---
|
|
94
101
|
This accordion is expanded by default.
|
|
95
|
-
|
|
102
|
+
\`\`\`
|
|
96
103
|
|
|
97
|
-
|
|
104
|
+
\`\`\`accordion
|
|
105
|
+
title: Custom Heading Level
|
|
106
|
+
level: 2
|
|
107
|
+
---
|
|
98
108
|
This accordion uses an H2 heading for better document structure.
|
|
99
|
-
|
|
109
|
+
\`\`\`
|
|
100
110
|
|
|
101
|
-
|
|
111
|
+
\`\`\`accordion
|
|
112
|
+
title: Custom Animation
|
|
113
|
+
duration: 0.5s
|
|
114
|
+
---
|
|
102
115
|
This accordion has a custom animation duration.
|
|
103
|
-
|
|
116
|
+
\`\`\`
|
|
104
117
|
`;
|
|
105
118
|
|
|
106
119
|
// Parse and render
|
|
@@ -110,46 +123,83 @@ console.log(html);
|
|
|
110
123
|
|
|
111
124
|
### Syntax & Usage
|
|
112
125
|
|
|
113
|
-
The accordion
|
|
126
|
+
The accordion uses a fenced code block with the info string `accordion`. Front matter (optional) is placed at the top of
|
|
127
|
+
the block, terminated by a lone `---` line. Everything after the `---` is rendered as Markdown content.
|
|
114
128
|
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
`````markdown
|
|
130
|
+
```accordion
|
|
131
|
+
title: Title
|
|
132
|
+
expanded: false
|
|
133
|
+
level: 3
|
|
134
|
+
duration: 0.3s
|
|
135
|
+
---
|
|
117
136
|
Your content here...
|
|
118
|
-
::::accordionend
|
|
119
137
|
```
|
|
138
|
+
`````
|
|
139
|
+
|
|
140
|
+
**Front matter parsing rules:**
|
|
141
|
+
|
|
142
|
+
- Front matter is **optional**. It is only parsed when the first non-blank line is a `key: value` pair AND a lone `---`
|
|
143
|
+
line terminates it.
|
|
144
|
+
- Without a `---` separator, the entire body is treated as content with an empty title.
|
|
145
|
+
- Values may be optionally wrapped in single or double quotes (quotes are stripped).
|
|
146
|
+
- Unsupported keys are silently ignored.
|
|
120
147
|
|
|
121
148
|
**Available Properties:**
|
|
122
149
|
|
|
123
|
-
| Property
|
|
124
|
-
|
|
125
|
-
| `title`
|
|
126
|
-
| `expanded`
|
|
127
|
-
| `level`
|
|
128
|
-
| `duration`
|
|
150
|
+
| Property | Type | Default | Description |
|
|
151
|
+
|----------------|-----------|----------|-----------------------------------------------------------------------------------|
|
|
152
|
+
| `title` | `string` | `""` | Header text (supports inline markdown) |
|
|
153
|
+
| `expanded` | `boolean` | `false` | Whether accordion is open by default |
|
|
154
|
+
| `level` | `number` | `3` | Heading level (1-6) for semantic HTML structure |
|
|
155
|
+
| `duration` | `string` | (option) | Animation duration (CSS time value) |
|
|
156
|
+
| `easing` | `string` | (option) | Animation timing function (CSS easing value) |
|
|
157
|
+
| `group` | `string` | `""` | Exclusive group name (HTML `name` attribute) |
|
|
158
|
+
| `id` | `string` | `""` | Custom `id` for anchor links |
|
|
159
|
+
| `icon` | `string` | `""` | Icon character/emoji shown around the title |
|
|
160
|
+
| `iconPosition` | `string` | (option) | Icon placement relative to the title: `before` / `after` |
|
|
161
|
+
| `variant` | `string` | `""` | Named variant (`note`/`tip`/`important`/`warning`/`caution`) with a baked-in icon |
|
|
162
|
+
| `class` | `string` | `""` | Extra CSS class(es) appended to the container |
|
|
163
|
+
| `data-*` | `string` | — | Any `data-*` key becomes an escaped `data-*` attribute |
|
|
129
164
|
|
|
130
165
|
**Examples:**
|
|
131
166
|
|
|
132
|
-
|
|
167
|
+
`````markdown
|
|
133
168
|
<!-- Minimal accordion -->
|
|
134
|
-
|
|
169
|
+
|
|
170
|
+
```accordion
|
|
171
|
+
title: Basic Example
|
|
172
|
+
---
|
|
135
173
|
Content here
|
|
136
|
-
|
|
174
|
+
```
|
|
137
175
|
|
|
138
176
|
<!-- Expanded by default -->
|
|
139
|
-
|
|
177
|
+
|
|
178
|
+
```accordion
|
|
179
|
+
title: Pre-opened
|
|
180
|
+
expanded: true
|
|
181
|
+
---
|
|
140
182
|
This content is visible on page load
|
|
141
|
-
|
|
183
|
+
```
|
|
142
184
|
|
|
143
185
|
<!-- Custom heading level for better SEO -->
|
|
144
|
-
|
|
186
|
+
|
|
187
|
+
```accordion
|
|
188
|
+
title: Section Heading
|
|
189
|
+
level: 2
|
|
190
|
+
---
|
|
145
191
|
Using H2 for better document outline
|
|
146
|
-
|
|
192
|
+
```
|
|
147
193
|
|
|
148
194
|
<!-- Slower animation -->
|
|
149
|
-
|
|
195
|
+
|
|
196
|
+
```accordion
|
|
197
|
+
title: Smooth Animation
|
|
198
|
+
duration: 0.5s
|
|
199
|
+
---
|
|
150
200
|
Content with slower transition
|
|
151
|
-
::::accordionend
|
|
152
201
|
```
|
|
202
|
+
`````
|
|
153
203
|
|
|
154
204
|
<!-- SECTION:CUSTOM_USAGE_NOTES -->
|
|
155
205
|
|
|
@@ -233,8 +283,10 @@ For Angular projects using `ngx-markdown`:
|
|
|
233
283
|
}
|
|
234
284
|
|
|
235
285
|
// Or import in your global styles.scss:
|
|
236
|
-
@import
|
|
237
|
-
|
|
286
|
+
@import
|
|
287
|
+
'@fsegurai/marked-extended-accordion/styles/accordion.scss';
|
|
288
|
+
@import
|
|
289
|
+
'@fsegurai/marked-extended-accordion/styles/accordion-theme.scss';
|
|
238
290
|
```
|
|
239
291
|
|
|
240
292
|
#### Vanilla HTML/JavaScript Example
|
|
@@ -270,16 +322,21 @@ Complete example for projects without build tools:
|
|
|
270
322
|
|
|
271
323
|
// Your markdown content
|
|
272
324
|
const markdown = `
|
|
273
|
-
|
|
325
|
+
\`\`\`accordion
|
|
326
|
+
title: Simple Accordion
|
|
327
|
+
---
|
|
274
328
|
This is the content of the accordion.
|
|
275
329
|
|
|
276
330
|
- Item 1
|
|
277
331
|
- Item 2
|
|
278
|
-
|
|
332
|
+
\`\`\`
|
|
279
333
|
|
|
280
|
-
|
|
334
|
+
\`\`\`accordion
|
|
335
|
+
title: Expanded Accordion
|
|
336
|
+
expanded: true
|
|
337
|
+
---
|
|
281
338
|
This accordion is expanded by default.
|
|
282
|
-
|
|
339
|
+
\`\`\`
|
|
283
340
|
`;
|
|
284
341
|
|
|
285
342
|
// Render the markdown
|
|
@@ -301,16 +358,22 @@ The extension generates semantic HTML using native `<details>` and `<summary>` e
|
|
|
301
358
|
|
|
302
359
|
```html
|
|
303
360
|
|
|
304
|
-
<details id="accordion-{
|
|
361
|
+
<details id="accordion-{hash}" class="marked-extended-accordion" open name="faq"
|
|
362
|
+
style="--marked-extended-accordion-animation-duration: 0.3s; --marked-extended-accordion-transition-timing: ease-in-out;">
|
|
305
363
|
<summary class="marked-extended-accordion-header">
|
|
364
|
+
<span class="marked-extended-accordion-icon" aria-hidden="true">➤</span>
|
|
306
365
|
<h3 class="marked-extended-accordion-title">Your Title</h3>
|
|
307
366
|
</summary>
|
|
308
367
|
<div class="marked-extended-accordion-content">
|
|
309
|
-
<!--
|
|
368
|
+
<!-- rendered markdown content -->
|
|
310
369
|
</div>
|
|
311
370
|
</details>
|
|
312
371
|
```
|
|
313
372
|
|
|
373
|
+
(The `name` attribute and icon span only appear when `group`/`icon`/`variant` are set. A `variant` adds a
|
|
374
|
+
`marked-extended-accordion-{variant}` class, `class` appends extra classes, and `data-*` keys become `data-*`
|
|
375
|
+
attributes. With `iconPosition: after` the icon span moves after the heading.)
|
|
376
|
+
|
|
314
377
|
**Benefits of using `<details>`:**
|
|
315
378
|
|
|
316
379
|
- ✅ Native browser support (no JavaScript required for basic functionality)
|
|
@@ -325,6 +388,7 @@ The extension generates semantic HTML using native `<details>` and `<summary>` e
|
|
|
325
388
|
| `.marked-extended-accordion` | `details` | Main container element |
|
|
326
389
|
| `.marked-extended-accordion-header` | `summary` | Clickable header/trigger element |
|
|
327
390
|
| `.marked-extended-accordion-title` | `h1-h6` | Title text element |
|
|
391
|
+
| `.marked-extended-accordion-icon` | `span` | Optional icon before title |
|
|
328
392
|
| `.marked-extended-accordion-content` | `div` | Content wrapper |
|
|
329
393
|
|
|
330
394
|
**Styling Targets:**
|
|
@@ -583,46 +647,6 @@ Check the [demo](https://fsegurai.github.io/marked-extensions) to see various st
|
|
|
583
647
|
|
|
584
648
|
<!-- SECTION:CUSTOM_SECTIONS -->
|
|
585
649
|
|
|
586
|
-
### Aliases
|
|
587
|
-
|
|
588
|
-
For convenience, the accordion block supports shorthand aliases. You can use these alternative syntaxes:
|
|
589
|
-
|
|
590
|
-
#### Available Aliases
|
|
591
|
-
|
|
592
|
-
**Start Tags:**
|
|
593
|
-
|
|
594
|
-
- `::::accordion{...}` (full syntax)
|
|
595
|
-
- `:accordion{...}` (short syntax)
|
|
596
|
-
- `:acd{...}` (shortest syntax)
|
|
597
|
-
|
|
598
|
-
**End Tags:**
|
|
599
|
-
|
|
600
|
-
- `::::accordionend` (full syntax)
|
|
601
|
-
- `:accordionend` (short syntax)
|
|
602
|
-
- `:acdend` (shortest syntax)
|
|
603
|
-
|
|
604
|
-
#### Examples Using Aliases
|
|
605
|
-
|
|
606
|
-
```markdown
|
|
607
|
-
<!-- Full syntax -->
|
|
608
|
-
::::accordion{title="Full Syntax"}
|
|
609
|
-
Content here
|
|
610
|
-
::::accordionend
|
|
611
|
-
|
|
612
|
-
<!-- Short syntax -->
|
|
613
|
-
:accordion{title="Short Syntax"}
|
|
614
|
-
Content here
|
|
615
|
-
:accordionend
|
|
616
|
-
|
|
617
|
-
<!-- Shortest syntax -->
|
|
618
|
-
:acd{title="Shortest Syntax"}
|
|
619
|
-
Content here
|
|
620
|
-
:acdend
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
**Note:** You can mix and match start/end aliases, but it's recommended to use consistent syntax throughout your
|
|
624
|
-
document for readability.
|
|
625
|
-
|
|
626
650
|
### Configuration Options
|
|
627
651
|
|
|
628
652
|
The accordion extension accepts several configuration options when initializing. Pass them as an object to the extension
|
|
@@ -640,24 +664,35 @@ marked.use(markedExtendedAccordion({
|
|
|
640
664
|
|
|
641
665
|
#### Extension Options
|
|
642
666
|
|
|
643
|
-
| Option | Type
|
|
644
|
-
|
|
645
|
-
| `className` | `string`
|
|
646
|
-
| `prefixId` | `string`
|
|
647
|
-
| `animationDuration` | `string`
|
|
648
|
-
| `
|
|
649
|
-
| `
|
|
667
|
+
| Option | Type | Default | Description |
|
|
668
|
+
|---------------------|-------------|-------------------------------|------------------------------------------------------------------------------------------|
|
|
669
|
+
| `className` | `string` | `'marked-extended-accordion'` | Base CSS class name applied to all accordion containers |
|
|
670
|
+
| `prefixId` | `string` | `'accordion-'` | Prefix for generating unique accordion IDs |
|
|
671
|
+
| `animationDuration` | `string` | `'0.3s'` | Default animation duration (can be overridden per accordion) |
|
|
672
|
+
| `animationEasing` | `string` | `'ease-in-out'` | Default animation timing function (can be overridden per accordion via `easing`) |
|
|
673
|
+
| `iconPosition` | `string` | `'before'` | Default icon placement relative to the title: `before` or `after` |
|
|
674
|
+
| `variants` | `Variant[]` | `[]` | Custom variants merged over the built-ins (`note`/`tip`/`important`/`warning`/`caution`) |
|
|
675
|
+
| `template` | `string` | `null` | Custom HTML template for rendering (see [Custom Templates](#custom-html-template)) |
|
|
676
|
+
| `customizeToken` | `function` | `null` | Function to customize tokens before rendering |
|
|
650
677
|
|
|
651
678
|
#### Markdown Syntax Properties
|
|
652
679
|
|
|
653
|
-
These properties are specified in the accordion's
|
|
654
|
-
|
|
655
|
-
| Property
|
|
656
|
-
|
|
657
|
-
| `title`
|
|
658
|
-
| `expanded`
|
|
659
|
-
| `level`
|
|
660
|
-
| `duration`
|
|
680
|
+
These properties are specified in the accordion's front matter:
|
|
681
|
+
|
|
682
|
+
| Property | Type | Default | Description |
|
|
683
|
+
|----------------|-----------|----------|-----------------------------------------------------------------------------------|
|
|
684
|
+
| `title` | `string` | `""` | Header text (supports inline markdown) |
|
|
685
|
+
| `expanded` | `boolean` | `false` | Whether accordion is open by default |
|
|
686
|
+
| `level` | `number` | `3` | Heading level (1-6) for semantic HTML structure |
|
|
687
|
+
| `duration` | `string` | (option) | Animation duration (CSS time value) |
|
|
688
|
+
| `easing` | `string` | (option) | Animation timing function (CSS easing value) |
|
|
689
|
+
| `group` | `string` | `""` | Exclusive group name (HTML `name` attribute) |
|
|
690
|
+
| `id` | `string` | `""` | Custom `id` for anchor links |
|
|
691
|
+
| `icon` | `string` | `""` | Icon character/emoji shown around the title |
|
|
692
|
+
| `iconPosition` | `string` | (option) | Icon placement relative to the title: `before` / `after` |
|
|
693
|
+
| `variant` | `string` | `""` | Named variant (`note`/`tip`/`important`/`warning`/`caution`) with a baked-in icon |
|
|
694
|
+
| `class` | `string` | `""` | Extra CSS class(es) appended to the container |
|
|
695
|
+
| `data-*` | `string` | — | Any `data-*` key becomes an escaped `data-*` attribute |
|
|
661
696
|
|
|
662
697
|
#### Configuration Examples
|
|
663
698
|
|
|
@@ -696,8 +731,8 @@ marked.use(markedExtendedAccordion({
|
|
|
696
731
|
token.meta.expanded = true;
|
|
697
732
|
}
|
|
698
733
|
|
|
699
|
-
// Apply custom class based on
|
|
700
|
-
if (token.meta.
|
|
734
|
+
// Apply custom class based on title
|
|
735
|
+
if (token.meta.title.toLowerCase().includes('warning')) {
|
|
701
736
|
token.meta.className += ' warning-accordion';
|
|
702
737
|
}
|
|
703
738
|
|
|
@@ -711,51 +746,207 @@ marked.use(markedExtendedAccordion({
|
|
|
711
746
|
|
|
712
747
|
### Advanced Examples
|
|
713
748
|
|
|
749
|
+
#### Titles with Inline Markdown
|
|
750
|
+
|
|
751
|
+
The `title` front matter key supports inline markdown — inline code and bold/italic are rendered inside the heading:
|
|
752
|
+
|
|
753
|
+
`````markdown
|
|
754
|
+
```accordion
|
|
755
|
+
title: Use `npm install` and **bold text** in titles
|
|
756
|
+
---
|
|
757
|
+
The heading above renders `<code>` and `<strong>` inline.
|
|
758
|
+
Raw HTML tags in titles are escaped for security.
|
|
759
|
+
```
|
|
760
|
+
`````
|
|
761
|
+
|
|
762
|
+
#### Native Exclusive Groups
|
|
763
|
+
|
|
764
|
+
Set the same `group` value on multiple accordions to make them mutually exclusive. The extension emits a native HTML
|
|
765
|
+
`name` attribute on `<details>`, so only one accordion in the group can be open at a time — **no JavaScript required**.
|
|
766
|
+
|
|
767
|
+
`````markdown
|
|
768
|
+
```accordion
|
|
769
|
+
title: What is Marked.js?
|
|
770
|
+
group: faq
|
|
771
|
+
---
|
|
772
|
+
Marked.js is a fast, lightweight markdown parser and compiler built for speed and extensibility.
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
```accordion
|
|
776
|
+
title: How do I install extensions?
|
|
777
|
+
group: faq
|
|
778
|
+
---
|
|
779
|
+
Use your preferred package manager:
|
|
780
|
+
|
|
781
|
+
\`\`\`bash
|
|
782
|
+
bun add @fsegurai/marked-extended-accordion
|
|
783
|
+
\`\`\`
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
```accordion
|
|
787
|
+
title: Is it free to use?
|
|
788
|
+
group: faq
|
|
789
|
+
expanded: true
|
|
790
|
+
---
|
|
791
|
+
Yes! This extension is MIT licensed and completely free for commercial and personal projects.
|
|
792
|
+
```
|
|
793
|
+
`````
|
|
794
|
+
|
|
795
|
+
#### Custom `id` for Anchor Links
|
|
796
|
+
|
|
797
|
+
Use `id` to assign a stable, human-readable identifier to an accordion. Without it, a deterministic (SSR-safe) id is
|
|
798
|
+
generated as `{prefixId}{hash}`.
|
|
799
|
+
|
|
800
|
+
`````markdown
|
|
801
|
+
```accordion
|
|
802
|
+
title: Pricing
|
|
803
|
+
id: pricing
|
|
804
|
+
---
|
|
805
|
+
See our [pricing page](#pricing) for details.
|
|
806
|
+
```
|
|
807
|
+
`````
|
|
808
|
+
|
|
809
|
+
Generated attribute: `<details id="pricing" ...>`.
|
|
810
|
+
|
|
811
|
+
#### Optional Icon
|
|
812
|
+
|
|
813
|
+
Set `icon` to render a character or emoji before the title. The icon is wrapped in
|
|
814
|
+
`<span class="marked-extended-accordion-icon" aria-hidden="true">`.
|
|
815
|
+
|
|
816
|
+
`````markdown
|
|
817
|
+
```accordion
|
|
818
|
+
title: Getting Started
|
|
819
|
+
icon: ➤
|
|
820
|
+
---
|
|
821
|
+
Follow these steps to get up and running quickly.
|
|
822
|
+
```
|
|
823
|
+
`````
|
|
824
|
+
|
|
825
|
+
The `.marked-extended-accordion-icon` class provides structural styling for positioning the icon relative to the title.
|
|
826
|
+
|
|
827
|
+
#### Icon Position
|
|
828
|
+
|
|
829
|
+
By default the icon renders **before** the title. Set `iconPosition: after` (per block) or the `iconPosition` option
|
|
830
|
+
(globally) to render it after the title instead.
|
|
831
|
+
|
|
832
|
+
`````markdown
|
|
833
|
+
```accordion
|
|
834
|
+
title: Details
|
|
835
|
+
icon: ➤
|
|
836
|
+
iconPosition: after
|
|
837
|
+
---
|
|
838
|
+
The icon appears after the title text.
|
|
839
|
+
```
|
|
840
|
+
`````
|
|
841
|
+
|
|
842
|
+
#### Variants
|
|
843
|
+
|
|
844
|
+
Use `variant` to apply one of the built-in semantic styles — `note`, `tip`, `important`, `warning`, or `caution` —
|
|
845
|
+
each of which supplies a baked-in icon and an accent color (via the theme styles). An explicit `icon` overrides the
|
|
846
|
+
variant's icon.
|
|
847
|
+
|
|
848
|
+
`````markdown
|
|
849
|
+
```accordion
|
|
850
|
+
title: Heads up
|
|
851
|
+
variant: warning
|
|
852
|
+
---
|
|
853
|
+
This panel renders the built-in warning icon and accent.
|
|
854
|
+
```
|
|
855
|
+
`````
|
|
856
|
+
|
|
857
|
+
Define your own variants — or override a built-in — through the `variants` option:
|
|
858
|
+
|
|
859
|
+
```javascript
|
|
860
|
+
marked.use(markedExtendedAccordion({
|
|
861
|
+
variants: [
|
|
862
|
+
{type: 'spec', icon: '<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><!-- ... --></svg>'},
|
|
863
|
+
],
|
|
864
|
+
}));
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
The variant name is also emitted as a modifier class (`{className}-{variant}`, e.g.
|
|
868
|
+
`marked-extended-accordion-warning`), so you can target it from CSS.
|
|
869
|
+
|
|
870
|
+
#### Custom Classes and Data Attributes
|
|
871
|
+
|
|
872
|
+
Append per-block CSS classes with `class`, and attach arbitrary `data-*` attributes (values are HTML-escaped) directly
|
|
873
|
+
in the front matter:
|
|
874
|
+
|
|
875
|
+
`````markdown
|
|
876
|
+
```accordion
|
|
877
|
+
title: Tracked panel
|
|
878
|
+
class: highlight featured
|
|
879
|
+
data-analytics-id: faq-pricing
|
|
880
|
+
---
|
|
881
|
+
Renders as `<details class="marked-extended-accordion highlight featured" data-analytics-id="faq-pricing">`.
|
|
882
|
+
```
|
|
883
|
+
`````
|
|
884
|
+
|
|
714
885
|
#### Multi-Level Nested Accordions
|
|
715
886
|
|
|
716
|
-
|
|
717
|
-
|
|
887
|
+
Nested accordions use standard CommonMark fence rules: the outer block must use a **longer fence** than the inner block.
|
|
888
|
+
|
|
889
|
+
`````markdown
|
|
890
|
+
````accordion
|
|
891
|
+
title: Level 1: Project Overview
|
|
892
|
+
---
|
|
718
893
|
This is the main project section.
|
|
719
894
|
|
|
720
|
-
|
|
895
|
+
```accordion
|
|
896
|
+
title: Level 2: Phase 1 Details
|
|
897
|
+
---
|
|
721
898
|
Details about phase 1 of the project.
|
|
722
899
|
|
|
723
900
|
- Planning
|
|
724
901
|
- Design
|
|
725
902
|
- Development
|
|
726
|
-
|
|
903
|
+
```
|
|
727
904
|
|
|
728
|
-
|
|
905
|
+
```accordion
|
|
906
|
+
title: Level 2: Phase 2 Details
|
|
907
|
+
---
|
|
729
908
|
Details about phase 2 of the project.
|
|
730
|
-
::::accordionend
|
|
731
|
-
::::accordionend
|
|
732
909
|
```
|
|
910
|
+
````
|
|
911
|
+
`````
|
|
733
912
|
|
|
734
913
|
#### FAQ Section with Custom Styling
|
|
735
914
|
|
|
736
|
-
|
|
737
|
-
|
|
915
|
+
`````markdown
|
|
916
|
+
```accordion
|
|
917
|
+
title: What is Marked.js?
|
|
918
|
+
group: faq-styled
|
|
919
|
+
---
|
|
738
920
|
Marked.js is a markdown parser and compiler. Built for speed and extensibility.
|
|
739
|
-
|
|
921
|
+
```
|
|
740
922
|
|
|
741
|
-
|
|
923
|
+
```accordion
|
|
924
|
+
title: How do I install extensions?
|
|
925
|
+
group: faq-styled
|
|
926
|
+
---
|
|
742
927
|
Use your preferred package manager:
|
|
743
928
|
|
|
744
929
|
\`\`\`bash
|
|
745
930
|
bun add @fsegurai/marked-extended-accordion
|
|
746
931
|
\`\`\`
|
|
747
|
-
|
|
932
|
+
```
|
|
748
933
|
|
|
749
|
-
|
|
934
|
+
```accordion
|
|
935
|
+
title: Is it free to use?
|
|
936
|
+
group: faq-styled
|
|
937
|
+
expanded: true
|
|
938
|
+
---
|
|
750
939
|
Yes! This extension is MIT licensed and completely free to use in commercial and personal projects.
|
|
751
|
-
::::accordionend
|
|
752
940
|
```
|
|
941
|
+
`````
|
|
753
942
|
|
|
754
943
|
#### Documentation Sections
|
|
755
944
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
945
|
+
`````markdown
|
|
946
|
+
```accordion
|
|
947
|
+
title: API Reference
|
|
948
|
+
level: 2
|
|
949
|
+
---
|
|
759
950
|
## Authentication
|
|
760
951
|
|
|
761
952
|
The API uses OAuth 2.0 for authentication.
|
|
@@ -771,26 +962,33 @@ The API uses OAuth 2.0 for authentication.
|
|
|
771
962
|
|
|
772
963
|
\`\`\`javascript
|
|
773
964
|
const response = await fetch('/api/v1/users', {
|
|
774
|
-
headers: {
|
|
775
|
-
'Authorization': 'Bearer YOUR_TOKEN'
|
|
776
|
-
}
|
|
965
|
+
headers: {
|
|
966
|
+
'Authorization': 'Bearer YOUR_TOKEN'
|
|
967
|
+
}
|
|
777
968
|
});
|
|
778
969
|
\`\`\`
|
|
779
|
-
::::accordionend
|
|
780
970
|
```
|
|
971
|
+
`````
|
|
781
972
|
|
|
782
973
|
#### Interactive Tutorial Steps
|
|
783
974
|
|
|
784
|
-
|
|
785
|
-
|
|
975
|
+
`````markdown
|
|
976
|
+
```accordion
|
|
977
|
+
title: Step 1: Installation
|
|
978
|
+
expanded: true
|
|
979
|
+
level: 3
|
|
980
|
+
---
|
|
786
981
|
Install the required packages:
|
|
787
982
|
|
|
788
983
|
\`\`\`bash
|
|
789
984
|
bun add marked @fsegurai/marked-extended-accordion
|
|
790
985
|
\`\`\`
|
|
791
|
-
|
|
986
|
+
```
|
|
792
987
|
|
|
793
|
-
|
|
988
|
+
```accordion
|
|
989
|
+
title: Step 2: Configuration
|
|
990
|
+
level: 3
|
|
991
|
+
---
|
|
794
992
|
Import and configure the extension:
|
|
795
993
|
|
|
796
994
|
\`\`\`javascript
|
|
@@ -798,21 +996,24 @@ import { marked } from 'marked';
|
|
|
798
996
|
import markedExtendedAccordion from '@fsegurai/marked-extended-accordion';
|
|
799
997
|
|
|
800
998
|
marked.use(markedExtendedAccordion({
|
|
801
|
-
animationDuration: '0.5s'
|
|
999
|
+
animationDuration: '0.5s'
|
|
802
1000
|
}));
|
|
803
1001
|
\`\`\`
|
|
804
|
-
|
|
1002
|
+
```
|
|
805
1003
|
|
|
806
|
-
|
|
807
|
-
|
|
1004
|
+
```accordion
|
|
1005
|
+
title: Step 3: Usage
|
|
1006
|
+
level: 3
|
|
1007
|
+
---
|
|
1008
|
+
Write your markdown with the fenced accordion syntax:
|
|
808
1009
|
|
|
809
|
-
\`\`\`
|
|
810
|
-
|
|
1010
|
+
\`\`\`accordion
|
|
1011
|
+
title: My First Accordion
|
|
1012
|
+
---
|
|
811
1013
|
Content goes here
|
|
812
|
-
::::accordionend
|
|
813
1014
|
\`\`\`
|
|
814
|
-
::::accordionend
|
|
815
1015
|
```
|
|
1016
|
+
`````
|
|
816
1017
|
|
|
817
1018
|
### Advanced Configuration
|
|
818
1019
|
|
|
@@ -825,21 +1026,24 @@ import markedExtendedAccordion from '@fsegurai/marked-extended-accordion';
|
|
|
825
1026
|
marked.use(markedExtendedAccordion({
|
|
826
1027
|
customizeToken: (token) => {
|
|
827
1028
|
// Add custom data attributes
|
|
828
|
-
if (token.
|
|
829
|
-
token.
|
|
1029
|
+
if (token.meta.title.includes('Important')) {
|
|
1030
|
+
token.meta.className = (token.meta.className || '') + ' important-accordion';
|
|
830
1031
|
}
|
|
831
1032
|
|
|
832
1033
|
// Auto-expand accordions with specific keywords
|
|
833
|
-
if (token.
|
|
834
|
-
token.
|
|
1034
|
+
if (token.meta.title.toLowerCase().includes('getting started')) {
|
|
1035
|
+
token.meta.expanded = true;
|
|
835
1036
|
}
|
|
836
1037
|
|
|
837
1038
|
// Log for debugging
|
|
838
|
-
console.log('Processing accordion:', token.
|
|
1039
|
+
console.log('Processing accordion:', token.meta.title);
|
|
839
1040
|
}
|
|
840
1041
|
}));
|
|
841
1042
|
```
|
|
842
1043
|
|
|
1044
|
+
The `token.meta` object has the following fields: `title`, `expanded`, `level`, `className`, `animationDuration`,
|
|
1045
|
+
`animationEasing`, `group`, `customId`, `icon`, `iconPosition`, `variant`, `variantIcon`, `extraClasses`, `dataAttrs`.
|
|
1046
|
+
|
|
843
1047
|
#### Custom HTML Template
|
|
844
1048
|
|
|
845
1049
|
You can provide a custom HTML template for complete control over the structure:
|
|
@@ -847,9 +1051,9 @@ You can provide a custom HTML template for complete control over the structure:
|
|
|
847
1051
|
```javascript
|
|
848
1052
|
marked.use(markedExtendedAccordion({
|
|
849
1053
|
template: `
|
|
850
|
-
<details id="{accordionId}" class="{className}" {expandedAttr}>
|
|
1054
|
+
<details id="{accordionId}" class="{className}" {expandedAttr} {nameAttr}>
|
|
851
1055
|
<summary class="{className}-header">
|
|
852
|
-
|
|
1056
|
+
{icon}
|
|
853
1057
|
<{headingTag} class="{className}-title">{title}</{headingTag}>
|
|
854
1058
|
</summary>
|
|
855
1059
|
<div class="{className}-content" style="animation-duration: {animationDuration}">
|
|
@@ -862,25 +1066,34 @@ marked.use(markedExtendedAccordion({
|
|
|
862
1066
|
|
|
863
1067
|
**Available Placeholders:**
|
|
864
1068
|
|
|
865
|
-
| Placeholder | Description
|
|
866
|
-
|
|
867
|
-
| `{accordionId}` | Unique identifier for the accordion
|
|
868
|
-
| `{className}` | Base CSS class name
|
|
869
|
-
| `{
|
|
870
|
-
| `{
|
|
871
|
-
| `{
|
|
872
|
-
| `{
|
|
873
|
-
| `{
|
|
874
|
-
| `{
|
|
1069
|
+
| Placeholder | Description | Example Value |
|
|
1070
|
+
|-----------------------|------------------------------------------------------------------------|----------------------------------------------------------------------------------|
|
|
1071
|
+
| `{accordionId}` | Unique identifier for the accordion | `accordion-abc123` |
|
|
1072
|
+
| `{className}` | Base CSS class name | `marked-extended-accordion` |
|
|
1073
|
+
| `{variantClass}` | Variant modifier class (leading space), empty when no variant | ` marked-extended-accordion-warning` or `` |
|
|
1074
|
+
| `{extraClasses}` | Per-block classes from `class` (leading space), empty when none | ` highlight featured` or `` |
|
|
1075
|
+
| `{expandedAttr}` | `open` attribute if expanded, empty otherwise | `open` or `` |
|
|
1076
|
+
| `{headingTag}` | HTML heading tag based on level | `h2`, `h3`, etc. |
|
|
1077
|
+
| `{title}` | Accordion title text (may contain inline HTML) | `My Accordion` |
|
|
1078
|
+
| `{content}` | Rendered markdown content | `<p>Content...</p>` |
|
|
1079
|
+
| `{animationDuration}` | Animation duration value | `0.3s` |
|
|
1080
|
+
| `{styleAttr}` | Inline CSS variables for duration and easing | `--marked-extended-accordion-animation-duration: 0.3s; ...` |
|
|
1081
|
+
| `{expanded}` | Boolean string value | `true` or `false` |
|
|
1082
|
+
| `{nameAttr}` | `name="group"` attribute for exclusive accordions, empty when no group | `name="faq"` or `` |
|
|
1083
|
+
| `{dataAttrs}` | Serialized custom `data-*` attributes, empty when none | ` data-id="42"` or `` |
|
|
1084
|
+
| `{icon}` | Icon span markup (before-title alias), empty when no icon | `<span class="marked-extended-accordion-icon" aria-hidden="true">➤</span>` or `` |
|
|
1085
|
+
| `{iconBefore}` | Icon span markup when positioned before the title, empty otherwise | same as `{icon}` or `` |
|
|
1086
|
+
| `{iconAfter}` | Icon span markup when positioned after the title, empty otherwise | same as `{icon}` or `` |
|
|
875
1087
|
|
|
876
1088
|
**Example: Card-Style Template**
|
|
877
1089
|
|
|
878
1090
|
```javascript
|
|
879
1091
|
marked.use(markedExtendedAccordion({
|
|
880
1092
|
template: `
|
|
881
|
-
<details id="{accordionId}" class="accordion-card" {expandedAttr}>
|
|
1093
|
+
<details id="{accordionId}" class="accordion-card" {expandedAttr} {nameAttr}>
|
|
882
1094
|
<summary class="accordion-card-header">
|
|
883
1095
|
<div class="accordion-card-header-content">
|
|
1096
|
+
{icon}
|
|
884
1097
|
<{headingTag} class="accordion-card-title">{title}</{headingTag}>
|
|
885
1098
|
<span class="accordion-card-icon" aria-hidden="true">
|
|
886
1099
|
<svg width="24" height="24" viewBox="0 0 24 24">
|
|
@@ -948,29 +1161,41 @@ This extension leverages native HTML `<details>` and `<summary>` elements for ex
|
|
|
948
1161
|
|
|
949
1162
|
1. **Use Appropriate Heading Levels**: Maintain proper document hierarchy
|
|
950
1163
|
|
|
951
|
-
|
|
952
|
-
|
|
1164
|
+
`````markdown
|
|
1165
|
+
```accordion
|
|
1166
|
+
title: Main Section
|
|
1167
|
+
level: 2
|
|
1168
|
+
---
|
|
953
1169
|
Content
|
|
954
|
-
|
|
1170
|
+
```
|
|
955
1171
|
|
|
956
|
-
|
|
1172
|
+
```accordion
|
|
1173
|
+
title: Subsection
|
|
1174
|
+
level: 3
|
|
1175
|
+
---
|
|
957
1176
|
Content
|
|
958
|
-
::::accordionend
|
|
959
1177
|
```
|
|
1178
|
+
`````
|
|
960
1179
|
|
|
961
1180
|
2. **Provide Descriptive Titles**: Make accordion titles clear and descriptive
|
|
962
1181
|
|
|
963
|
-
|
|
1182
|
+
`````markdown
|
|
964
1183
|
<!-- Good -->
|
|
965
|
-
|
|
1184
|
+
|
|
1185
|
+
```accordion
|
|
1186
|
+
title: How to install the extension
|
|
1187
|
+
---
|
|
966
1188
|
Installation instructions...
|
|
967
|
-
|
|
1189
|
+
```
|
|
968
1190
|
|
|
969
1191
|
<!-- Avoid -->
|
|
970
|
-
|
|
1192
|
+
|
|
1193
|
+
```accordion
|
|
1194
|
+
title: Click here
|
|
1195
|
+
---
|
|
971
1196
|
Content...
|
|
972
|
-
::::accordionend
|
|
973
1197
|
```
|
|
1198
|
+
`````
|
|
974
1199
|
|
|
975
1200
|
3. **Add Focus Styles**: Ensure keyboard users can see focus (
|
|
976
1201
|
see [Accessibility Considerations](#accessibility-considerations))
|
|
@@ -1110,23 +1335,28 @@ accordion.addEventListener('toggle', (event) => {
|
|
|
1110
1335
|
|
|
1111
1336
|
**Solutions**:
|
|
1112
1337
|
|
|
1113
|
-
1.
|
|
1114
|
-
2. Check nesting depth - avoid going beyond 3 levels
|
|
1115
|
-
3. Verify there are no syntax errors in the markdown
|
|
1338
|
+
1. The outer accordion fence must use **more backticks** than the inner one (CommonMark fence rule).
|
|
1339
|
+
2. Check nesting depth - avoid going beyond 3 levels.
|
|
1340
|
+
3. Verify there are no syntax errors in the markdown.
|
|
1116
1341
|
|
|
1117
|
-
**Valid nesting:**
|
|
1342
|
+
**Valid nesting (outer uses 4 backticks, inner uses 3):**
|
|
1118
1343
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1344
|
+
````markdown
|
|
1345
|
+
````accordion
|
|
1346
|
+
title: Outer
|
|
1347
|
+
---
|
|
1121
1348
|
Content here
|
|
1122
1349
|
|
|
1123
|
-
|
|
1350
|
+
```accordion
|
|
1351
|
+
title: Inner
|
|
1352
|
+
---
|
|
1124
1353
|
Nested content
|
|
1125
|
-
|
|
1354
|
+
```
|
|
1126
1355
|
|
|
1127
1356
|
More outer content
|
|
1128
|
-
|
|
1129
|
-
|
|
1357
|
+
````
|
|
1358
|
+
|
|
1359
|
+
````
|
|
1130
1360
|
|
|
1131
1361
|
### Integration Examples
|
|
1132
1362
|
|
|
@@ -1169,9 +1399,11 @@ import { ref, computed } from 'vue';
|
|
|
1169
1399
|
marked.use(markedExtendedAccordion());
|
|
1170
1400
|
|
|
1171
1401
|
const markdown = ref(`
|
|
1172
|
-
|
|
1402
|
+
\`\`\`accordion
|
|
1403
|
+
title: Example
|
|
1404
|
+
---
|
|
1173
1405
|
Content here
|
|
1174
|
-
|
|
1406
|
+
\`\`\`
|
|
1175
1407
|
`);
|
|
1176
1408
|
|
|
1177
1409
|
const html = computed(() => marked.parse(markdown.value));
|
|
@@ -1192,9 +1424,11 @@ const html = computed(() => marked.parse(markdown.value));
|
|
|
1192
1424
|
|
|
1193
1425
|
marked.use(markedExtendedAccordion());
|
|
1194
1426
|
|
|
1195
|
-
let markdown =
|
|
1427
|
+
let markdown = `\`\`\`accordion
|
|
1428
|
+
title: Example
|
|
1429
|
+
---
|
|
1196
1430
|
Content
|
|
1197
|
-
|
|
1431
|
+
\`\`\``;
|
|
1198
1432
|
|
|
1199
1433
|
$: html = marked.parse(markdown);
|
|
1200
1434
|
</script>
|
|
@@ -1208,65 +1442,95 @@ Content
|
|
|
1208
1442
|
|
|
1209
1443
|
Use appropriate heading levels to maintain proper document hierarchy:
|
|
1210
1444
|
|
|
1211
|
-
|
|
1445
|
+
`````markdown
|
|
1212
1446
|
<!-- Good: Maintains logical hierarchy -->
|
|
1213
|
-
|
|
1447
|
+
```accordion
|
|
1448
|
+
title: Chapter 1: Introduction
|
|
1449
|
+
level: 2
|
|
1450
|
+
---
|
|
1214
1451
|
Content for chapter 1
|
|
1452
|
+
```
|
|
1215
1453
|
|
|
1216
|
-
|
|
1454
|
+
```accordion
|
|
1455
|
+
title: Section 1.1: Getting Started
|
|
1456
|
+
level: 3
|
|
1457
|
+
---
|
|
1217
1458
|
Nested content
|
|
1218
|
-
|
|
1219
|
-
::::accordionend
|
|
1459
|
+
```
|
|
1220
1460
|
|
|
1221
1461
|
<!-- Avoid: Skipping heading levels -->
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1462
|
+
```accordion
|
|
1463
|
+
title: Main Topic
|
|
1464
|
+
level: 2
|
|
1465
|
+
---
|
|
1466
|
+
Content
|
|
1467
|
+
```
|
|
1468
|
+
|
|
1469
|
+
```accordion
|
|
1470
|
+
title: Subtopic
|
|
1471
|
+
level: 5
|
|
1472
|
+
---
|
|
1473
|
+
<!-- ❌ Skips h3 and h4 -->
|
|
1226
1474
|
```
|
|
1475
|
+
`````
|
|
1227
1476
|
|
|
1228
1477
|
#### 2. **Progressive Enhancement**
|
|
1229
1478
|
|
|
1230
1479
|
Design content to be accessible even if JavaScript or CSS fails:
|
|
1231
1480
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1481
|
+
`````markdown
|
|
1482
|
+
```accordion
|
|
1483
|
+
title: Important Information
|
|
1484
|
+
---
|
|
1234
1485
|
Always write content that makes sense even when fully expanded.
|
|
1235
1486
|
Don't rely on the accordion state for critical information visibility.
|
|
1236
|
-
::::accordionend
|
|
1237
1487
|
```
|
|
1488
|
+
`````
|
|
1238
1489
|
|
|
1239
1490
|
#### 3. **Clear, Descriptive Titles**
|
|
1240
1491
|
|
|
1241
1492
|
Use meaningful titles that describe the content:
|
|
1242
1493
|
|
|
1243
|
-
|
|
1494
|
+
`````markdown
|
|
1244
1495
|
<!-- Good: Descriptive -->
|
|
1245
|
-
|
|
1496
|
+
|
|
1497
|
+
```accordion
|
|
1498
|
+
title: How to install the extension
|
|
1499
|
+
---
|
|
1246
1500
|
Installation steps...
|
|
1247
|
-
|
|
1501
|
+
```
|
|
1248
1502
|
|
|
1249
1503
|
<!-- Avoid: Vague -->
|
|
1250
|
-
|
|
1504
|
+
|
|
1505
|
+
```accordion
|
|
1506
|
+
title: More info
|
|
1507
|
+
---
|
|
1251
1508
|
Content...
|
|
1252
|
-
::::accordionend
|
|
1253
1509
|
```
|
|
1510
|
+
`````
|
|
1254
1511
|
|
|
1255
1512
|
#### 4. **Optimal Default States**
|
|
1256
1513
|
|
|
1257
1514
|
Consider which accordions should be open by default:
|
|
1258
1515
|
|
|
1259
|
-
|
|
1516
|
+
`````markdown
|
|
1260
1517
|
<!-- Expand important or frequently accessed content -->
|
|
1261
|
-
|
|
1518
|
+
|
|
1519
|
+
```accordion
|
|
1520
|
+
title: Quick Start Guide
|
|
1521
|
+
expanded: true
|
|
1522
|
+
---
|
|
1262
1523
|
Most users need this information first
|
|
1263
|
-
|
|
1524
|
+
```
|
|
1264
1525
|
|
|
1265
1526
|
<!-- Keep optional details collapsed -->
|
|
1266
|
-
|
|
1527
|
+
|
|
1528
|
+
```accordion
|
|
1529
|
+
title: Advanced Configuration
|
|
1530
|
+
---
|
|
1267
1531
|
Optional advanced settings
|
|
1268
|
-
::::accordionend
|
|
1269
1532
|
```
|
|
1533
|
+
`````
|
|
1270
1534
|
|
|
1271
1535
|
#### 5. **Mobile Optimization**
|
|
1272
1536
|
|
|
@@ -1283,24 +1547,24 @@ Ensure tap targets are large enough (minimum 44×44px):
|
|
|
1283
1547
|
|
|
1284
1548
|
Keep nesting to 2-3 levels maximum for optimal UX and performance:
|
|
1285
1549
|
|
|
1286
|
-
|
|
1287
|
-
<!-- Recommended: 2 levels -->
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1550
|
+
````markdown
|
|
1551
|
+
<!-- Recommended: 2 levels (outer uses 4 backticks, inner uses 3) -->
|
|
1552
|
+
|
|
1553
|
+
````accordion
|
|
1554
|
+
title: Level 1
|
|
1555
|
+
---
|
|
1556
|
+
````accordion content prefix removed — inner block:
|
|
1293
1557
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
::::accordion{title="Level 4"} <!-- ❌ Too complex -->
|
|
1299
|
-
::::accordionend
|
|
1300
|
-
::::accordionend
|
|
1301
|
-
::::accordionend
|
|
1302
|
-
::::accordionend
|
|
1558
|
+
```accordion
|
|
1559
|
+
title: Level 2
|
|
1560
|
+
---
|
|
1561
|
+
Content
|
|
1303
1562
|
```
|
|
1563
|
+
````
|
|
1564
|
+
|
|
1565
|
+
(For deeply nested structures, each level must use progressively longer fences.)
|
|
1566
|
+
|
|
1567
|
+
````
|
|
1304
1568
|
|
|
1305
1569
|
#### 7. **Animation Duration**
|
|
1306
1570
|
|
|
@@ -1321,36 +1585,47 @@ marked.use(markedExtendedAccordion({
|
|
|
1321
1585
|
|
|
1322
1586
|
Keep individual accordion content reasonable in length:
|
|
1323
1587
|
|
|
1324
|
-
|
|
1588
|
+
`````markdown
|
|
1325
1589
|
<!-- Good: Focused content -->
|
|
1326
|
-
|
|
1590
|
+
```accordion
|
|
1591
|
+
title: Installation
|
|
1592
|
+
---
|
|
1327
1593
|
Run: `npm install package-name`
|
|
1328
|
-
|
|
1594
|
+
```
|
|
1329
1595
|
|
|
1330
1596
|
<!-- Avoid: Overly long content -->
|
|
1331
|
-
|
|
1597
|
+
```accordion
|
|
1598
|
+
title: Everything About Our Product
|
|
1599
|
+
---
|
|
1332
1600
|
<!-- ❌ Thousands of lines of content -->
|
|
1333
|
-
::::accordionend
|
|
1334
1601
|
```
|
|
1602
|
+
`````
|
|
1335
1603
|
|
|
1336
1604
|
#### 9. **Group Related Content**
|
|
1337
1605
|
|
|
1338
1606
|
Use accordions to organize related information:
|
|
1339
1607
|
|
|
1340
|
-
|
|
1608
|
+
`````markdown
|
|
1341
1609
|
<!-- Good: Logical grouping -->
|
|
1342
|
-
|
|
1610
|
+
|
|
1611
|
+
```accordion
|
|
1612
|
+
title: Getting Started
|
|
1613
|
+
---
|
|
1343
1614
|
Installation, setup, and first steps
|
|
1344
|
-
|
|
1615
|
+
```
|
|
1345
1616
|
|
|
1346
|
-
|
|
1617
|
+
```accordion
|
|
1618
|
+
title: Configuration
|
|
1619
|
+
---
|
|
1347
1620
|
All configuration options
|
|
1348
|
-
|
|
1621
|
+
```
|
|
1349
1622
|
|
|
1350
|
-
|
|
1623
|
+
```accordion
|
|
1624
|
+
title: API Reference
|
|
1625
|
+
---
|
|
1351
1626
|
API documentation
|
|
1352
|
-
::::accordionend
|
|
1353
1627
|
```
|
|
1628
|
+
`````
|
|
1354
1629
|
|
|
1355
1630
|
#### 10. **Test Across Devices**
|
|
1356
1631
|
|
|
@@ -1362,23 +1637,44 @@ Always test your accordions on:
|
|
|
1362
1637
|
- With screen readers
|
|
1363
1638
|
- In both light and dark modes
|
|
1364
1639
|
|
|
1365
|
-
### Migration
|
|
1640
|
+
### Migration to the Fenced Syntax
|
|
1366
1641
|
|
|
1367
|
-
|
|
1642
|
+
> **Breaking change**: The directive syntax and all its aliases have been removed.
|
|
1368
1643
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1644
|
+
The `::::accordion{...}::::accordionend` directive syntax is no longer supported. The `:acd`, `:accordion`, `:acdend`,
|
|
1645
|
+
and `:accordionend` aliases are also removed. All accordions must now be written as fenced code blocks with the
|
|
1646
|
+
`accordion` info string.
|
|
1371
1647
|
|
|
1372
|
-
|
|
1373
|
-
// Old (v16.x)
|
|
1374
|
-
marked.use(markedExtendedAccordion({injectStyles: true}));
|
|
1648
|
+
**Before (old directive syntax — no longer works):**
|
|
1375
1649
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1650
|
+
```markdown
|
|
1651
|
+
::::accordion{title="Getting Started" expanded="true"}
|
|
1652
|
+
Your **markdown** content here.
|
|
1378
1653
|
|
|
1379
|
-
|
|
1654
|
+
- item 1
|
|
1655
|
+
- item 2
|
|
1656
|
+
::::accordionend
|
|
1380
1657
|
```
|
|
1381
1658
|
|
|
1659
|
+
**After (new fenced syntax):**
|
|
1660
|
+
|
|
1661
|
+
`````markdown
|
|
1662
|
+
```accordion
|
|
1663
|
+
title: Getting Started
|
|
1664
|
+
expanded: true
|
|
1665
|
+
---
|
|
1666
|
+
Your **markdown** content here.
|
|
1667
|
+
- item 1
|
|
1668
|
+
- item 2
|
|
1669
|
+
```
|
|
1670
|
+
`````
|
|
1671
|
+
|
|
1672
|
+
Key differences:
|
|
1673
|
+
|
|
1674
|
+
- Properties are now written as `key: value` front matter lines, not as HTML-style attributes.
|
|
1675
|
+
- The front matter block is terminated by a lone `---` line.
|
|
1676
|
+
- There is no closing tag — the fence closing (` ``` `) ends the block.
|
|
1677
|
+
|
|
1382
1678
|
See [MIGRATION.md](./MIGRATION.md) for complete migration guide.
|
|
1383
1679
|
|
|
1384
1680
|
### API Reference
|
|
@@ -1386,10 +1682,18 @@ See [MIGRATION.md](./MIGRATION.md) for complete migration guide.
|
|
|
1386
1682
|
#### Extension Options
|
|
1387
1683
|
|
|
1388
1684
|
```typescript
|
|
1685
|
+
interface AccordionVariant {
|
|
1686
|
+
type: string; // Variant name referenced by the `variant` front matter key
|
|
1687
|
+
icon: string; // Trusted icon markup (e.g. inline SVG)
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1389
1690
|
interface AccordionOptions {
|
|
1390
1691
|
className?: string; // Base CSS class (default: 'marked-extended-accordion')
|
|
1391
1692
|
prefixId?: string; // ID prefix (default: 'accordion-')
|
|
1392
1693
|
animationDuration?: string; // Animation duration (default: '0.3s')
|
|
1694
|
+
animationEasing?: string; // Animation timing function (default: 'ease-in-out')
|
|
1695
|
+
iconPosition?: 'before' | 'after'; // Default icon placement (default: 'before')
|
|
1696
|
+
variants?: AccordionVariant[]; // Custom variants merged over the built-ins (default: [])
|
|
1393
1697
|
template?: string | null; // Custom HTML template (default: null)
|
|
1394
1698
|
customizeToken?: (token: AccordionToken) => void; // Token customization function
|
|
1395
1699
|
}
|
|
@@ -1397,50 +1701,78 @@ interface AccordionOptions {
|
|
|
1397
1701
|
|
|
1398
1702
|
#### Markdown Syntax
|
|
1399
1703
|
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1704
|
+
`````markdown
|
|
1705
|
+
```accordion
|
|
1706
|
+
title: Your title here
|
|
1707
|
+
expanded: true
|
|
1708
|
+
level: 2
|
|
1709
|
+
duration: 0.4s
|
|
1710
|
+
group: my-group
|
|
1711
|
+
id: my-anchor
|
|
1712
|
+
icon: ➤
|
|
1713
|
+
---
|
|
1714
|
+
Content goes here.
|
|
1404
1715
|
```
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
- `
|
|
1410
|
-
- `
|
|
1411
|
-
- `
|
|
1412
|
-
- `duration` (string): Custom animation duration
|
|
1716
|
+
`````
|
|
1717
|
+
|
|
1718
|
+
Available front matter properties:
|
|
1719
|
+
|
|
1720
|
+
- `title` (string): Accordion header text (supports inline markdown; raw HTML tags are escaped)
|
|
1721
|
+
- `expanded` (true/yes/1 or false): Initial open state
|
|
1722
|
+
- `level` (1-6): Heading level (clamped to 1-6)
|
|
1723
|
+
- `duration` (string): Custom animation duration; falls back to the extension's `animationDuration` option
|
|
1724
|
+
- `easing` (string): Custom animation timing function; falls back to the extension's `animationEasing` option
|
|
1725
|
+
- `group` (string): Exclusive group — maps to `<details name="...">` for native mutual exclusion
|
|
1726
|
+
- `id` (string): Custom element id for stable anchor links; auto-generated when omitted
|
|
1727
|
+
- `icon` (string): Character or emoji rendered around the title in an `aria-hidden` span
|
|
1728
|
+
- `iconPosition` (`before`/`after`): Icon placement relative to the title; falls back to the `iconPosition` option
|
|
1729
|
+
- `variant` (string): Named variant (`note`/`tip`/`important`/`warning`/`caution`, or a custom one) supplying a baked-in
|
|
1730
|
+
icon; an explicit `icon` overrides it
|
|
1731
|
+
- `class` (string): Extra CSS class(es) appended to the container element
|
|
1732
|
+
- `data-*` (string): Any `data-*` key is emitted as an escaped attribute on the `<details>` element
|
|
1413
1733
|
|
|
1414
1734
|
### Real-World Use Cases
|
|
1415
1735
|
|
|
1416
1736
|
#### 1. **FAQ Pages**
|
|
1417
1737
|
|
|
1418
|
-
Create expandable frequently asked questions:
|
|
1738
|
+
Create expandable frequently asked questions with native exclusive groups:
|
|
1419
1739
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1740
|
+
`````markdown
|
|
1741
|
+
```accordion
|
|
1742
|
+
title: What is Marked.js?
|
|
1743
|
+
group: faq
|
|
1744
|
+
expanded: true
|
|
1745
|
+
---
|
|
1422
1746
|
Marked.js is a fast, lightweight markdown parser and compiler. It's built for speed and extensibility.
|
|
1423
|
-
|
|
1747
|
+
```
|
|
1424
1748
|
|
|
1425
|
-
|
|
1749
|
+
```accordion
|
|
1750
|
+
title: How do I install extensions?
|
|
1751
|
+
group: faq
|
|
1752
|
+
---
|
|
1426
1753
|
Use your preferred package manager:
|
|
1427
1754
|
\`\`\`bash
|
|
1428
1755
|
bun add @fsegurai/marked-extended-accordion
|
|
1429
1756
|
\`\`\`
|
|
1430
|
-
|
|
1757
|
+
```
|
|
1431
1758
|
|
|
1432
|
-
|
|
1759
|
+
```accordion
|
|
1760
|
+
title: Is it free to use?
|
|
1761
|
+
group: faq
|
|
1762
|
+
---
|
|
1433
1763
|
Yes! This extension is MIT licensed and completely free for commercial and personal use.
|
|
1434
|
-
::::accordionend
|
|
1435
1764
|
```
|
|
1765
|
+
`````
|
|
1436
1766
|
|
|
1437
1767
|
#### 2. **Documentation Sections**
|
|
1438
1768
|
|
|
1439
1769
|
Organize API documentation or technical guides:
|
|
1440
1770
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1771
|
+
`````markdown
|
|
1772
|
+
```accordion
|
|
1773
|
+
title: API Authentication
|
|
1774
|
+
level: 2
|
|
1775
|
+
---
|
|
1444
1776
|
## Overview
|
|
1445
1777
|
|
|
1446
1778
|
The API uses OAuth 2.0 for authentication.
|
|
@@ -1456,22 +1788,29 @@ The API uses OAuth 2.0 for authentication.
|
|
|
1456
1788
|
\`\`\`javascript
|
|
1457
1789
|
const token = await getAccessToken(clientId, clientSecret);
|
|
1458
1790
|
\`\`\`
|
|
1459
|
-
::::accordionend
|
|
1460
1791
|
```
|
|
1792
|
+
`````
|
|
1461
1793
|
|
|
1462
1794
|
#### 3. **Interactive Tutorials**
|
|
1463
1795
|
|
|
1464
1796
|
Create step-by-step learning experiences:
|
|
1465
1797
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1798
|
+
`````markdown
|
|
1799
|
+
```accordion
|
|
1800
|
+
title: Step 1: Installation
|
|
1801
|
+
expanded: true
|
|
1802
|
+
level: 3
|
|
1803
|
+
---
|
|
1468
1804
|
First, install the required packages:
|
|
1469
1805
|
\`\`\`bash
|
|
1470
1806
|
npm install marked @fsegurai/marked-extended-accordion
|
|
1471
1807
|
\`\`\`
|
|
1472
|
-
|
|
1808
|
+
```
|
|
1473
1809
|
|
|
1474
|
-
|
|
1810
|
+
```accordion
|
|
1811
|
+
title: Step 2: Configuration
|
|
1812
|
+
level: 3
|
|
1813
|
+
---
|
|
1475
1814
|
Configure the extension in your code:
|
|
1476
1815
|
\`\`\`javascript
|
|
1477
1816
|
import { marked } from 'marked';
|
|
@@ -1479,61 +1818,75 @@ import markedExtendedAccordion from '@fsegurai/marked-extended-accordion';
|
|
|
1479
1818
|
|
|
1480
1819
|
marked.use(markedExtendedAccordion());
|
|
1481
1820
|
\`\`\`
|
|
1482
|
-
::::accordionend
|
|
1483
1821
|
```
|
|
1822
|
+
`````
|
|
1484
1823
|
|
|
1485
1824
|
#### 4. **Product Features**
|
|
1486
1825
|
|
|
1487
1826
|
Showcase product capabilities in an organized manner:
|
|
1488
1827
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1828
|
+
`````markdown
|
|
1829
|
+
```accordion
|
|
1830
|
+
title: 🚀 Performance Features
|
|
1831
|
+
---
|
|
1492
1832
|
- Lightning-fast parsing
|
|
1493
1833
|
- Minimal bundle size
|
|
1494
1834
|
- Optimized rendering
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
::::accordion{title="🎨 Customization Options"}
|
|
1835
|
+
```
|
|
1498
1836
|
|
|
1837
|
+
```accordion
|
|
1838
|
+
title: 🎨 Customization Options
|
|
1839
|
+
---
|
|
1499
1840
|
- Custom themes
|
|
1500
1841
|
- CSS variables
|
|
1501
1842
|
- Template overrides
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
::::accordion{title="♿ Accessibility"}
|
|
1843
|
+
```
|
|
1505
1844
|
|
|
1845
|
+
```accordion
|
|
1846
|
+
title: ♿ Accessibility
|
|
1847
|
+
---
|
|
1506
1848
|
- WCAG 2.1 compliant
|
|
1507
1849
|
- Screen reader support
|
|
1508
1850
|
- Keyboard navigation
|
|
1509
|
-
::::accordionend
|
|
1510
1851
|
```
|
|
1852
|
+
`````
|
|
1511
1853
|
|
|
1512
1854
|
#### 5. **Privacy Policies & Legal Documents**
|
|
1513
1855
|
|
|
1514
1856
|
Make long documents more digestible:
|
|
1515
1857
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1858
|
+
`````markdown
|
|
1859
|
+
```accordion
|
|
1860
|
+
title: 1. Information We Collect
|
|
1861
|
+
level: 2
|
|
1862
|
+
---
|
|
1518
1863
|
We collect information you provide directly to us...
|
|
1519
|
-
|
|
1864
|
+
```
|
|
1520
1865
|
|
|
1521
|
-
|
|
1866
|
+
```accordion
|
|
1867
|
+
title: 2. How We Use Your Information
|
|
1868
|
+
level: 2
|
|
1869
|
+
---
|
|
1522
1870
|
We use the information we collect to...
|
|
1523
|
-
|
|
1871
|
+
```
|
|
1524
1872
|
|
|
1525
|
-
|
|
1873
|
+
```accordion
|
|
1874
|
+
title: 3. Information Sharing
|
|
1875
|
+
level: 2
|
|
1876
|
+
---
|
|
1526
1877
|
We may share your information in the following circumstances...
|
|
1527
|
-
::::accordionend
|
|
1528
1878
|
```
|
|
1879
|
+
`````
|
|
1529
1880
|
|
|
1530
1881
|
#### 6. **Release Notes / Changelogs**
|
|
1531
1882
|
|
|
1532
1883
|
Organize version history:
|
|
1533
1884
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1885
|
+
`````markdown
|
|
1886
|
+
```accordion
|
|
1887
|
+
title: Version 2.0.0 - January 2024
|
|
1888
|
+
expanded: true
|
|
1889
|
+
---
|
|
1537
1890
|
### Breaking Changes
|
|
1538
1891
|
|
|
1539
1892
|
- Removed deprecated API methods
|
|
@@ -1546,51 +1899,65 @@ Organize version history:
|
|
|
1546
1899
|
### Bug Fixes
|
|
1547
1900
|
|
|
1548
1901
|
- Fixed animation glitches
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
::::accordion{title="Version 1.5.0 - December 2023"}
|
|
1902
|
+
```
|
|
1552
1903
|
|
|
1904
|
+
```accordion
|
|
1905
|
+
title: Version 1.5.0 - December 2023
|
|
1906
|
+
---
|
|
1553
1907
|
### New Features
|
|
1554
1908
|
|
|
1555
1909
|
- Added dark mode support
|
|
1556
|
-
::::accordionend
|
|
1557
1910
|
```
|
|
1911
|
+
`````
|
|
1558
1912
|
|
|
1559
1913
|
#### 7. **Course Curriculum**
|
|
1560
1914
|
|
|
1561
1915
|
Structure educational content:
|
|
1562
1916
|
|
|
1563
|
-
|
|
1564
|
-
|
|
1917
|
+
````markdown
|
|
1918
|
+
````accordion
|
|
1919
|
+
title: Week 1: Introduction to JavaScript
|
|
1920
|
+
level: 2
|
|
1921
|
+
---
|
|
1565
1922
|
|
|
1566
|
-
|
|
1923
|
+
```accordion
|
|
1924
|
+
title: Lesson 1.1: Variables and Data Types
|
|
1925
|
+
level: 3
|
|
1926
|
+
---
|
|
1567
1927
|
Learn about var, let, and const...
|
|
1568
|
-
|
|
1928
|
+
```
|
|
1569
1929
|
|
|
1570
|
-
|
|
1930
|
+
```accordion
|
|
1931
|
+
title: Lesson 1.2: Functions
|
|
1932
|
+
level: 3
|
|
1933
|
+
---
|
|
1571
1934
|
Understanding function declarations...
|
|
1572
|
-
::::accordionend
|
|
1573
|
-
|
|
1574
|
-
::::accordionend
|
|
1575
1935
|
```
|
|
1936
|
+
````
|
|
1937
|
+
|
|
1938
|
+
````
|
|
1576
1939
|
|
|
1577
1940
|
#### 8. **Troubleshooting Guides**
|
|
1578
1941
|
|
|
1579
1942
|
Organize problem-solution pairs:
|
|
1580
1943
|
|
|
1581
|
-
|
|
1582
|
-
|
|
1944
|
+
`````markdown
|
|
1945
|
+
```accordion
|
|
1946
|
+
title: Installation Issues
|
|
1947
|
+
---
|
|
1583
1948
|
**Problem**: Package fails to install
|
|
1584
1949
|
|
|
1585
1950
|
**Solution**: Clear your package manager cache...
|
|
1586
|
-
|
|
1951
|
+
```
|
|
1587
1952
|
|
|
1588
|
-
|
|
1953
|
+
```accordion
|
|
1954
|
+
title: Build Errors
|
|
1955
|
+
---
|
|
1589
1956
|
**Problem**: Build fails with TypeScript errors
|
|
1590
1957
|
|
|
1591
1958
|
**Solution**: Update your tsconfig.json...
|
|
1592
|
-
::::accordionend
|
|
1593
1959
|
```
|
|
1960
|
+
`````
|
|
1594
1961
|
|
|
1595
1962
|
### Contributing
|
|
1596
1963
|
|