nizel-plugin-badge 0.1.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.md +128 -0
- package/dist/escape.d.ts +3 -0
- package/dist/escape.d.ts.map +1 -0
- package/dist/escape.js +7 -0
- package/dist/escape.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/parseBadgeExpression.d.ts +4 -0
- package/dist/parseBadgeExpression.d.ts.map +1 -0
- package/dist/parseBadgeExpression.js +91 -0
- package/dist/parseBadgeExpression.js.map +1 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +167 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
- package/style.css +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# nizel-plugin-badge
|
|
2
|
+
|
|
3
|
+
Inline badge and status label syntax for Nizel.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install nizel-plugin-badge
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { useNizel } from 'nizel';
|
|
15
|
+
import { badgePlugin } from 'nizel-plugin-badge';
|
|
16
|
+
import 'nizel-plugin-badge/style.css';
|
|
17
|
+
|
|
18
|
+
const nizel = useNizel({
|
|
19
|
+
plugins: [
|
|
20
|
+
badgePlugin({
|
|
21
|
+
defaultTone: 'neutral',
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Syntax
|
|
28
|
+
|
|
29
|
+
```md
|
|
30
|
+
:badge(beta)
|
|
31
|
+
:badge(v1.2.0)
|
|
32
|
+
:badge(deprecated, tone="warning")
|
|
33
|
+
:badge(done, tone="success", title="This task is complete")
|
|
34
|
+
:badge("Breaking Change", tone="danger")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The first positional argument is the label. Use quotes when the label contains a comma or closing parenthesis.
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
badgePlugin({
|
|
43
|
+
className: 'nizel-badge',
|
|
44
|
+
defaultTone: 'neutral',
|
|
45
|
+
allowedTones: ['neutral', 'info', 'success', 'warning', 'danger', 'purple', 'blue', 'green', 'yellow', 'red'],
|
|
46
|
+
collectMetadata: true,
|
|
47
|
+
aliases: {
|
|
48
|
+
beta: { label: 'Beta', tone: 'info' },
|
|
49
|
+
deprecated: { label: 'Deprecated', tone: 'warning' },
|
|
50
|
+
done: { label: 'Done', tone: 'success' },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Supported Markdown options are `tone`, `title`, and `className`.
|
|
56
|
+
|
|
57
|
+
Unknown or disallowed tones fall back to the configured `defaultTone`, or `neutral` if the configured default is not allowed.
|
|
58
|
+
|
|
59
|
+
## Output
|
|
60
|
+
|
|
61
|
+
```md
|
|
62
|
+
:badge(deprecated, tone="warning")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<span class="nizel-badge" data-tone="warning">deprecated</span>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
All label, title, class, and tone values are escaped before rendering.
|
|
70
|
+
|
|
71
|
+
## Aliases
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
badgePlugin({
|
|
75
|
+
aliases: {
|
|
76
|
+
beta: { label: 'Beta', tone: 'info' },
|
|
77
|
+
deprecated: { label: 'Deprecated', tone: 'warning' },
|
|
78
|
+
done: { label: 'Done', tone: 'success' },
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Explicit Markdown options override alias defaults.
|
|
84
|
+
|
|
85
|
+
## Styling
|
|
86
|
+
|
|
87
|
+
Import the default stylesheet when you want the minimal bundled badge styles:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import 'nizel-plugin-badge/style.css';
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The stylesheet only defines the base pill shape and tone colors. Host apps can override all selectors.
|
|
94
|
+
|
|
95
|
+
## Metadata
|
|
96
|
+
|
|
97
|
+
When `collectMetadata` is enabled, the plugin adds badge usage to `result.meta.badge.badges`.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
{
|
|
101
|
+
badge: {
|
|
102
|
+
badges: [
|
|
103
|
+
{
|
|
104
|
+
label: 'Deprecated',
|
|
105
|
+
tone: 'warning',
|
|
106
|
+
original: 'deprecated'
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Security
|
|
114
|
+
|
|
115
|
+
The plugin escapes badge labels, titles, custom classes, and `data-tone` values. Unknown tones do not pass through to HTML; they fall back to `defaultTone` or `neutral`.
|
|
116
|
+
|
|
117
|
+
## Parser Behavior
|
|
118
|
+
|
|
119
|
+
The plugin transforms inline `:badge(...)` expressions in normal text. It does not transform fenced code, inline code, raw HTML blocks, or escaped syntax such as `\:badge(beta)`.
|
|
120
|
+
|
|
121
|
+
## Integration Example
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const result = await nizel('# Release :badge(beta, tone="info")');
|
|
125
|
+
|
|
126
|
+
console.log(result.html);
|
|
127
|
+
console.log(result.meta.badge);
|
|
128
|
+
```
|
package/dist/escape.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../src/escape.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,MAIlB,CAAC;AAE3B,eAAO,MAAM,eAAe,UANM,OAAO,KAAG,MAMH,CAAC"}
|
package/dist/escape.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../src/escape.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;KAChE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;KACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;KACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;KACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAE3B,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BADGE_TONES, badgePlugin, badgePluginMeta, transformBadges } from './plugin.js';
|
|
2
|
+
export { parseBadgeExpression } from './parseBadgeExpression.js';
|
|
3
|
+
export type { BadgeAlias, BadgeMarkdownOptions, BadgeMetadata, BadgePluginOptions, BadgeTone, BadgeUsage, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ParsedBadgeExpression } from './types.js';
|
|
2
|
+
export declare const parseBadgeExpression: (source: string) => ParsedBadgeExpression | null;
|
|
3
|
+
export declare const findBadgeExpressionEnd: (source: string, startIndex: number) => number;
|
|
4
|
+
//# sourceMappingURL=parseBadgeExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseBadgeExpression.d.ts","sourceRoot":"","sources":["../src/parseBadgeExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAI9E,eAAO,MAAM,oBAAoB,GAAI,QAAQ,MAAM,KAAG,qBAAqB,GAAG,IAmB7E,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,EAAE,YAAY,MAAM,KAAG,MAmB3E,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const SUPPORTED_OPTIONS = new Set(['tone', 'title', 'className']);
|
|
2
|
+
export const parseBadgeExpression = (source) => {
|
|
3
|
+
const trimmed = source.trim();
|
|
4
|
+
if (!trimmed.startsWith(':badge(') || !trimmed.endsWith(')'))
|
|
5
|
+
return null;
|
|
6
|
+
const body = trimmed.slice(':badge('.length, -1).trim();
|
|
7
|
+
if (!body)
|
|
8
|
+
return null;
|
|
9
|
+
const parts = splitArguments(body);
|
|
10
|
+
const rawLabel = parts.shift()?.trim();
|
|
11
|
+
if (!rawLabel || rawLabel.includes('='))
|
|
12
|
+
return null;
|
|
13
|
+
const options = {};
|
|
14
|
+
for (const part of parts) {
|
|
15
|
+
const parsed = parseNamedOption(part);
|
|
16
|
+
if (!parsed)
|
|
17
|
+
return null;
|
|
18
|
+
const [key, value] = parsed;
|
|
19
|
+
options[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return { label: unquoteValue(rawLabel), options };
|
|
22
|
+
};
|
|
23
|
+
export const findBadgeExpressionEnd = (source, startIndex) => {
|
|
24
|
+
const open = startIndex + ':badge'.length;
|
|
25
|
+
if (source[open] !== '(')
|
|
26
|
+
return -1;
|
|
27
|
+
let quote;
|
|
28
|
+
for (let index = open + 1; index < source.length; index += 1) {
|
|
29
|
+
const char = source[index];
|
|
30
|
+
const previous = source[index - 1];
|
|
31
|
+
if (quote) {
|
|
32
|
+
if (char === quote && previous !== '\\')
|
|
33
|
+
quote = undefined;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (char === '"' || char === "'") {
|
|
37
|
+
quote = char;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (char === ')' && isExpressionBoundary(source[index + 1]))
|
|
41
|
+
return index + 1;
|
|
42
|
+
}
|
|
43
|
+
return -1;
|
|
44
|
+
};
|
|
45
|
+
const isExpressionBoundary = (char) => {
|
|
46
|
+
return char === undefined || /[\s.,;:!?}\]]/.test(char);
|
|
47
|
+
};
|
|
48
|
+
const splitArguments = (source) => {
|
|
49
|
+
const parts = [];
|
|
50
|
+
let quote;
|
|
51
|
+
let start = 0;
|
|
52
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
53
|
+
const char = source[index];
|
|
54
|
+
const previous = source[index - 1];
|
|
55
|
+
if (quote) {
|
|
56
|
+
if (char === quote && previous !== '\\')
|
|
57
|
+
quote = undefined;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === '"' || char === "'") {
|
|
61
|
+
quote = char;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (char === ',') {
|
|
65
|
+
parts.push(source.slice(start, index).trim());
|
|
66
|
+
start = index + 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
parts.push(source.slice(start).trim());
|
|
70
|
+
return parts.filter(Boolean);
|
|
71
|
+
};
|
|
72
|
+
const parseNamedOption = (source) => {
|
|
73
|
+
const equals = source.indexOf('=');
|
|
74
|
+
if (equals <= 0)
|
|
75
|
+
return null;
|
|
76
|
+
const key = source.slice(0, equals).trim();
|
|
77
|
+
if (!SUPPORTED_OPTIONS.has(key))
|
|
78
|
+
return null;
|
|
79
|
+
const rawValue = source.slice(equals + 1).trim();
|
|
80
|
+
if (!rawValue || rawValue.startsWith('{') || rawValue.endsWith('}'))
|
|
81
|
+
return null;
|
|
82
|
+
return [key, unquoteValue(rawValue)];
|
|
83
|
+
};
|
|
84
|
+
const unquoteValue = (value) => {
|
|
85
|
+
const quoted = /^"((?:\\.|[^"\\])*)"$|^'((?:\\.|[^'\\])*)'$/.exec(value);
|
|
86
|
+
if (quoted)
|
|
87
|
+
return unescapeQuoted(quoted[1] ?? quoted[2] ?? '');
|
|
88
|
+
return value;
|
|
89
|
+
};
|
|
90
|
+
const unescapeQuoted = (value) => value.replace(/\\(["'\\])/g, '$1');
|
|
91
|
+
//# sourceMappingURL=parseBadgeExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseBadgeExpression.js","sourceRoot":"","sources":["../src/parseBadgeExpression.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAgC,EAAE;IACnF,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE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AAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NizelOptions, NizelPlugin, NizelRootNode } from 'nizel';
|
|
2
|
+
import type { BadgePluginOptions, BadgeTone, BadgeUsage, NormalizedBadgePluginOptions } from './types.js';
|
|
3
|
+
export declare const badgePluginMeta: {
|
|
4
|
+
readonly id: "badge";
|
|
5
|
+
readonly label: "Badge";
|
|
6
|
+
readonly description: "Renders inline badges and status labels in Markdown.";
|
|
7
|
+
readonly category: "Inline";
|
|
8
|
+
readonly defaultEnabled: false;
|
|
9
|
+
};
|
|
10
|
+
export declare const BADGE_TONES: BadgeTone[];
|
|
11
|
+
export declare const badgePlugin: (options?: BadgePluginOptions) => NizelPlugin;
|
|
12
|
+
export declare const transformBadges: (ast: NizelRootNode, options: NormalizedBadgePluginOptions, usage?: BadgeUsage[], resolvedOptions?: NizelOptions) => NizelRootNode;
|
|
13
|
+
export default badgePlugin;
|
|
14
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGvG,OAAO,KAAK,EAEV,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,4BAA4B,EAE7B,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAEX,eAAO,MAAM,WAAW,EAAE,SAAS,EAWlC,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,UAAS,kBAAuB,KAAG,WAiB9D,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,aAAa,EAClB,SAAS,4BAA4B,EACrC,QAAO,UAAU,EAAO,EACxB,kBAAkB,YAAY,KAC7B,aAEF,CAAC;AAgJF,eAAe,WAAW,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { escapeAttribute, escapeHtml } from './escape.js';
|
|
2
|
+
import { findBadgeExpressionEnd, parseBadgeExpression } from './parseBadgeExpression.js';
|
|
3
|
+
const ESCAPED_BADGE_SENTINEL = '\uE000nizel-badge-escaped';
|
|
4
|
+
export const badgePluginMeta = {
|
|
5
|
+
id: 'badge',
|
|
6
|
+
label: 'Badge',
|
|
7
|
+
description: 'Renders inline badges and status labels in Markdown.',
|
|
8
|
+
category: 'Inline',
|
|
9
|
+
defaultEnabled: false,
|
|
10
|
+
};
|
|
11
|
+
export const BADGE_TONES = [
|
|
12
|
+
'neutral',
|
|
13
|
+
'info',
|
|
14
|
+
'success',
|
|
15
|
+
'warning',
|
|
16
|
+
'danger',
|
|
17
|
+
'purple',
|
|
18
|
+
'blue',
|
|
19
|
+
'green',
|
|
20
|
+
'yellow',
|
|
21
|
+
'red',
|
|
22
|
+
];
|
|
23
|
+
export const badgePlugin = (options = {}) => {
|
|
24
|
+
const normalized = normalizeOptions(options);
|
|
25
|
+
const metadata = { badges: [] };
|
|
26
|
+
return {
|
|
27
|
+
name: badgePluginMeta.id,
|
|
28
|
+
options: normalized.collectMetadata ? { meta: { badge: metadata } } : undefined,
|
|
29
|
+
hooks: {
|
|
30
|
+
beforeParse(markdown) {
|
|
31
|
+
metadata.badges = [];
|
|
32
|
+
return protectRawHtmlBadge(markdown).replace(/\\:badge\(/g, `${ESCAPED_BADGE_SENTINEL}(`);
|
|
33
|
+
},
|
|
34
|
+
afterParse(ast, resolvedOptions) {
|
|
35
|
+
return transformBadges(ast, normalized, metadata.badges, resolvedOptions);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const transformBadges = (ast, options, usage = [], resolvedOptions) => {
|
|
41
|
+
return { ...ast, children: ast.children.map((node) => transformBlock(node, options, usage, resolvedOptions)) };
|
|
42
|
+
};
|
|
43
|
+
const normalizeOptions = (options) => ({
|
|
44
|
+
className: options.className ?? 'nizel-badge',
|
|
45
|
+
defaultTone: options.defaultTone ?? 'neutral',
|
|
46
|
+
allowedTones: options.allowedTones ?? BADGE_TONES,
|
|
47
|
+
collectMetadata: options.collectMetadata ?? true,
|
|
48
|
+
aliases: options.aliases ?? {},
|
|
49
|
+
});
|
|
50
|
+
const transformBlock = (node, options, usage, resolvedOptions) => {
|
|
51
|
+
if (node.type === 'paragraph' || node.type === 'heading') {
|
|
52
|
+
return { ...node, children: transformInlineNodes(node.children, options, usage, resolvedOptions) };
|
|
53
|
+
}
|
|
54
|
+
if (node.type === 'blockquote')
|
|
55
|
+
return { ...node, children: node.children.map((child) => transformBlock(child, options, usage, resolvedOptions)) };
|
|
56
|
+
if (node.type === 'list') {
|
|
57
|
+
return {
|
|
58
|
+
...node,
|
|
59
|
+
children: node.children.map((item) => ({
|
|
60
|
+
...item,
|
|
61
|
+
children: item.children.map((child) => transformBlock(child, options, usage, resolvedOptions)),
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (node.type === 'table') {
|
|
66
|
+
return {
|
|
67
|
+
...node,
|
|
68
|
+
children: node.children.map((row) => ({
|
|
69
|
+
...row,
|
|
70
|
+
children: row.children.map((cell) => ({ ...cell, children: transformInlineNodes(cell.children, options, usage, resolvedOptions) })),
|
|
71
|
+
})),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (node.type === 'customBlock')
|
|
75
|
+
return { ...node, children: node.children?.map((child) => transformBlock(child, options, usage, resolvedOptions)) };
|
|
76
|
+
return node;
|
|
77
|
+
};
|
|
78
|
+
const transformInlineNodes = (nodes, options, usage, resolvedOptions) => {
|
|
79
|
+
const transformed = [];
|
|
80
|
+
for (const node of nodes) {
|
|
81
|
+
if (node.type === 'text')
|
|
82
|
+
transformed.push(...transformText(node.value, options, usage, resolvedOptions));
|
|
83
|
+
else if ('children' in node)
|
|
84
|
+
transformed.push({ ...node, children: transformInlineNodes(node.children, options, usage, resolvedOptions) });
|
|
85
|
+
else
|
|
86
|
+
transformed.push(node);
|
|
87
|
+
}
|
|
88
|
+
return transformed;
|
|
89
|
+
};
|
|
90
|
+
const transformText = (value, options, usage, resolvedOptions) => {
|
|
91
|
+
const nodes = [];
|
|
92
|
+
let cursor = 0;
|
|
93
|
+
while (cursor < value.length) {
|
|
94
|
+
const start = value.indexOf(':badge(', cursor);
|
|
95
|
+
if (start === -1)
|
|
96
|
+
break;
|
|
97
|
+
const end = findBadgeExpressionEnd(value, start);
|
|
98
|
+
if (end === -1)
|
|
99
|
+
break;
|
|
100
|
+
if (start > cursor)
|
|
101
|
+
nodes.push({ type: 'text', value: restoreEscapedSyntax(value.slice(cursor, start)) });
|
|
102
|
+
const source = value.slice(start, end);
|
|
103
|
+
const parsed = parseBadgeExpression(source);
|
|
104
|
+
if (!parsed) {
|
|
105
|
+
nodes.push({ type: 'text', value: restoreEscapedSyntax(source) });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
nodes.push({ type: 'inlineHtml', value: renderParsedBadge(parsed, options, usage, resolvedOptions) });
|
|
109
|
+
}
|
|
110
|
+
cursor = end;
|
|
111
|
+
}
|
|
112
|
+
if (cursor < value.length)
|
|
113
|
+
nodes.push({ type: 'text', value: restoreEscapedSyntax(value.slice(cursor)) });
|
|
114
|
+
if (nodes.length === 0)
|
|
115
|
+
nodes.push({ type: 'text', value: restoreEscapedSyntax(value) });
|
|
116
|
+
return nodes;
|
|
117
|
+
};
|
|
118
|
+
const renderParsedBadge = (parsed, options, usage, resolvedOptions) => {
|
|
119
|
+
const alias = options.aliases[parsed.label];
|
|
120
|
+
const label = alias?.label ?? parsed.label;
|
|
121
|
+
const tone = resolveTone(parsed.options.tone ?? alias?.tone, options);
|
|
122
|
+
const className = parsed.options.className ? `${options.className} ${parsed.options.className}` : options.className;
|
|
123
|
+
const title = parsed.options.title;
|
|
124
|
+
if (options.collectMetadata) {
|
|
125
|
+
usage.push(cleanUsage({
|
|
126
|
+
label,
|
|
127
|
+
tone,
|
|
128
|
+
original: alias ? parsed.label : undefined,
|
|
129
|
+
title,
|
|
130
|
+
}));
|
|
131
|
+
syncResolvedMetadata(resolvedOptions, usage);
|
|
132
|
+
}
|
|
133
|
+
const titleAttribute = title === undefined ? '' : ` title="${escapeAttribute(title)}"`;
|
|
134
|
+
return `<span class="${escapeAttribute(className)}" data-tone="${escapeAttribute(tone)}"${titleAttribute}>${escapeHtml(label)}</span>`;
|
|
135
|
+
};
|
|
136
|
+
const resolveTone = (tone, options) => {
|
|
137
|
+
if (tone && options.allowedTones.includes(tone))
|
|
138
|
+
return tone;
|
|
139
|
+
if (options.allowedTones.includes(options.defaultTone))
|
|
140
|
+
return options.defaultTone;
|
|
141
|
+
return 'neutral';
|
|
142
|
+
};
|
|
143
|
+
const syncResolvedMetadata = (resolvedOptions, badges) => {
|
|
144
|
+
const meta = resolvedOptions?.meta;
|
|
145
|
+
if (!meta)
|
|
146
|
+
return;
|
|
147
|
+
meta.badge = { badges };
|
|
148
|
+
};
|
|
149
|
+
const cleanUsage = (usage) => {
|
|
150
|
+
const cleaned = {
|
|
151
|
+
label: usage.label,
|
|
152
|
+
tone: usage.tone,
|
|
153
|
+
};
|
|
154
|
+
if (usage.original !== undefined)
|
|
155
|
+
cleaned.original = usage.original;
|
|
156
|
+
if (usage.title !== undefined)
|
|
157
|
+
cleaned.title = usage.title;
|
|
158
|
+
return cleaned;
|
|
159
|
+
};
|
|
160
|
+
const protectRawHtmlBadge = (markdown) => {
|
|
161
|
+
return markdown.replace(/<([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?>[\s\S]*?<\/\1>/g, (html) => {
|
|
162
|
+
return html.replace(/:badge\(/g, `${ESCAPED_BADGE_SENTINEL}(`);
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const restoreEscapedSyntax = (value) => value.replaceAll(`${ESCAPED_BADGE_SENTINEL}(`, ':badge(');
|
|
166
|
+
export default badgePlugin;
|
|
167
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAUzF,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAE3D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,sDAAsD;IACnE,QAAQ,EAAE,QAAQ;IAClB,cAAc,EAAE,KAAK;CACb,CAAC;AAEX,MAAM,CAAC,MAAM,WAAW,GAAgB;IACtC,SAAS;IACT,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,QAAQ;IACR,KAAK;CACN,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAA8B,EAAE,EAAe,EAAE;IAC3E,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAA2B,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAExD,OAAO;QACL,IAAI,EAAE,eAAe,CAAC,EAAE;QACxB,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;QAC/E,KAAK,EAAE;YACL,WAAW,CAAC,QAAQ;gBAClB,QAAQ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0,0 +1,40 @@
|
|
|
1
|
+
export type BadgeTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger' | 'purple' | 'blue' | 'green' | 'yellow' | 'red';
|
|
2
|
+
export type BadgeMarkdownOptions = {
|
|
3
|
+
tone?: BadgeTone | string;
|
|
4
|
+
title?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
export type BadgeAlias = {
|
|
8
|
+
label?: string;
|
|
9
|
+
tone?: BadgeTone;
|
|
10
|
+
};
|
|
11
|
+
export type BadgePluginOptions = {
|
|
12
|
+
className?: string;
|
|
13
|
+
defaultTone?: BadgeTone;
|
|
14
|
+
allowedTones?: BadgeTone[];
|
|
15
|
+
collectMetadata?: boolean;
|
|
16
|
+
aliases?: Record<string, BadgeAlias>;
|
|
17
|
+
};
|
|
18
|
+
export type BadgeUsage = {
|
|
19
|
+
label: string;
|
|
20
|
+
tone: BadgeTone;
|
|
21
|
+
original?: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
};
|
|
24
|
+
export type BadgeMetadata = {
|
|
25
|
+
badge: {
|
|
26
|
+
badges: BadgeUsage[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type ParsedBadgeExpression = {
|
|
30
|
+
label: string;
|
|
31
|
+
options: BadgeMarkdownOptions;
|
|
32
|
+
};
|
|
33
|
+
export type NormalizedBadgePluginOptions = {
|
|
34
|
+
className: string;
|
|
35
|
+
defaultTone: BadgeTone;
|
|
36
|
+
allowedTones: BadgeTone[];
|
|
37
|
+
collectMetadata: boolean;
|
|
38
|
+
aliases: Record<string, BadgeAlias>;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,MAAM,GACN,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,G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ED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nizel-plugin-badge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Inline badge and status label plugin for Nizel.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/silvandiepen/nizel"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./style.css": "./style.css"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"style.css"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "npm run build && vitest run test/*.mjs",
|
|
28
|
+
"test:watch": "npm run build && vitest test/*.mjs",
|
|
29
|
+
"test:run": "vitest run test/*.mjs"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"nizel": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"provenance": true
|
|
37
|
+
}
|
|
38
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.nizel-badge {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
border-radius: 999px;
|
|
5
|
+
padding: 0.125em 0.5em;
|
|
6
|
+
font-size: 0.85em;
|
|
7
|
+
line-height: 1.4;
|
|
8
|
+
font-weight: 600;
|
|
9
|
+
white-space: nowrap;
|
|
10
|
+
vertical-align: baseline;
|
|
11
|
+
background: color-mix(in srgb, currentColor 10%, transparent);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.nizel-badge[data-tone="neutral"] {
|
|
15
|
+
color: currentColor;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.nizel-badge[data-tone="info"],
|
|
19
|
+
.nizel-badge[data-tone="blue"] {
|
|
20
|
+
color: #175cd3;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.nizel-badge[data-tone="success"],
|
|
24
|
+
.nizel-badge[data-tone="green"] {
|
|
25
|
+
color: #16794c;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.nizel-badge[data-tone="warning"],
|
|
29
|
+
.nizel-badge[data-tone="yellow"] {
|
|
30
|
+
color: #946200;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.nizel-badge[data-tone="danger"],
|
|
34
|
+
.nizel-badge[data-tone="red"] {
|
|
35
|
+
color: #b42318;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.nizel-badge[data-tone="purple"] {
|
|
39
|
+
color: #6941c6;
|
|
40
|
+
}
|