jupyterlab_github_markdown_alerts_extension 1.0.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/LICENSE +29 -0
- package/README.md +157 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +168 -0
- package/package.json +197 -0
- package/src/__tests__/jupyterlab_github_markdown_alerts_extension.spec.ts +9 -0
- package/src/index.ts +246 -0
- package/style/base.css +189 -0
- package/style/index.css +1 -0
- package/style/index.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Stellars Henson
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# JupyterLab GitHub Markdown Alerts Extension
|
|
2
|
+
|
|
3
|
+
[](/actions/workflows/build.yml)
|
|
4
|
+
|
|
5
|
+
A JupyterLab 4 extension that renders GitHub-style alert blocks in Markdown cells, providing visual emphasis for notes, tips, warnings, and other important information.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
**Key Features**:
|
|
10
|
+
- Five alert types - NOTE, TIP, IMPORTANT, WARNING, CAUTION
|
|
11
|
+
- Automatic theme adaptation - colors adjust for light and dark modes
|
|
12
|
+
- GitHub-compatible syntax - works with standard GitHub markdown alert notation
|
|
13
|
+
- Icon integration - each alert type displays with its corresponding icon
|
|
14
|
+
- Zero configuration - works immediately after installation
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- JupyterLab >= 4.0.0
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Create alert blocks in markdown cells using GitHub's alert syntax. Start with a blockquote containing the alert type, followed by content lines:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
> [!NOTE]
|
|
26
|
+
> Useful information that users should know, even when skimming content.
|
|
27
|
+
|
|
28
|
+
> [!TIP]
|
|
29
|
+
> Helpful advice for doing things better or more easily.
|
|
30
|
+
|
|
31
|
+
> [!IMPORTANT]
|
|
32
|
+
> Key information users need to know to achieve their goal.
|
|
33
|
+
|
|
34
|
+
> [!WARNING]
|
|
35
|
+
> Urgent info that needs immediate user attention to avoid problems.
|
|
36
|
+
|
|
37
|
+
> [!CAUTION]
|
|
38
|
+
> Advises about risks or negative outcomes of certain actions.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each alert type renders with distinct colors and icons matching GitHub's design. Multi-line content is supported by continuing the blockquote format.
|
|
42
|
+
|
|
43
|
+
**Alert Examples**:
|
|
44
|
+
|
|
45
|
+
> [!NOTE]
|
|
46
|
+
> Useful information that users should know, even when skimming content.
|
|
47
|
+
|
|
48
|
+
> [!TIP]
|
|
49
|
+
> Helpful advice for doing things better or more easily.
|
|
50
|
+
|
|
51
|
+
> [!IMPORTANT]
|
|
52
|
+
> Key information users need to know to achieve their goal.
|
|
53
|
+
|
|
54
|
+
> [!WARNING]
|
|
55
|
+
> Urgent info that needs immediate user attention to avoid problems.
|
|
56
|
+
|
|
57
|
+
> [!CAUTION]
|
|
58
|
+
> Advises about risks or negative outcomes of certain actions.
|
|
59
|
+
|
|
60
|
+
## Settings
|
|
61
|
+
|
|
62
|
+
The extension provides optional settings accessible through JupyterLab's Settings Editor:
|
|
63
|
+
|
|
64
|
+
- **Show Alert Backgrounds** - Enable subtle colored backgrounds for alerts (disabled by default to match GitHub exactly)
|
|
65
|
+
|
|
66
|
+
To access settings: Settings → Settings Editor → GitHub Markdown Alerts
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install jupyterlab_github_markdown_alerts_extension
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Uninstall
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip uninstall jupyterlab_github_markdown_alerts_extension
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Contributing
|
|
81
|
+
|
|
82
|
+
### Development install
|
|
83
|
+
|
|
84
|
+
Note: You will need NodeJS to build the extension package.
|
|
85
|
+
|
|
86
|
+
The `jlpm` command is JupyterLab's pinned version of
|
|
87
|
+
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
|
|
88
|
+
`yarn` or `npm` in lieu of `jlpm` below.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Clone the repo to your local environment
|
|
92
|
+
# Change directory to the jupyterlab_github_markdown_alerts_extension directory
|
|
93
|
+
|
|
94
|
+
# Set up a virtual environment and install package in development mode
|
|
95
|
+
python -m venv .venv
|
|
96
|
+
source .venv/bin/activate
|
|
97
|
+
pip install --editable "."
|
|
98
|
+
|
|
99
|
+
# Link your development version of the extension with JupyterLab
|
|
100
|
+
jupyter labextension develop . --overwrite
|
|
101
|
+
|
|
102
|
+
# Rebuild extension Typescript source after making changes
|
|
103
|
+
# IMPORTANT: Unlike the steps above which are performed only once, do this step
|
|
104
|
+
# every time you make a change.
|
|
105
|
+
jlpm build
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Watch the source directory in one terminal, automatically rebuilding when needed
|
|
112
|
+
jlpm watch
|
|
113
|
+
# Run JupyterLab in another terminal
|
|
114
|
+
jupyter lab
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
|
|
118
|
+
|
|
119
|
+
By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
jupyter lab build --minimize=False
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Development uninstall
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip uninstall jupyterlab_github_markdown_alerts_extension
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
|
|
132
|
+
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
|
|
133
|
+
folder is located. Then you can remove the symlink named `jupyterlab_github_markdown_alerts_extension` within that folder.
|
|
134
|
+
|
|
135
|
+
### Testing the extension
|
|
136
|
+
|
|
137
|
+
#### Frontend tests
|
|
138
|
+
|
|
139
|
+
This extension is using [Jest](https://jestjs.io/) for JavaScript code testing.
|
|
140
|
+
|
|
141
|
+
To execute them, execute:
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
jlpm
|
|
145
|
+
jlpm test
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Integration tests
|
|
149
|
+
|
|
150
|
+
This extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).
|
|
151
|
+
More precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.
|
|
152
|
+
|
|
153
|
+
More information are provided within the [ui-tests](./ui-tests/README.md) README.
|
|
154
|
+
|
|
155
|
+
### Packaging the extension
|
|
156
|
+
|
|
157
|
+
See [RELEASE](RELEASE.md)
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { IMarkdownParser } from '@jupyterlab/rendermime';
|
|
2
|
+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
3
|
+
const ALERT_TYPES = {
|
|
4
|
+
NOTE: {
|
|
5
|
+
className: 'markdown-alert-note',
|
|
6
|
+
title: 'Note',
|
|
7
|
+
iconClass: 'octicon-info',
|
|
8
|
+
iconColor: '#0969da',
|
|
9
|
+
iconColorDark: '#2f81f7',
|
|
10
|
+
iconPath: 'M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'
|
|
11
|
+
},
|
|
12
|
+
TIP: {
|
|
13
|
+
className: 'markdown-alert-tip',
|
|
14
|
+
title: 'Tip',
|
|
15
|
+
iconClass: 'octicon-light-bulb',
|
|
16
|
+
iconColor: '#1a7f37',
|
|
17
|
+
iconColorDark: '#3fb950',
|
|
18
|
+
iconPath: 'M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z'
|
|
19
|
+
},
|
|
20
|
+
IMPORTANT: {
|
|
21
|
+
className: 'markdown-alert-important',
|
|
22
|
+
title: 'Important',
|
|
23
|
+
iconClass: 'octicon-report',
|
|
24
|
+
iconColor: '#8250df',
|
|
25
|
+
iconColorDark: '#a371f7',
|
|
26
|
+
iconPath: 'M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'
|
|
27
|
+
},
|
|
28
|
+
WARNING: {
|
|
29
|
+
className: 'markdown-alert-warning',
|
|
30
|
+
title: 'Warning',
|
|
31
|
+
iconClass: 'octicon-alert',
|
|
32
|
+
iconColor: '#9a6700',
|
|
33
|
+
iconColorDark: '#d29922',
|
|
34
|
+
iconPath: 'M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'
|
|
35
|
+
},
|
|
36
|
+
CAUTION: {
|
|
37
|
+
className: 'markdown-alert-caution',
|
|
38
|
+
title: 'Caution',
|
|
39
|
+
iconClass: 'octicon-stop',
|
|
40
|
+
iconColor: '#cf222e',
|
|
41
|
+
iconColorDark: '#f85149',
|
|
42
|
+
iconPath: 'M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Create SVG icon element as data URI with both light and dark theme versions
|
|
47
|
+
*/
|
|
48
|
+
function createIcon(iconPath, iconClass, iconColor, iconColorDark) {
|
|
49
|
+
// Create light theme icon
|
|
50
|
+
const svgContentLight = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="${iconColor}" d="${iconPath}"></path></svg>`;
|
|
51
|
+
const dataUriLight = `data:image/svg+xml;base64,${btoa(svgContentLight)}`;
|
|
52
|
+
// Create dark theme icon
|
|
53
|
+
const svgContentDark = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="${iconColorDark}" d="${iconPath}"></path></svg>`;
|
|
54
|
+
const dataUriDark = `data:image/svg+xml;base64,${btoa(svgContentDark)}`;
|
|
55
|
+
return (`<img src="${dataUriLight}" class="octicon ${iconClass} octicon-light mr-2" width="16" height="16" aria-hidden="true" alt="" />` +
|
|
56
|
+
`<img src="${dataUriDark}" class="octicon ${iconClass} octicon-dark mr-2" width="16" height="16" aria-hidden="true" alt="" />`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Process markdown text to convert GitHub-style alerts
|
|
60
|
+
*/
|
|
61
|
+
function processAlerts(text) {
|
|
62
|
+
const lines = text.split('\n');
|
|
63
|
+
const result = [];
|
|
64
|
+
let i = 0;
|
|
65
|
+
let inCodeBlock = false;
|
|
66
|
+
while (i < lines.length) {
|
|
67
|
+
const line = lines[i];
|
|
68
|
+
// Track code blocks (both ``` and ~~~)
|
|
69
|
+
if (line.trim().match(/^```|^~~~/)) {
|
|
70
|
+
inCodeBlock = !inCodeBlock;
|
|
71
|
+
result.push(line);
|
|
72
|
+
i++;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// Skip alert processing inside code blocks
|
|
76
|
+
if (inCodeBlock) {
|
|
77
|
+
result.push(line);
|
|
78
|
+
i++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const alertMatch = line.match(/^>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/);
|
|
82
|
+
if (alertMatch) {
|
|
83
|
+
const alertType = alertMatch[1];
|
|
84
|
+
const contentLines = [];
|
|
85
|
+
i++;
|
|
86
|
+
while (i < lines.length && lines[i].startsWith('>')) {
|
|
87
|
+
const content = lines[i].replace(/^>\s?/, '');
|
|
88
|
+
if (content) {
|
|
89
|
+
contentLines.push(content);
|
|
90
|
+
}
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
if (contentLines.length > 0) {
|
|
94
|
+
const content = contentLines.join('\n\n');
|
|
95
|
+
// Use HTML comments as markers that will survive markdown processing
|
|
96
|
+
result.push(`<!--ALERT_START:${alertType}-->`, content, `<!--ALERT_END:${alertType}-->`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
result.push(line);
|
|
101
|
+
i++;
|
|
102
|
+
}
|
|
103
|
+
return result.join('\n');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Post-process rendered HTML to wrap alert markers with styled divs
|
|
107
|
+
*/
|
|
108
|
+
function postProcessAlerts(html, showBackgrounds) {
|
|
109
|
+
// Replace alert markers with proper HTML structure
|
|
110
|
+
const result = html.replace(/<!--ALERT_START:(NOTE|TIP|IMPORTANT|WARNING|CAUTION)-->([\s\S]*?)<!--ALERT_END:\1-->/g, (match, alertType, content) => {
|
|
111
|
+
const config = ALERT_TYPES[alertType];
|
|
112
|
+
const icon = createIcon(config.iconPath, config.iconClass, config.iconColor, config.iconColorDark);
|
|
113
|
+
const backgroundClass = showBackgrounds
|
|
114
|
+
? ' markdown-alert-with-backgrounds'
|
|
115
|
+
: '';
|
|
116
|
+
const alertHtml = `<div class="markdown-alert ${config.className}${backgroundClass}" dir="auto">` +
|
|
117
|
+
`<p class="markdown-alert-title" dir="auto">${icon}${config.title}</p>` +
|
|
118
|
+
content +
|
|
119
|
+
`</div>`;
|
|
120
|
+
console.log('Alert HTML generated:', alertHtml);
|
|
121
|
+
return alertHtml;
|
|
122
|
+
});
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Initialization data for the jupyterlab_github_markdown_alerts_extension extension.
|
|
127
|
+
*/
|
|
128
|
+
const plugin = {
|
|
129
|
+
id: 'jupyterlab_github_markdown_alerts_extension:plugin',
|
|
130
|
+
description: 'Jupyterlab extension to render alerts tips like they are rendered in github in markdown',
|
|
131
|
+
autoStart: true,
|
|
132
|
+
requires: [IMarkdownParser],
|
|
133
|
+
optional: [ISettingRegistry],
|
|
134
|
+
activate: (app, markdownParser, settingRegistry) => {
|
|
135
|
+
let showBackgrounds = false;
|
|
136
|
+
// Load settings
|
|
137
|
+
if (settingRegistry) {
|
|
138
|
+
const loadSettings = () => {
|
|
139
|
+
settingRegistry
|
|
140
|
+
.load(plugin.id)
|
|
141
|
+
.then(settings => {
|
|
142
|
+
showBackgrounds = settings.get('showBackgrounds')
|
|
143
|
+
.composite;
|
|
144
|
+
settings.changed.connect(() => {
|
|
145
|
+
showBackgrounds = settings.get('showBackgrounds')
|
|
146
|
+
.composite;
|
|
147
|
+
});
|
|
148
|
+
})
|
|
149
|
+
.catch(reason => {
|
|
150
|
+
console.error('Failed to load settings for jupyterlab_github_markdown_alerts_extension', reason);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
loadSettings();
|
|
154
|
+
}
|
|
155
|
+
const originalRender = markdownParser.render.bind(markdownParser);
|
|
156
|
+
markdownParser.render = async (content) => {
|
|
157
|
+
const processedContent = processAlerts(content);
|
|
158
|
+
console.log('Processed content:', processedContent);
|
|
159
|
+
const renderedHtml = await originalRender(processedContent);
|
|
160
|
+
console.log('Rendered HTML:', renderedHtml);
|
|
161
|
+
const finalHtml = postProcessAlerts(renderedHtml, showBackgrounds);
|
|
162
|
+
console.log('Final HTML:', finalHtml);
|
|
163
|
+
return finalHtml;
|
|
164
|
+
};
|
|
165
|
+
console.log('JupyterLab extension jupyterlab_github_markdown_alerts_extension is activated!');
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
export default plugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jupyterlab_github_markdown_alerts_extension",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Jupyterlab extension to render alerts tips like they are rendered in github in markdown",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jupyter",
|
|
7
|
+
"jupyterlab",
|
|
8
|
+
"jupyterlab-extension"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/stellarshenson/jupyterlab_github_markdown_alerts_extension",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/stellarshenson/jupyterlab_github_markdown_alerts_extension/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "BSD-3-Clause",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Stellars Henson",
|
|
17
|
+
"email": "konrad.jelen@gmail.com"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
21
|
+
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
|
|
22
|
+
"src/**/*.{ts,tsx}"
|
|
23
|
+
],
|
|
24
|
+
"main": "lib/index.js",
|
|
25
|
+
"types": "lib/index.d.ts",
|
|
26
|
+
"style": "style/index.css",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/stellarshenson/jupyterlab_github_markdown_alerts_extension.git"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "jlpm build:lib && jlpm build:labextension:dev",
|
|
33
|
+
"build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension",
|
|
34
|
+
"build:labextension": "jupyter labextension build .",
|
|
35
|
+
"build:labextension:dev": "jupyter labextension build --development True .",
|
|
36
|
+
"build:lib": "tsc --sourceMap",
|
|
37
|
+
"build:lib:prod": "tsc",
|
|
38
|
+
"clean": "jlpm clean:lib",
|
|
39
|
+
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
|
|
40
|
+
"clean:lintcache": "rimraf .eslintcache .stylelintcache",
|
|
41
|
+
"clean:labextension": "rimraf jupyterlab_github_markdown_alerts_extension/labextension jupyterlab_github_markdown_alerts_extension/_version.py",
|
|
42
|
+
"clean:all": "jlpm clean:lib && jlpm clean:labextension && jlpm clean:lintcache",
|
|
43
|
+
"eslint": "jlpm eslint:check --fix",
|
|
44
|
+
"eslint:check": "eslint . --cache --ext .ts,.tsx",
|
|
45
|
+
"install:extension": "jlpm build",
|
|
46
|
+
"lint": "jlpm stylelint && jlpm prettier && jlpm eslint",
|
|
47
|
+
"lint:check": "jlpm stylelint:check && jlpm prettier:check && jlpm eslint:check",
|
|
48
|
+
"prettier": "jlpm prettier:base --write --list-different",
|
|
49
|
+
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
|
|
50
|
+
"prettier:check": "jlpm prettier:base --check",
|
|
51
|
+
"stylelint": "jlpm stylelint:check --fix",
|
|
52
|
+
"stylelint:check": "stylelint --cache \"style/**/*.css\"",
|
|
53
|
+
"test": "jest --coverage",
|
|
54
|
+
"watch": "run-p watch:src watch:labextension",
|
|
55
|
+
"watch:src": "tsc -w --sourceMap",
|
|
56
|
+
"watch:labextension": "jupyter labextension watch ."
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@jupyterlab/application": "^4.0.0",
|
|
60
|
+
"@jupyterlab/rendermime": "^4.0.0",
|
|
61
|
+
"@jupyterlab/settingregistry": "^4.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@jupyterlab/builder": "^4.0.0",
|
|
65
|
+
"@jupyterlab/testutils": "^4.0.0",
|
|
66
|
+
"@types/jest": "^29.2.0",
|
|
67
|
+
"@types/json-schema": "^7.0.11",
|
|
68
|
+
"@types/react": "^18.0.26",
|
|
69
|
+
"@types/react-addons-linked-state-mixin": "^0.14.22",
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
|
71
|
+
"@typescript-eslint/parser": "^6.1.0",
|
|
72
|
+
"css-loader": "^6.7.1",
|
|
73
|
+
"eslint": "^8.36.0",
|
|
74
|
+
"eslint-config-prettier": "^8.8.0",
|
|
75
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
76
|
+
"jest": "^29.2.0",
|
|
77
|
+
"npm-run-all2": "^7.0.1",
|
|
78
|
+
"prettier": "^3.0.0",
|
|
79
|
+
"rimraf": "^5.0.10",
|
|
80
|
+
"source-map-loader": "^1.0.2",
|
|
81
|
+
"style-loader": "^3.3.1",
|
|
82
|
+
"stylelint": "^15.10.1",
|
|
83
|
+
"stylelint-config-recommended": "^13.0.0",
|
|
84
|
+
"stylelint-config-standard": "^34.0.0",
|
|
85
|
+
"stylelint-csstree-validator": "^3.0.0",
|
|
86
|
+
"stylelint-prettier": "^4.0.0",
|
|
87
|
+
"typescript": "~5.8.0",
|
|
88
|
+
"yjs": "^13.5.0"
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": [
|
|
91
|
+
"style/*.css",
|
|
92
|
+
"style/index.js"
|
|
93
|
+
],
|
|
94
|
+
"styleModule": "style/index.js",
|
|
95
|
+
"publishConfig": {
|
|
96
|
+
"access": "public"
|
|
97
|
+
},
|
|
98
|
+
"jupyterlab": {
|
|
99
|
+
"extension": true,
|
|
100
|
+
"outputDir": "jupyterlab_github_markdown_alerts_extension/labextension",
|
|
101
|
+
"schemaDir": "schema"
|
|
102
|
+
},
|
|
103
|
+
"eslintIgnore": [
|
|
104
|
+
"node_modules",
|
|
105
|
+
"dist",
|
|
106
|
+
"coverage",
|
|
107
|
+
"**/*.d.ts",
|
|
108
|
+
"tests",
|
|
109
|
+
"**/__tests__",
|
|
110
|
+
"ui-tests"
|
|
111
|
+
],
|
|
112
|
+
"eslintConfig": {
|
|
113
|
+
"extends": [
|
|
114
|
+
"eslint:recommended",
|
|
115
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
116
|
+
"plugin:@typescript-eslint/recommended",
|
|
117
|
+
"plugin:prettier/recommended"
|
|
118
|
+
],
|
|
119
|
+
"parser": "@typescript-eslint/parser",
|
|
120
|
+
"parserOptions": {
|
|
121
|
+
"project": "tsconfig.json",
|
|
122
|
+
"sourceType": "module"
|
|
123
|
+
},
|
|
124
|
+
"plugins": [
|
|
125
|
+
"@typescript-eslint"
|
|
126
|
+
],
|
|
127
|
+
"rules": {
|
|
128
|
+
"@typescript-eslint/naming-convention": [
|
|
129
|
+
"error",
|
|
130
|
+
{
|
|
131
|
+
"selector": "interface",
|
|
132
|
+
"format": [
|
|
133
|
+
"PascalCase"
|
|
134
|
+
],
|
|
135
|
+
"custom": {
|
|
136
|
+
"regex": "^I[A-Z]",
|
|
137
|
+
"match": true
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"@typescript-eslint/no-unused-vars": [
|
|
142
|
+
"warn",
|
|
143
|
+
{
|
|
144
|
+
"args": "none"
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
148
|
+
"@typescript-eslint/no-namespace": "off",
|
|
149
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
150
|
+
"@typescript-eslint/quotes": [
|
|
151
|
+
"error",
|
|
152
|
+
"single",
|
|
153
|
+
{
|
|
154
|
+
"avoidEscape": true,
|
|
155
|
+
"allowTemplateLiterals": false
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"curly": [
|
|
159
|
+
"error",
|
|
160
|
+
"all"
|
|
161
|
+
],
|
|
162
|
+
"eqeqeq": "error",
|
|
163
|
+
"prefer-arrow-callback": "error"
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"prettier": {
|
|
167
|
+
"singleQuote": true,
|
|
168
|
+
"trailingComma": "none",
|
|
169
|
+
"arrowParens": "avoid",
|
|
170
|
+
"endOfLine": "auto",
|
|
171
|
+
"overrides": [
|
|
172
|
+
{
|
|
173
|
+
"files": "package.json",
|
|
174
|
+
"options": {
|
|
175
|
+
"tabWidth": 4
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
"stylelint": {
|
|
181
|
+
"extends": [
|
|
182
|
+
"stylelint-config-recommended",
|
|
183
|
+
"stylelint-config-standard",
|
|
184
|
+
"stylelint-prettier/recommended"
|
|
185
|
+
],
|
|
186
|
+
"plugins": [
|
|
187
|
+
"stylelint-csstree-validator"
|
|
188
|
+
],
|
|
189
|
+
"rules": {
|
|
190
|
+
"csstree/validator": true,
|
|
191
|
+
"property-no-vendor-prefix": null,
|
|
192
|
+
"selector-class-pattern": "^([a-z][A-z\\d]*)(-[A-z\\d]+)*$",
|
|
193
|
+
"selector-no-vendor-prefix": null,
|
|
194
|
+
"value-no-vendor-prefix": null
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JupyterFrontEnd,
|
|
3
|
+
JupyterFrontEndPlugin
|
|
4
|
+
} from '@jupyterlab/application';
|
|
5
|
+
|
|
6
|
+
import { IMarkdownParser } from '@jupyterlab/rendermime';
|
|
7
|
+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Alert type configuration
|
|
11
|
+
*/
|
|
12
|
+
interface IAlertConfig {
|
|
13
|
+
className: string;
|
|
14
|
+
title: string;
|
|
15
|
+
iconPath: string;
|
|
16
|
+
iconClass: string;
|
|
17
|
+
iconColor: string;
|
|
18
|
+
iconColorDark: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ALERT_TYPES: Record<string, IAlertConfig> = {
|
|
22
|
+
NOTE: {
|
|
23
|
+
className: 'markdown-alert-note',
|
|
24
|
+
title: 'Note',
|
|
25
|
+
iconClass: 'octicon-info',
|
|
26
|
+
iconColor: '#0969da',
|
|
27
|
+
iconColorDark: '#2f81f7',
|
|
28
|
+
iconPath:
|
|
29
|
+
'M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'
|
|
30
|
+
},
|
|
31
|
+
TIP: {
|
|
32
|
+
className: 'markdown-alert-tip',
|
|
33
|
+
title: 'Tip',
|
|
34
|
+
iconClass: 'octicon-light-bulb',
|
|
35
|
+
iconColor: '#1a7f37',
|
|
36
|
+
iconColorDark: '#3fb950',
|
|
37
|
+
iconPath:
|
|
38
|
+
'M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z'
|
|
39
|
+
},
|
|
40
|
+
IMPORTANT: {
|
|
41
|
+
className: 'markdown-alert-important',
|
|
42
|
+
title: 'Important',
|
|
43
|
+
iconClass: 'octicon-report',
|
|
44
|
+
iconColor: '#8250df',
|
|
45
|
+
iconColorDark: '#a371f7',
|
|
46
|
+
iconPath:
|
|
47
|
+
'M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'
|
|
48
|
+
},
|
|
49
|
+
WARNING: {
|
|
50
|
+
className: 'markdown-alert-warning',
|
|
51
|
+
title: 'Warning',
|
|
52
|
+
iconClass: 'octicon-alert',
|
|
53
|
+
iconColor: '#9a6700',
|
|
54
|
+
iconColorDark: '#d29922',
|
|
55
|
+
iconPath:
|
|
56
|
+
'M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'
|
|
57
|
+
},
|
|
58
|
+
CAUTION: {
|
|
59
|
+
className: 'markdown-alert-caution',
|
|
60
|
+
title: 'Caution',
|
|
61
|
+
iconClass: 'octicon-stop',
|
|
62
|
+
iconColor: '#cf222e',
|
|
63
|
+
iconColorDark: '#f85149',
|
|
64
|
+
iconPath:
|
|
65
|
+
'M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create SVG icon element as data URI with both light and dark theme versions
|
|
71
|
+
*/
|
|
72
|
+
function createIcon(
|
|
73
|
+
iconPath: string,
|
|
74
|
+
iconClass: string,
|
|
75
|
+
iconColor: string,
|
|
76
|
+
iconColorDark: string
|
|
77
|
+
): string {
|
|
78
|
+
// Create light theme icon
|
|
79
|
+
const svgContentLight = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="${iconColor}" d="${iconPath}"></path></svg>`;
|
|
80
|
+
const dataUriLight = `data:image/svg+xml;base64,${btoa(svgContentLight)}`;
|
|
81
|
+
|
|
82
|
+
// Create dark theme icon
|
|
83
|
+
const svgContentDark = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="${iconColorDark}" d="${iconPath}"></path></svg>`;
|
|
84
|
+
const dataUriDark = `data:image/svg+xml;base64,${btoa(svgContentDark)}`;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
`<img src="${dataUriLight}" class="octicon ${iconClass} octicon-light mr-2" width="16" height="16" aria-hidden="true" alt="" />` +
|
|
88
|
+
`<img src="${dataUriDark}" class="octicon ${iconClass} octicon-dark mr-2" width="16" height="16" aria-hidden="true" alt="" />`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Process markdown text to convert GitHub-style alerts
|
|
94
|
+
*/
|
|
95
|
+
function processAlerts(text: string): string {
|
|
96
|
+
const lines = text.split('\n');
|
|
97
|
+
const result: string[] = [];
|
|
98
|
+
let i = 0;
|
|
99
|
+
let inCodeBlock = false;
|
|
100
|
+
|
|
101
|
+
while (i < lines.length) {
|
|
102
|
+
const line = lines[i];
|
|
103
|
+
|
|
104
|
+
// Track code blocks (both ``` and ~~~)
|
|
105
|
+
if (line.trim().match(/^```|^~~~/)) {
|
|
106
|
+
inCodeBlock = !inCodeBlock;
|
|
107
|
+
result.push(line);
|
|
108
|
+
i++;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Skip alert processing inside code blocks
|
|
113
|
+
if (inCodeBlock) {
|
|
114
|
+
result.push(line);
|
|
115
|
+
i++;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const alertMatch = line.match(
|
|
120
|
+
/^>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (alertMatch) {
|
|
124
|
+
const alertType = alertMatch[1];
|
|
125
|
+
const contentLines: string[] = [];
|
|
126
|
+
|
|
127
|
+
i++;
|
|
128
|
+
while (i < lines.length && lines[i].startsWith('>')) {
|
|
129
|
+
const content = lines[i].replace(/^>\s?/, '');
|
|
130
|
+
if (content) {
|
|
131
|
+
contentLines.push(content);
|
|
132
|
+
}
|
|
133
|
+
i++;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (contentLines.length > 0) {
|
|
137
|
+
const content = contentLines.join('\n\n');
|
|
138
|
+
|
|
139
|
+
// Use HTML comments as markers that will survive markdown processing
|
|
140
|
+
result.push(
|
|
141
|
+
`<!--ALERT_START:${alertType}-->`,
|
|
142
|
+
content,
|
|
143
|
+
`<!--ALERT_END:${alertType}-->`
|
|
144
|
+
);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
result.push(line);
|
|
150
|
+
i++;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return result.join('\n');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Post-process rendered HTML to wrap alert markers with styled divs
|
|
158
|
+
*/
|
|
159
|
+
function postProcessAlerts(html: string, showBackgrounds: boolean): string {
|
|
160
|
+
// Replace alert markers with proper HTML structure
|
|
161
|
+
const result = html.replace(
|
|
162
|
+
/<!--ALERT_START:(NOTE|TIP|IMPORTANT|WARNING|CAUTION)-->([\s\S]*?)<!--ALERT_END:\1-->/g,
|
|
163
|
+
(match, alertType, content) => {
|
|
164
|
+
const config = ALERT_TYPES[alertType];
|
|
165
|
+
const icon = createIcon(
|
|
166
|
+
config.iconPath,
|
|
167
|
+
config.iconClass,
|
|
168
|
+
config.iconColor,
|
|
169
|
+
config.iconColorDark
|
|
170
|
+
);
|
|
171
|
+
const backgroundClass = showBackgrounds
|
|
172
|
+
? ' markdown-alert-with-backgrounds'
|
|
173
|
+
: '';
|
|
174
|
+
|
|
175
|
+
const alertHtml =
|
|
176
|
+
`<div class="markdown-alert ${config.className}${backgroundClass}" dir="auto">` +
|
|
177
|
+
`<p class="markdown-alert-title" dir="auto">${icon}${config.title}</p>` +
|
|
178
|
+
content +
|
|
179
|
+
`</div>`;
|
|
180
|
+
|
|
181
|
+
console.log('Alert HTML generated:', alertHtml);
|
|
182
|
+
return alertHtml;
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Initialization data for the jupyterlab_github_markdown_alerts_extension extension.
|
|
190
|
+
*/
|
|
191
|
+
const plugin: JupyterFrontEndPlugin<void> = {
|
|
192
|
+
id: 'jupyterlab_github_markdown_alerts_extension:plugin',
|
|
193
|
+
description:
|
|
194
|
+
'Jupyterlab extension to render alerts tips like they are rendered in github in markdown',
|
|
195
|
+
autoStart: true,
|
|
196
|
+
requires: [IMarkdownParser],
|
|
197
|
+
optional: [ISettingRegistry],
|
|
198
|
+
activate: (
|
|
199
|
+
app: JupyterFrontEnd,
|
|
200
|
+
markdownParser: IMarkdownParser,
|
|
201
|
+
settingRegistry: ISettingRegistry | null
|
|
202
|
+
) => {
|
|
203
|
+
let showBackgrounds = false;
|
|
204
|
+
|
|
205
|
+
// Load settings
|
|
206
|
+
if (settingRegistry) {
|
|
207
|
+
const loadSettings = () => {
|
|
208
|
+
settingRegistry
|
|
209
|
+
.load(plugin.id)
|
|
210
|
+
.then(settings => {
|
|
211
|
+
showBackgrounds = settings.get('showBackgrounds')
|
|
212
|
+
.composite as boolean;
|
|
213
|
+
settings.changed.connect(() => {
|
|
214
|
+
showBackgrounds = settings.get('showBackgrounds')
|
|
215
|
+
.composite as boolean;
|
|
216
|
+
});
|
|
217
|
+
})
|
|
218
|
+
.catch(reason => {
|
|
219
|
+
console.error(
|
|
220
|
+
'Failed to load settings for jupyterlab_github_markdown_alerts_extension',
|
|
221
|
+
reason
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
loadSettings();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const originalRender = markdownParser.render.bind(markdownParser);
|
|
229
|
+
|
|
230
|
+
markdownParser.render = async (content: string): Promise<string> => {
|
|
231
|
+
const processedContent = processAlerts(content);
|
|
232
|
+
console.log('Processed content:', processedContent);
|
|
233
|
+
const renderedHtml = await originalRender(processedContent);
|
|
234
|
+
console.log('Rendered HTML:', renderedHtml);
|
|
235
|
+
const finalHtml = postProcessAlerts(renderedHtml, showBackgrounds);
|
|
236
|
+
console.log('Final HTML:', finalHtml);
|
|
237
|
+
return finalHtml;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
console.log(
|
|
241
|
+
'JupyterLab extension jupyterlab_github_markdown_alerts_extension is activated!'
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export default plugin;
|
package/style/base.css
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* GitHub-style markdown alerts
|
|
3
|
+
* Matches GitHub's exact styling from github.com
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
.markdown-alert {
|
|
7
|
+
padding: 0.5rem 1rem;
|
|
8
|
+
margin-bottom: 1rem;
|
|
9
|
+
color: inherit;
|
|
10
|
+
border-left: 0.25em solid;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.markdown-alert > :first-child {
|
|
14
|
+
margin-top: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.markdown-alert > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.markdown-alert .markdown-alert-title {
|
|
22
|
+
display: flex;
|
|
23
|
+
font-weight: 500;
|
|
24
|
+
align-items: center;
|
|
25
|
+
line-height: 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.octicon {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
vertical-align: text-bottom;
|
|
31
|
+
flex-shrink: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Show light theme icons by default, hide dark theme icons */
|
|
35
|
+
.octicon-light {
|
|
36
|
+
display: inline-block;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.octicon-dark {
|
|
40
|
+
display: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* In dark theme, show dark icons and hide light icons */
|
|
44
|
+
body[data-jp-theme-light='false'] .octicon-light {
|
|
45
|
+
display: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
body[data-jp-theme-light='false'] .octicon-dark {
|
|
49
|
+
display: inline-block;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.mr-2 {
|
|
53
|
+
margin-right: 8px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Note - Blue */
|
|
57
|
+
.markdown-alert-note {
|
|
58
|
+
border-left-color: #0969da;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.markdown-alert-note .markdown-alert-title {
|
|
62
|
+
color: #0969da;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Tip - Green */
|
|
66
|
+
.markdown-alert-tip {
|
|
67
|
+
border-left-color: #1a7f37;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.markdown-alert-tip .markdown-alert-title {
|
|
71
|
+
color: #1a7f37;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Important - Purple */
|
|
75
|
+
.markdown-alert-important {
|
|
76
|
+
border-left-color: #8250df;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.markdown-alert-important .markdown-alert-title {
|
|
80
|
+
color: #8250df;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Warning - Orange */
|
|
84
|
+
.markdown-alert-warning {
|
|
85
|
+
border-left-color: #9a6700;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.markdown-alert-warning .markdown-alert-title {
|
|
89
|
+
color: #9a6700;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Caution - Red */
|
|
93
|
+
.markdown-alert-caution {
|
|
94
|
+
border-left-color: #cf222e;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.markdown-alert-caution .markdown-alert-title {
|
|
98
|
+
color: #cf222e;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* Dark theme support */
|
|
102
|
+
body[data-jp-theme-light='false'] .markdown-alert-note {
|
|
103
|
+
border-left-color: #2f81f7;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
body[data-jp-theme-light='false'] .markdown-alert-note .markdown-alert-title {
|
|
107
|
+
color: #2f81f7;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
body[data-jp-theme-light='false'] .markdown-alert-tip {
|
|
111
|
+
border-left-color: #3fb950;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
body[data-jp-theme-light='false'] .markdown-alert-tip .markdown-alert-title {
|
|
115
|
+
color: #3fb950;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
body[data-jp-theme-light='false'] .markdown-alert-important {
|
|
119
|
+
border-left-color: #a371f7;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
body[data-jp-theme-light='false']
|
|
123
|
+
.markdown-alert-important
|
|
124
|
+
.markdown-alert-title {
|
|
125
|
+
color: #a371f7;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
body[data-jp-theme-light='false'] .markdown-alert-warning {
|
|
129
|
+
border-left-color: #d29922;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
body[data-jp-theme-light='false'] .markdown-alert-warning .markdown-alert-title {
|
|
133
|
+
color: #d29922;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
body[data-jp-theme-light='false'] .markdown-alert-caution {
|
|
137
|
+
border-left-color: #f85149;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
body[data-jp-theme-light='false'] .markdown-alert-caution .markdown-alert-title {
|
|
141
|
+
color: #f85149;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* Optional backgrounds (enabled via settings) */
|
|
145
|
+
.markdown-alert-with-backgrounds.markdown-alert-note {
|
|
146
|
+
background-color: rgba(9, 105, 218, 0.1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.markdown-alert-with-backgrounds.markdown-alert-tip {
|
|
150
|
+
background-color: rgba(26, 127, 55, 0.1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.markdown-alert-with-backgrounds.markdown-alert-important {
|
|
154
|
+
background-color: rgba(130, 80, 223, 0.1);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.markdown-alert-with-backgrounds.markdown-alert-warning {
|
|
158
|
+
background-color: rgba(154, 103, 0, 0.1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.markdown-alert-with-backgrounds.markdown-alert-caution {
|
|
162
|
+
background-color: rgba(209, 36, 47, 0.1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* Dark theme backgrounds */
|
|
166
|
+
body[data-jp-theme-light='false']
|
|
167
|
+
.markdown-alert-with-backgrounds.markdown-alert-note {
|
|
168
|
+
background-color: rgba(47, 129, 247, 0.15);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
body[data-jp-theme-light='false']
|
|
172
|
+
.markdown-alert-with-backgrounds.markdown-alert-tip {
|
|
173
|
+
background-color: rgba(63, 185, 80, 0.15);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
body[data-jp-theme-light='false']
|
|
177
|
+
.markdown-alert-with-backgrounds.markdown-alert-important {
|
|
178
|
+
background-color: rgba(163, 113, 247, 0.15);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
body[data-jp-theme-light='false']
|
|
182
|
+
.markdown-alert-with-backgrounds.markdown-alert-warning {
|
|
183
|
+
background-color: rgba(210, 153, 34, 0.15);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
body[data-jp-theme-light='false']
|
|
187
|
+
.markdown-alert-with-backgrounds.markdown-alert-caution {
|
|
188
|
+
background-color: rgba(248, 81, 73, 0.15);
|
|
189
|
+
}
|
package/style/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import url('base.css');
|
package/style/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './base.css';
|