remark-mind-elixir 0.3.3 → 0.5.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 +68 -2
- package/package.json +2 -1
- package/src/client.js +6 -6
- package/src/index.js +38 -8
package/README.md
CHANGED
|
@@ -45,6 +45,71 @@ const file = await remark()
|
|
|
45
45
|
console.log(String(file))
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## Usage with Astro
|
|
49
|
+
|
|
50
|
+
Install the plugin in your Astro project:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install remark-mind-elixir
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then add it to the `markdown.remarkPlugins` configuration in `astro.config.mjs`:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
// @ts-check
|
|
60
|
+
import { defineConfig } from 'astro/config'
|
|
61
|
+
import remarkMindElixir from 'remark-mind-elixir'
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
markdown: {
|
|
65
|
+
remarkPlugins: [remarkMindElixir()],
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
You can then use `elixir-mind` blocks directly in your Markdown or MDX pages:
|
|
71
|
+
|
|
72
|
+
````markdown
|
|
73
|
+
# JavaScript
|
|
74
|
+
|
|
75
|
+
```elixir-mind
|
|
76
|
+
root:
|
|
77
|
+
topic: JavaScript
|
|
78
|
+
children:
|
|
79
|
+
- topic: Browser
|
|
80
|
+
children:
|
|
81
|
+
- topic: DOM
|
|
82
|
+
- topic: Web APIs
|
|
83
|
+
- topic: Node.js
|
|
84
|
+
- topic: Deno
|
|
85
|
+
```
|
|
86
|
+
````
|
|
87
|
+
|
|
88
|
+
The plugin transforms the block during Astro's Markdown processing and injects the client-side Mind Elixir runtime automatically.
|
|
89
|
+
|
|
90
|
+
### Astro with CDN disabled
|
|
91
|
+
|
|
92
|
+
By default, `remark-mind-elixir` loads the client runtime from `esm.sh`.
|
|
93
|
+
|
|
94
|
+
You can disable this behavior:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import { defineConfig } from 'astro/config'
|
|
98
|
+
import remarkMindElixir from 'remark-mind-elixir'
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
markdown: {
|
|
102
|
+
remarkPlugins: [
|
|
103
|
+
remarkMindElixir({
|
|
104
|
+
useCdn: false,
|
|
105
|
+
}),
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
When `useCdn` is disabled, your application must provide the Mind Elixir client runtime itself.
|
|
112
|
+
|
|
48
113
|
## Markdown Syntax
|
|
49
114
|
|
|
50
115
|
Use an `elixir-mind` fenced code block:
|
|
@@ -73,6 +138,7 @@ Separate the configuration and data using `---`:
|
|
|
73
138
|
---
|
|
74
139
|
direction: right
|
|
75
140
|
---
|
|
141
|
+
|
|
76
142
|
root:
|
|
77
143
|
topic: JavaScript
|
|
78
144
|
children:
|
|
@@ -141,7 +207,7 @@ When disabled, the plugin does not inject the CDN runtime. Your application must
|
|
|
141
207
|
|
|
142
208
|
By default, the plugin injects the Mind Elixir runtime using `esm.sh`.
|
|
143
209
|
|
|
144
|
-
The generated
|
|
210
|
+
The generated HTML contains a container similar to:
|
|
145
211
|
|
|
146
212
|
```html
|
|
147
213
|
<div
|
|
@@ -200,4 +266,4 @@ It is built on top of ZikoJS utilities while remaining a remark plugin rather th
|
|
|
200
266
|
|
|
201
267
|
## License
|
|
202
268
|
|
|
203
|
-
MIT
|
|
269
|
+
MIT + Mind Elixir License
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -2,15 +2,15 @@ import { MindMap } from '@zikojs/mind-elixir/no-css'
|
|
|
2
2
|
|
|
3
3
|
document.addEventListener('DOMContentLoaded', () => {
|
|
4
4
|
document.querySelectorAll('[data-elixir-mind]').forEach((element) => {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const body = element.dataset.xmindBody
|
|
6
|
+
const config = element.dataset?.xmindConfig
|
|
7
7
|
|
|
8
|
-
if (!
|
|
8
|
+
if (!body) return
|
|
9
9
|
|
|
10
|
-
const nodeData = JSON.parse(
|
|
11
|
-
|
|
10
|
+
const nodeData = JSON.parse(body)
|
|
11
|
+
const nodeConfig = JSON.parse(config)
|
|
12
12
|
|
|
13
|
-
const map = MindMap({}, nodeData)
|
|
13
|
+
const map = MindMap({height : '400px', ...nodeConfig}, nodeData)
|
|
14
14
|
|
|
15
15
|
map.mount(element)
|
|
16
16
|
})
|
package/src/index.js
CHANGED
|
@@ -16,10 +16,10 @@ const remarkElixirMind = ({
|
|
|
16
16
|
let config = {}, body = null;
|
|
17
17
|
|
|
18
18
|
const documents = splitDocuments(node.value.trim());
|
|
19
|
-
if(documents.length === 1) body =
|
|
19
|
+
if(documents.length === 1) body = parseMindBody(documents[0])
|
|
20
20
|
else {
|
|
21
21
|
config = parse(documents[0])
|
|
22
|
-
body =
|
|
22
|
+
body = parseMindBody(documents[1])
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// parent creates circular references, so serialize a clean copy
|
|
@@ -59,12 +59,12 @@ const remarkElixirMind = ({
|
|
|
59
59
|
import { MindMap } from 'https://esm.sh/@zikojs/mind-elixir@latest/src/mind/main.js'
|
|
60
60
|
document.addEventListener('DOMContentLoaded', () => {
|
|
61
61
|
document.querySelectorAll('[data-elixir-mind]').forEach((element) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
if (!
|
|
65
|
-
const nodeData = JSON.parse(
|
|
66
|
-
|
|
67
|
-
const map = MindMap({}, nodeData)
|
|
62
|
+
const body = element.dataset.xmindBody
|
|
63
|
+
const config = element.dataset?.xmindConfig
|
|
64
|
+
if (!body) return
|
|
65
|
+
const nodeData = JSON.parse(body)
|
|
66
|
+
const nodeConfig = JSON.parse(config)
|
|
67
|
+
const map = MindMap({height : '400px', ...nodeConfig}, nodeData)
|
|
68
68
|
map.mount(element)
|
|
69
69
|
})
|
|
70
70
|
})
|
|
@@ -140,4 +140,34 @@ const splitDocuments = (text) => {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
return documents
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// const parseMindBody = (text) => {
|
|
146
|
+
// try {
|
|
147
|
+
// return JSON.parse(text)
|
|
148
|
+
// } catch {
|
|
149
|
+
// return yaml2MindElixirData(text)
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
|
|
153
|
+
const parseMindBody = (text) => {
|
|
154
|
+
const trimmed = text.trim()
|
|
155
|
+
|
|
156
|
+
// JSON
|
|
157
|
+
try {
|
|
158
|
+
return JSON.parse(trimmed)
|
|
159
|
+
} catch {}
|
|
160
|
+
|
|
161
|
+
// JavaScript object/array
|
|
162
|
+
if (
|
|
163
|
+
trimmed.startsWith('{') ||
|
|
164
|
+
trimmed.startsWith('[')
|
|
165
|
+
) {
|
|
166
|
+
try {
|
|
167
|
+
return Function(`"use strict"; return (${trimmed})`)()
|
|
168
|
+
} catch {}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// YAML
|
|
172
|
+
return yaml2MindElixirData(trimmed)
|
|
143
173
|
}
|