jupyterlab_github_markdown_alerts_extension 1.0.20 → 1.0.21

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.md CHANGED
@@ -6,6 +6,9 @@
6
6
  [![Total PyPI downloads](https://static.pepy.tech/badge/jupyterlab-github-markdown-alerts-extension)](https://pepy.tech/project/jupyterlab-github-markdown-alerts-extension)
7
7
  [![JupyterLab 4](https://img.shields.io/badge/JupyterLab-4-orange.svg)](https://jupyterlab.readthedocs.io/en/stable/)
8
8
 
9
+ > [!TIP]
10
+ > This extension is part of the [stellars_jupyterlab_extensions](https://github.com/stellarshenson/stellars_jupyterlab_extensions) metapackage. Install all Stellars extensions at once: `pip install stellars_jupyterlab_extensions`
11
+
9
12
  A JupyterLab 4 extension that renders GitHub-style alert blocks in Markdown cells, providing visual emphasis for notes, tips, warnings, and other important information.
10
13
 
11
14
  This extension brings GitHub's alert syntax to JupyterLab, allowing you to create styled callout blocks using simple markdown notation. Alerts automatically adapt to light and dark themes, matching GitHub's visual design.
package/lib/index.js CHANGED
@@ -34,12 +34,26 @@ const plugin = {
34
34
  };
35
35
  loadSettings();
36
36
  }
37
- const originalRender = markdownParser.render.bind(markdownParser);
38
- markdownParser.render = async (content) => {
39
- const processedContent = processAlerts(content);
40
- const renderedHtml = await originalRender(processedContent);
41
- return postProcessAlerts(renderedHtml, showBackgrounds);
42
- };
37
+ // Idempotent: never re-wrap on re-activation, otherwise originalRender
38
+ // would capture an already-wrapped function
39
+ if (!markdownParser.render.__alertsWrapped) {
40
+ const originalRender = markdownParser.render.bind(markdownParser);
41
+ const wrappedRender = async (content) => {
42
+ try {
43
+ const processedContent = processAlerts(content);
44
+ const renderedHtml = await originalRender(processedContent);
45
+ return postProcessAlerts(renderedHtml, showBackgrounds);
46
+ }
47
+ catch (reason) {
48
+ // Degrade to plain Markdown instead of rejecting render, which
49
+ // would push rendermime into an un-highlighted fallback
50
+ console.error('jupyterlab_github_markdown_alerts_extension: render failed, falling back to plain markdown', reason);
51
+ return originalRender(content);
52
+ }
53
+ };
54
+ wrappedRender.__alertsWrapped = true;
55
+ markdownParser.render = wrappedRender;
56
+ }
43
57
  console.log('JupyterLab extension jupyterlab_github_markdown_alerts_extension is activated!');
44
58
  }
45
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyterlab_github_markdown_alerts_extension",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Jupyterlab extension to render alerts tips like they are rendered in github in markdown",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -60,7 +60,9 @@ describe('processAlerts', () => {
60
60
  > | Cell 1 | Cell 2 |`;
61
61
  const result = processAlerts(input);
62
62
  // Tables require consecutive lines - single newlines between rows
63
- expect(result).toContain('| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |');
63
+ expect(result).toContain(
64
+ '| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |'
65
+ );
64
66
  });
65
67
 
66
68
  it('should not insert blank lines between table rows', () => {
@@ -94,7 +96,9 @@ describe('processAlerts', () => {
94
96
  >
95
97
  > Paragraph three.`;
96
98
  const result = processAlerts(input);
97
- expect(result).toContain('Paragraph one.\n\nParagraph two.\n\nParagraph three.');
99
+ expect(result).toContain(
100
+ 'Paragraph one.\n\nParagraph two.\n\nParagraph three.'
101
+ );
98
102
  });
99
103
  });
100
104
 
@@ -197,7 +201,8 @@ describe('postProcessAlerts', () => {
197
201
  });
198
202
 
199
203
  it('should add background class when showBackgrounds is true', () => {
200
- const input = '<!--ALERT_START:WARNING-->Warning content<!--ALERT_END:WARNING-->';
204
+ const input =
205
+ '<!--ALERT_START:WARNING-->Warning content<!--ALERT_END:WARNING-->';
201
206
  const result = postProcessAlerts(input, true);
202
207
  expect(result).toContain('markdown-alert-with-backgrounds');
203
208
  });
package/src/index.ts CHANGED
@@ -52,13 +52,29 @@ const plugin: JupyterFrontEndPlugin<void> = {
52
52
  loadSettings();
53
53
  }
54
54
 
55
- const originalRender = markdownParser.render.bind(markdownParser);
55
+ // Idempotent: never re-wrap on re-activation, otherwise originalRender
56
+ // would capture an already-wrapped function
57
+ if (!(markdownParser.render as any).__alertsWrapped) {
58
+ const originalRender = markdownParser.render.bind(markdownParser);
56
59
 
57
- markdownParser.render = async (content: string): Promise<string> => {
58
- const processedContent = processAlerts(content);
59
- const renderedHtml = await originalRender(processedContent);
60
- return postProcessAlerts(renderedHtml, showBackgrounds);
61
- };
60
+ const wrappedRender = async (content: string): Promise<string> => {
61
+ try {
62
+ const processedContent = processAlerts(content);
63
+ const renderedHtml = await originalRender(processedContent);
64
+ return postProcessAlerts(renderedHtml, showBackgrounds);
65
+ } catch (reason) {
66
+ // Degrade to plain Markdown instead of rejecting render, which
67
+ // would push rendermime into an un-highlighted fallback
68
+ console.error(
69
+ 'jupyterlab_github_markdown_alerts_extension: render failed, falling back to plain markdown',
70
+ reason
71
+ );
72
+ return originalRender(content);
73
+ }
74
+ };
75
+ (wrappedRender as any).__alertsWrapped = true;
76
+ markdownParser.render = wrappedRender;
77
+ }
62
78
 
63
79
  console.log(
64
80
  'JupyterLab extension jupyterlab_github_markdown_alerts_extension is activated!'
package/style/base.css CHANGED
@@ -173,47 +173,47 @@ body[data-jp-theme-light='false']
173
173
 
174
174
  /* Optional backgrounds (enabled via settings) */
175
175
  .markdown-alert-with-backgrounds.markdown-alert-note {
176
- background-color: rgba(9, 105, 218, 0.1);
176
+ background-color: rgb(9 105 218 / 10%);
177
177
  }
178
178
 
179
179
  .markdown-alert-with-backgrounds.markdown-alert-tip {
180
- background-color: rgba(26, 127, 55, 0.1);
180
+ background-color: rgb(26 127 55 / 10%);
181
181
  }
182
182
 
183
183
  .markdown-alert-with-backgrounds.markdown-alert-important {
184
- background-color: rgba(130, 80, 223, 0.1);
184
+ background-color: rgb(130 80 223 / 10%);
185
185
  }
186
186
 
187
187
  .markdown-alert-with-backgrounds.markdown-alert-warning {
188
- background-color: rgba(154, 103, 0, 0.1);
188
+ background-color: rgb(154 103 0 / 10%);
189
189
  }
190
190
 
191
191
  .markdown-alert-with-backgrounds.markdown-alert-caution {
192
- background-color: rgba(209, 36, 47, 0.1);
192
+ background-color: rgb(209 36 47 / 10%);
193
193
  }
194
194
 
195
195
  /* Dark theme backgrounds */
196
196
  body[data-jp-theme-light='false']
197
197
  .markdown-alert-with-backgrounds.markdown-alert-note {
198
- background-color: rgba(47, 129, 247, 0.15);
198
+ background-color: rgb(47 129 247 / 15%);
199
199
  }
200
200
 
201
201
  body[data-jp-theme-light='false']
202
202
  .markdown-alert-with-backgrounds.markdown-alert-tip {
203
- background-color: rgba(63, 185, 80, 0.15);
203
+ background-color: rgb(63 185 80 / 15%);
204
204
  }
205
205
 
206
206
  body[data-jp-theme-light='false']
207
207
  .markdown-alert-with-backgrounds.markdown-alert-important {
208
- background-color: rgba(163, 113, 247, 0.15);
208
+ background-color: rgb(163 113 247 / 15%);
209
209
  }
210
210
 
211
211
  body[data-jp-theme-light='false']
212
212
  .markdown-alert-with-backgrounds.markdown-alert-warning {
213
- background-color: rgba(210, 153, 34, 0.15);
213
+ background-color: rgb(210 153 34 / 15%);
214
214
  }
215
215
 
216
216
  body[data-jp-theme-light='false']
217
217
  .markdown-alert-with-backgrounds.markdown-alert-caution {
218
- background-color: rgba(248, 81, 73, 0.15);
218
+ background-color: rgb(248 81 73 / 15%);
219
219
  }