markdown-it-admon-collapsible 1.9.3 → 1.9.4

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/CHANGELOG.md CHANGED
@@ -11,3 +11,10 @@
11
11
  2025-12-27
12
12
 
13
13
  - Changed the generated HTML to be more like markdown-it-container
14
+
15
+ ## 1.9.4
16
+
17
+ 2025-12-27
18
+
19
+ - Reverted since the previous change was a misunderstanding
20
+ - Using details/summary for collapsible admonitions
package/index.js CHANGED
@@ -44,27 +44,10 @@ function validate (params) {
44
44
  return !!tag
45
45
  }
46
46
 
47
-
48
47
  function renderDefault(tokens, idx, _options, env, slf) {
49
48
  return slf.renderToken(tokens, idx, _options, env, slf);
50
49
  }
51
50
 
52
- function renderCollapsibleOpen(tokens, idx) {
53
- const token = tokens[idx];
54
- const classes = token.attrs ? token.attrs.find(a => a[0] === 'class')[1] : '';
55
- return `<div class="${classes}">\n`;
56
- }
57
-
58
- function renderCollapsibleTitleOpen(tokens, idx) {
59
- const expanded = tokens[idx - 1]?.meta?.expanded;
60
- // Add toggle button
61
- return `<div class="admonition-title"><button class="collapsible-toggle" tabindex="0">${expanded ? '&#x2212;' : '&#x2b;'}</button>`;
62
- }
63
-
64
- function renderCollapsibleTitleClose() {
65
- return '</div>\n';
66
- }
67
-
68
51
  function renderCollapsibleContentOpen(tokens, idx) {
69
52
  return '';
70
53
  }
@@ -73,14 +56,12 @@ function renderCollapsibleContentClose() {
73
56
  return '';
74
57
  }
75
58
 
76
-
77
59
  const minMarkers = 3;
78
60
  const markerTypes = [
79
61
  { str: '!', type: 'admonition' },
80
62
  { str: '?', type: 'collapsible' }
81
63
  ];
82
64
 
83
-
84
65
  function admonition(state, startLine, endLine, silent) {
85
66
  let pos, nextLine, token;
86
67
  const start = state.bMarks[startLine] + state.tShift[startLine];
@@ -155,10 +136,13 @@ function admonition(state, startLine, endLine, silent) {
155
136
  const openType = isCollapsible ? 'collapsible_open' : 'admonition_open';
156
137
  const closeType = isCollapsible ? 'collapsible_close' : 'admonition_close';
157
138
 
158
- token = state.push(openType, 'div', 1);
139
+ token = isCollapsible ? state.push(openType, 'details', 1) : state.push(openType, 'div', 1)
159
140
  token.markup = markup;
160
141
  token.block = true;
161
- token.attrs = [['class', `admonition ${tag}${isCollapsible ? ' collapsible' : ''}${expanded ? ' expanded' : ''}`]];
142
+ token.attrs = [['class', `admonition ${tag}`]];
143
+ if (expanded) {
144
+ token.attrs.push(['open', '']);
145
+ }
162
146
  token.meta = { tag, expanded };
163
147
  token.content = title;
164
148
  token.info = params;
@@ -166,7 +150,7 @@ function admonition(state, startLine, endLine, silent) {
166
150
 
167
151
  if (title) {
168
152
  const titleMarkup = markup + ' ' + tag;
169
- token = state.push(isCollapsible ? 'collapsible_title_open' : 'admonition_title_open', 'div', 1);
153
+ token = isCollapsible ? state.push('collapsible_title_open', 'summary', 1) : state.push('admonition_title_open', 'p', 1)
170
154
  token.markup = titleMarkup;
171
155
  token.attrs = [['class', 'admonition-title']];
172
156
  token.map = [startLine, startLine + 1];
@@ -176,7 +160,7 @@ function admonition(state, startLine, endLine, silent) {
176
160
  token.map = [startLine, startLine + 1];
177
161
  token.children = [];
178
162
 
179
- token = state.push(isCollapsible ? 'collapsible_title_close' : 'admonition_title_close', 'div', -1);
163
+ token = isCollapsible ? state.push('collapsible_title_close', 'summary', -1) : state.push('admonition_title_close', 'p', -1);
180
164
  token.markup = titleMarkup;
181
165
  }
182
166
 
@@ -203,10 +187,9 @@ module.exports = function admonitionPlugin(md, options = {}) {
203
187
  md.renderer.rules.admonition_title_close = render;
204
188
 
205
189
  // Collapsible rendering
206
- md.renderer.rules.collapsible_open = renderCollapsibleOpen;
207
- md.renderer.rules.collapsible_close = (tokens, idx) => '</div>\n';
208
- md.renderer.rules.collapsible_title_open = renderCollapsibleTitleOpen;
209
- md.renderer.rules.collapsible_title_close = renderCollapsibleTitleClose;
190
+ // Use default renderer for collapsible_open/close
191
+ md.renderer.rules.collapsible_close = (tokens, idx) => '</details>\n';
192
+ // Use default renderer for collapsible_title_open/close
210
193
 
211
194
  // Wrap content in collapsible-content div
212
195
  const origBlockTokenize = md.block.tokenize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-it-admon-collapsible",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "description": "Plugin to create admonitions for markdown-it markdown parser",
5
5
  "keywords": [
6
6
  "admonition",
@@ -1,40 +1,38 @@
1
- /* Collapsible block styles */
2
- .collapsible {
3
- border-left-color: #888;
1
+
2
+ summary.admonition-title {
4
3
  position: relative;
5
4
  }
6
- .collapsible .admonition-title {
7
- cursor: pointer;
8
- user-select: none;
9
- padding-right: 2.5rem;
10
- }
11
- .collapsible .admonition-title {
12
- position: relative;
5
+ summary.admonition-title::marker {
6
+ content: none;
13
7
  }
14
- .collapsible .collapsible-toggle {
15
- position: absolute;
16
- right: 1.2rem;
17
- top: 50%;
18
- transform: translateY(-50%);
19
- font-size: 1.2rem;
20
- background: none;
21
- border: none;
22
- cursor: pointer;
23
- outline: none;
24
- margin: 0;
25
- padding: 0;
26
- line-height: 1;
8
+ summary.admonition-title::after {
9
+ content: '▶';
27
10
  }
28
- .collapsible.expanded {
29
- /* Optionally highlight expanded state */
11
+ summary.admonition-title::after {
12
+ position: absolute;
13
+ right: 0.5rem;
14
+ }
15
+ [open] summary.admonition-title::after {
16
+ transform: rotate(90deg);
17
+ transform-origin: 50% 50%;
30
18
  }
31
19
 
32
- /* Hide all siblings of .admonition-title when not expanded */
33
- .collapsible:not(.expanded) > .admonition-title ~ * {
34
- display: none;
20
+ /* Collapsible block styles using <details> and <summary> */
21
+ details.admonition {
22
+ border-left-color: #888;
23
+ position: relative;
35
24
  }
36
- .collapsible.expanded > .admonition-title ~ * {
37
- display: block;
25
+ summary.admonition-title {
26
+ cursor: pointer;
27
+ user-select: none;
28
+ position: relative;
29
+ padding-right: 2.5rem;
30
+ margin: 0 -1.2rem;
31
+ padding: .8rem 1.0rem .8rem 1.0rem;
32
+ border-bottom: 1px solid rgba(68, 138, 255, .2);
33
+ background-color: rgba(68, 138, 255, .1);
34
+ font-weight: 700;
35
+ list-style: none;
38
36
  }
39
37
  /**
40
38
  * @credits https://github.com/qjebbs/vscode-markdown-extended