@md-plugins/md-plugin-containers 0.1.0-alpha.1 → 0.1.0-alpha.10
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.md +1 -1
- package/README.md +71 -44
- package/dist/index.mjs +1 -3
- package/package.json +9 -5
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024-present,
|
|
3
|
+
Copyright (c) 2024-present, MD-PLUGINS
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -27,16 +27,44 @@ pnpm add @md-plugins/md-plugin-containers
|
|
|
27
27
|
### Basic Setup
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
-
import MarkdownIt from 'markdown-it'
|
|
31
|
-
import { containersPlugin } from '@md-plugins/md-plugin-containers'
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
md
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
30
|
+
import MarkdownIt from 'markdown-it'
|
|
31
|
+
import { containersPlugin } from '@md-plugins/md-plugin-containers'
|
|
32
|
+
import container from 'markdown-it-container'
|
|
33
|
+
|
|
34
|
+
const md = new MarkdownIt()
|
|
35
|
+
|
|
36
|
+
const containers = [
|
|
37
|
+
{ type: 'warning', defaultTitle: 'Warning' },
|
|
38
|
+
{ type: 'tip', defaultTitle: 'Tip' },
|
|
39
|
+
{ type: 'details', defaultTitle: 'Details' },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
function createContainer(container, containerType, defaultTitle) {
|
|
43
|
+
const containerTypeLen = containerType.length
|
|
44
|
+
|
|
45
|
+
return [
|
|
46
|
+
container,
|
|
47
|
+
containerType,
|
|
48
|
+
{
|
|
49
|
+
render(tokens, idx) {
|
|
50
|
+
const token = tokens[idx]
|
|
51
|
+
const title = token.info.trim().slice(containerTypeLen).trim() || defaultTitle
|
|
52
|
+
|
|
53
|
+
if (containerType === 'details') {
|
|
54
|
+
return token.nesting === 1
|
|
55
|
+
? `<details class="markdown-note markdown-note--${containerType}"><summary class="markdown-note__title">${title}</summary>\n`
|
|
56
|
+
: '</details>\n'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return token.nesting === 1
|
|
60
|
+
? `<div class="markdown-note markdown-note--${containerType}"><p class="markdown-note__title">${title}</p>\n`
|
|
61
|
+
: '</div>\n'
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
md.use(containersPlugin, containers, createContainer)
|
|
40
68
|
|
|
41
69
|
const markdownContent = `
|
|
42
70
|
:::note
|
|
@@ -46,11 +74,11 @@ This is a note.
|
|
|
46
74
|
:::warning
|
|
47
75
|
This is a warning!
|
|
48
76
|
:::
|
|
49
|
-
|
|
77
|
+
`
|
|
50
78
|
|
|
51
|
-
const renderedOutput = md.render(markdownContent)
|
|
79
|
+
const renderedOutput = md.render(markdownContent)
|
|
52
80
|
|
|
53
|
-
console.log('Rendered Output:', renderedOutput)
|
|
81
|
+
console.log('Rendered Output:', renderedOutput)
|
|
54
82
|
```
|
|
55
83
|
|
|
56
84
|
### Example Output
|
|
@@ -81,42 +109,37 @@ The `md-plugin-containers` plugin supports the following options:
|
|
|
81
109
|
You can define custom containers with their own styles or components:
|
|
82
110
|
|
|
83
111
|
```js
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// Closing tag
|
|
109
|
-
return `</div>\n`;
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
});
|
|
112
|
+
function createContainer(container, containerType, defaultTitle) {
|
|
113
|
+
const containerTypeLen = containerType.length
|
|
114
|
+
|
|
115
|
+
return [
|
|
116
|
+
container,
|
|
117
|
+
containerType,
|
|
118
|
+
{
|
|
119
|
+
render(tokens, idx) {
|
|
120
|
+
const token = tokens[idx]
|
|
121
|
+
const title = token.info.trim().slice(containerTypeLen).trim() || defaultTitle
|
|
122
|
+
|
|
123
|
+
if (containerType === 'details') {
|
|
124
|
+
return token.nesting === 1
|
|
125
|
+
? `<details class="markdown-note markdown-note--${containerType}"><summary class="markdown-note__title">${title}</summary>\n`
|
|
126
|
+
: '</details>\n'
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return token.nesting === 1
|
|
130
|
+
? `<div class="markdown-note markdown-note--${containerType}"><p class="markdown-note__title">${title}</p>\n`
|
|
131
|
+
: '</div>\n'
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
}
|
|
113
136
|
```
|
|
114
137
|
|
|
115
138
|
## Adding Titles
|
|
116
139
|
|
|
117
140
|
Containers can include titles by default or allow custom titles to be specified:
|
|
118
141
|
|
|
119
|
-
```
|
|
142
|
+
```markup
|
|
120
143
|
:::note Custom Note Title
|
|
121
144
|
This is a custom note with a title.
|
|
122
145
|
:::
|
|
@@ -135,7 +158,7 @@ Rendered Output:
|
|
|
135
158
|
|
|
136
159
|
Containers can be nested if your rendering logic supports it:
|
|
137
160
|
|
|
138
|
-
```
|
|
161
|
+
```markup
|
|
139
162
|
:::note Outer Note
|
|
140
163
|
:::warning Inner Warning
|
|
141
164
|
Be cautious!
|
|
@@ -161,6 +184,10 @@ To run the tests for this plugin, use the following command:
|
|
|
161
184
|
pnpm test
|
|
162
185
|
```
|
|
163
186
|
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/md-plugins/containers/overview) for the latest information.
|
|
190
|
+
|
|
164
191
|
## License
|
|
165
192
|
|
|
166
193
|
This plugin is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
package/dist/index.mjs
CHANGED
|
@@ -6,9 +6,7 @@ function containersPlugin(md, containers, createContainer) {
|
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
if (typeof createContainer !== "function") {
|
|
9
|
-
throw new Error(
|
|
10
|
-
"Invalid createContainer function provided to containersPlugin."
|
|
11
|
-
);
|
|
9
|
+
throw new Error("Invalid createContainer function provided to containersPlugin.");
|
|
12
10
|
}
|
|
13
11
|
containers.forEach(({ type, defaultTitle }) => {
|
|
14
12
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/md-plugin-containers",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"description": "A markdown-it plugin for handling custom containers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -33,20 +33,24 @@
|
|
|
33
33
|
"./dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@types/markdown-it": "^14.1.2",
|
|
37
36
|
"markdown-it": "^14.1.0",
|
|
38
37
|
"markdown-it-container": "^4.0.0",
|
|
39
|
-
"@md-plugins/shared": "0.1.0-alpha.
|
|
38
|
+
"@md-plugins/shared": "0.1.0-alpha.10"
|
|
40
39
|
},
|
|
41
40
|
"publishConfig": {
|
|
42
41
|
"access": "public"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@types/markdown-it-container": "^2.0.10"
|
|
44
|
+
"@types/markdown-it-container": "^2.0.10",
|
|
45
|
+
"@types/markdown-it": "^14.1.2"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"markdown-it": "^14.1.0",
|
|
49
|
+
"markdown-it-container": "^4.0.0"
|
|
46
50
|
},
|
|
47
51
|
"scripts": {
|
|
48
52
|
"build": "unbuild",
|
|
49
|
-
"clean": "rm -rf dist",
|
|
53
|
+
"clean": "rm -rf dist/ node_modules/",
|
|
50
54
|
"test": "vitest"
|
|
51
55
|
}
|
|
52
56
|
}
|