mdzjs 0.0.0 → 0.0.2
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 +72 -58
- package/__src__/index.js +2 -0
- package/__src__/test.js +21 -0
- package/__v2__/_test.js +77 -0
- package/__v2__/clean.js +67 -0
- package/__v2__/hast.js +70 -0
- package/__v2__/html2js.js +59 -0
- package/__v2__/index.js +2 -0
- package/__v2__/pre-parse/clean-md.js +93 -0
- package/__v2__/readme.md +17 -0
- package/__v2__/test.js +19 -0
- package/__v2__/transformers/vite/index.js +16 -0
- package/__v2__/transpiler/get-component-type.js +27 -0
- package/__v2__/transpiler/import-plugin.js +19 -0
- package/__v2__/transpiler/index.js +168 -0
- package/__v2__/transpiler/jsx2js.js +30 -0
- package/__v2__/transpiler/process-text.js +48 -0
- package/__v2__/utils/is-object.js +11 -0
- package/__v2__/utils/split-between.js +47 -0
- package/package.json +17 -7
- package/preview/Components/Dom.js +6 -0
- package/preview/Components/Hi.js +2 -0
- package/preview/Components/Scene.js +10 -0
- package/preview/index.html +10 -1
- package/preview/main.js +7 -10
- package/preview/package-lock.json +837 -7
- package/preview/package.json +7 -1
- package/preview/test.mdz +29 -13
- package/preview/test.mdz.__ +24 -0
- package/preview/vite.config.js +3 -2
- package/rollup.config.js +1 -1
- package/src/bundlers/vite.js +15 -0
- package/src/example.md +3 -0
- package/src/index.js +1 -2
- package/src/test.js +45 -17
- package/src/transpiler/index.js +3 -0
- package/src/transpiler/parser.js +14 -0
- package/src/transpiler/process.js +172 -0
- package/src/transpiler/transpile.js +22 -0
- package/src/utils/component-type.js +5 -0
- package/src/utils/hyperscript.js +4 -0
- package/src/utils/index.js +4 -0
- package/src/utils/parse-yml.js +19 -0
- package/src/utils/process-attributes.js +13 -0
- /package/{src → __src__}/converter/index.js +0 -0
- /package/{src → __src__}/parser/get-component-type.js +0 -0
- /package/{src → __src__}/parser/index.js +0 -0
- /package/{src → __src__}/parser/jsx2js.js +0 -0
- /package/{src → __src__}/parser/parser-markdown.js +0 -0
- /package/{src → __src__}/parser/smart-join.js +0 -0
- /package/{src → __src__}/vite/index.js +0 -0
- /package/preview/{InteractiveBlock.js → Components/InteractiveBlock.js} +0 -0
- /package/preview/{__main2.js → __main2.js.txt} +0 -0
package/preview/package.json
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
"vite": "^5.4.8"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
15
|
+
"highlight.js": "^11.11.0",
|
|
16
|
+
"jsdom": "^25.0.1",
|
|
17
|
+
"prism": "^4.1.2",
|
|
18
|
+
"ziko": "^0.0.27",
|
|
19
|
+
"ziko-gl": "^0.0.3",
|
|
20
|
+
"ziko-lottie": "^0.0.7",
|
|
21
|
+
"ziko-wrapper": "^0.0.25"
|
|
16
22
|
}
|
|
17
23
|
}
|
package/preview/test.mdz
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
title : "MDZ Overview"
|
|
3
|
+
background : "red"
|
|
4
|
+
__props__ : {
|
|
5
|
+
name : World KKK
|
|
6
|
+
}
|
|
6
7
|
---
|
|
7
|
-
|
|
8
|
+
import {Dom} from "./Components/Dom"
|
|
9
|
+
import InteractiveBlock from "./Components/InteractiveBlock.js"
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
# Hello world
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
<Dom text="Hello from dom" color="red" />
|
|
14
|
+
<InteractiveBlock />
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
Hello **{name}**
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
|Addon|Dependncies|
|
|
19
|
+
|-|-|
|
|
20
|
+
|ziko-gl|threejs|
|
|
21
|
+
|ziko-code|codemirror|
|
|
22
|
+
|ziko-lottie|lottie-web|
|
|
20
23
|
|
|
24
|
+
```js
|
|
25
|
+
console.log({a:1})
|
|
26
|
+
fuction B(){
|
|
27
|
+
return [
|
|
28
|
+
1,
|
|
29
|
+
2
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
21
33
|
|
|
34
|
+
```py
|
|
35
|
+
print(10)
|
|
36
|
+
A=[1,2,3]
|
|
37
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
modules :
|
|
3
|
+
- import InteractiveBlock from "./InteractiveBlock.js"
|
|
4
|
+
- import Scene from "./Scene.js"
|
|
5
|
+
title : MDZ
|
|
6
|
+
background : tomato
|
|
7
|
+
---
|
|
8
|
+
**MDZ** (Markdown for ***zikojs***) is a format that allows you to append Zikojs Elements directly within Markdown.
|
|
9
|
+
|
|
10
|
+
It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
|
|
11
|
+
|
|
12
|
+
Here’s an example of an interactive block rendered within this MDZ file:
|
|
13
|
+
|
|
14
|
+
<InteractiveBlock data="Hello from MDZ" color="cyan"/>
|
|
15
|
+
|
|
16
|
+
### Features of MDZ:
|
|
17
|
+
1- **Simple Integration :** Write Markdown as usual, and inject ZikoJS elements wherever needed.
|
|
18
|
+
2- **Frontmatter Support :** In this example, the title of the document is set dynamically through the frontmatter.
|
|
19
|
+
|
|
20
|
+
3- **Extensible :** Create custom components like InteractiveBlock and use them in any Markdown file.
|
|
21
|
+
|
|
22
|
+
<Scene />
|
|
23
|
+
|
|
24
|
+
|
package/preview/vite.config.js
CHANGED
package/rollup.config.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { transpileMDZ } from "../transpiler/index.js";
|
|
2
|
+
export default function ViteMDZ({extensions = [".mdx"]}={}){
|
|
3
|
+
return {
|
|
4
|
+
name: 'MDZ',
|
|
5
|
+
transform(src, id) {
|
|
6
|
+
if (id.endsWith('.mdz')||extensions.some(ext=>id.endsWith(ext))) {
|
|
7
|
+
return {
|
|
8
|
+
code: transpileMDZ(src),
|
|
9
|
+
map: null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
package/src/example.md
ADDED
package/src/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {MDZ} from "./vite/index.js"
|
|
1
|
+
export * from "./transpiler/index.js"
|
package/src/test.js
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// import { cleanMD } from "./pre-parse/clean-md.js";
|
|
2
|
+
import { parseMDZ, transpileMDZ } from "./transpiler/index.js";
|
|
3
|
+
import { parseYml } from "./utils/parse-yml.js";
|
|
4
|
+
|
|
5
|
+
const md = `---
|
|
6
|
+
title : get started
|
|
7
|
+
id : 1
|
|
8
|
+
__props__ :
|
|
9
|
+
color : red
|
|
10
|
+
size : 10
|
|
9
11
|
---
|
|
10
|
-
Para
|
|
11
|
-
[Link](#hi)
|
|
12
12
|
|
|
13
|
-
<
|
|
13
|
+
<script>
|
|
14
|
+
console.log(1)
|
|
15
|
+
console.log(2)
|
|
16
|
+
|
|
17
|
+
console.log(3)
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
import A from "./A"
|
|
21
|
+
export const b = 10;
|
|
22
|
+
|
|
23
|
+
Hello {name} mm {m} [mmmm](kkk)
|
|
24
|
+
|
|
25
|
+
<B exp={1+1} str="kk">
|
|
26
|
+
# hi
|
|
27
|
+
# hi
|
|
28
|
+
</B>
|
|
29
|
+
|
|
30
|
+
# Hi
|
|
31
|
+
## HI {Ziko}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|A|B|
|
|
35
|
+
|-|-|
|
|
36
|
+
|
|
37
|
+
`
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
// const md = `---
|
|
40
|
+
// title : Hi
|
|
41
|
+
// ---
|
|
42
|
+
// `
|
|
43
|
+
const ast = parseMDZ(md)
|
|
44
|
+
// console.log(ast.children.at(-1))
|
|
45
|
+
const js = transpileMDZ(md)
|
|
46
|
+
console.log(js)
|
|
47
|
+
// console.log(JSON.stringify(ast, null, 2))
|
|
16
48
|
|
|
17
|
-
|
|
18
|
-
<OtherComonenetWithProps data="hello" />
|
|
19
|
-
`;
|
|
20
|
-
const script = getZikoScript(markdownContent);
|
|
21
|
-
console.log(script)
|
|
49
|
+
// parseYml('a : 1\n__props__ : \n d : 2\n e : 1')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkFrontmatter from 'remark-frontmatter';
|
|
4
|
+
import remarkGFM from "remark-gfm";
|
|
5
|
+
import remarkMdx from "remark-mdx"
|
|
6
|
+
|
|
7
|
+
const parseMDZ = (markdown) => unified()
|
|
8
|
+
.use(remarkParse)
|
|
9
|
+
.use(remarkGFM)
|
|
10
|
+
.use(remarkFrontmatter, ['yaml'])
|
|
11
|
+
.use(remarkMdx)
|
|
12
|
+
.parse(markdown)
|
|
13
|
+
|
|
14
|
+
export{parseMDZ}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
componentType,
|
|
3
|
+
processAttribute,
|
|
4
|
+
parseYml,
|
|
5
|
+
hyperscript
|
|
6
|
+
} from "../utils/index.js"
|
|
7
|
+
import hljs from "highlight.js"
|
|
8
|
+
const processMDZAST = (markdownAST) => {
|
|
9
|
+
const transformNode = (node) => {
|
|
10
|
+
switch(node.type){
|
|
11
|
+
case 'mdxjsEsm' : {
|
|
12
|
+
return {
|
|
13
|
+
type : "script",
|
|
14
|
+
value : node.value
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
case 'text' : {
|
|
18
|
+
const text = node.value;
|
|
19
|
+
return `"${text}"`
|
|
20
|
+
}
|
|
21
|
+
case 'mdxTextExpression' : {
|
|
22
|
+
const {value} = node
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
case 'heading' : {
|
|
26
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
27
|
+
return hyperscript(`h${node.depth}`,"{}", childNodes);
|
|
28
|
+
// return `h('h${node.depth}', {}, ${childNodes})`;
|
|
29
|
+
}
|
|
30
|
+
case 'paragraph' : {
|
|
31
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
32
|
+
return hyperscript("p","{}", childNodes)
|
|
33
|
+
// return `h('p', {}, ${childNodes})`
|
|
34
|
+
}
|
|
35
|
+
case 'strong': {
|
|
36
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
37
|
+
return hyperscript("strong","{}", childNodes);
|
|
38
|
+
// return `h('strong', {}, ${childNodes})`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case 'emphasis': {
|
|
42
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
43
|
+
return hyperscript("emphasis","{}", childNodes);
|
|
44
|
+
// return `h('em', {}, ${childNodes})`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
case 'link': {
|
|
48
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
49
|
+
return hyperscript("a", `{ href: "${node.url}" }`, childNodes);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case 'image': {
|
|
53
|
+
hyperscript("img", `{ src: "${node.url}", alt: "${node.alt || ''}`)
|
|
54
|
+
return `h('img', { src: "${node.url}", alt: "${node.alt || ''}" })`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case 'list': {
|
|
58
|
+
const listTag = node.ordered ? 'ol' : 'ul';
|
|
59
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
60
|
+
return hyperscript(listTag, "{}", childNodes);
|
|
61
|
+
// return `h('${listTag}', {}, ${childNodes})`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
case 'listItem': {
|
|
65
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
66
|
+
return hyperscript("li", "{}", childNodes);
|
|
67
|
+
// return `h('li', {}, ${childNodes})`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case 'code': {
|
|
71
|
+
const language = node.lang ? `{ 'data-lang': '${node.lang}' }` : '';
|
|
72
|
+
const highlightedCode = hljs.highlightAuto(node.value, [node.lang || '']).value;
|
|
73
|
+
hljs
|
|
74
|
+
const formatedCode = highlightedCode.replace(/(\r\n|\n|\r)/g, "<br>")
|
|
75
|
+
const out = hyperscript("pre", "{}", hyperscript(
|
|
76
|
+
"code",
|
|
77
|
+
language,
|
|
78
|
+
JSON.stringify(node.value)
|
|
79
|
+
));
|
|
80
|
+
return `HTMLWrapper('<pre>${formatedCode}</pre>')`
|
|
81
|
+
// return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
case 'blockquote': {
|
|
85
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
86
|
+
return hyperscript("blockquote", "{}", childNodes);
|
|
87
|
+
}
|
|
88
|
+
case 'thematicBreak': {
|
|
89
|
+
return `h('hr', {})`;
|
|
90
|
+
}
|
|
91
|
+
case 'table': {
|
|
92
|
+
const headerRows = node.children[0].children.map(transformNode).join(', ');
|
|
93
|
+
const bodyRows = node.children.slice(1).map(transformNode).join(', ');
|
|
94
|
+
const thead = hyperscript("thead", "{}", hyperscript("tr", "{}", headerRows));
|
|
95
|
+
const tbody = hyperscript("tbody", "{}", bodyRows);
|
|
96
|
+
return hyperscript("table", "{}", [thead, tbody].join(","))
|
|
97
|
+
// console.log({thead, tbody})
|
|
98
|
+
// const thead = `h('thead', {}, h('tr', {}, ${headerRows})`;
|
|
99
|
+
// const tbody = `h('tbody', {}, ${bodyRows})`
|
|
100
|
+
// return `h('table', {}, ${thead}), ${tbody}).style({border : "1px solid darkblue", borderCollapse: "collapse"}`;
|
|
101
|
+
}
|
|
102
|
+
case 'tableRow': {
|
|
103
|
+
const cells = node.children.map(transformNode).join(', ');
|
|
104
|
+
return `${hyperscript("tr", "{}", cells)}.style({border : "1px solid darkblue", borderCollapse: "collapse"})`
|
|
105
|
+
// return `h('tr', {}, ${cells}).style({border : "1px solid darkblue", borderCollapse: "collapse"})`;
|
|
106
|
+
}
|
|
107
|
+
case 'tableCell': {
|
|
108
|
+
const childNodes = node.children.map(transformNode).join(', ');
|
|
109
|
+
return `${hyperscript("td", "{}", childNodes)}.style({border : "1px solid darkblue", borderCollapse: "collapse", padding : "5px"})`
|
|
110
|
+
// return `h('td', {}, ${childNodes}).style({border : "1px solid darkblue", borderCollapse: "collapse", padding : "5px"})`;
|
|
111
|
+
}
|
|
112
|
+
case 'yaml':{
|
|
113
|
+
const {props, attrs} = parseYml(node.value)
|
|
114
|
+
return {
|
|
115
|
+
type : "yaml",
|
|
116
|
+
props,
|
|
117
|
+
attrs
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
case 'mdxJsxFlowElement':{
|
|
121
|
+
const {name, attributes, children} = node;
|
|
122
|
+
const childNodes = children.map(transformNode).join(', ');
|
|
123
|
+
const hasChildren = childNodes.length > 0;
|
|
124
|
+
console.log({name})
|
|
125
|
+
console.log(componentType(name))
|
|
126
|
+
switch(componentType(name)){
|
|
127
|
+
case "jsx" : return `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
128
|
+
case "html" : return `h("${name}", ${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
129
|
+
case "script" : {
|
|
130
|
+
const statements = [];
|
|
131
|
+
for(let i=0; i<node.children.length; i++) statements.push(node.children[i].children[0].value)
|
|
132
|
+
return {
|
|
133
|
+
type : "script",
|
|
134
|
+
isScript : true,
|
|
135
|
+
value : statements.join("\n")
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return 'null';
|
|
142
|
+
};
|
|
143
|
+
let esm = [];
|
|
144
|
+
let props = "";
|
|
145
|
+
let attrs = "";
|
|
146
|
+
|
|
147
|
+
const statements = []
|
|
148
|
+
markdownAST.children.forEach((node) => {
|
|
149
|
+
switch(node.type){
|
|
150
|
+
case 'yaml' : {
|
|
151
|
+
const Transformed = transformNode(node)
|
|
152
|
+
props = Transformed.props,
|
|
153
|
+
attrs = Transformed.attrs
|
|
154
|
+
} break;
|
|
155
|
+
case 'mdxjsEsm' : esm.push(node.value); break;
|
|
156
|
+
default : {
|
|
157
|
+
const Transformed = transformNode(node);
|
|
158
|
+
if(Transformed.isScript) statements.push(Transformed.value);
|
|
159
|
+
else statements.push(`__items__.push(${Transformed})`)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
attrs,
|
|
165
|
+
props,
|
|
166
|
+
esm,
|
|
167
|
+
statements
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
export {
|
|
171
|
+
processMDZAST
|
|
172
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parseMDZ } from "./parser.js";
|
|
2
|
+
import { processMDZAST } from "./process.js";
|
|
3
|
+
|
|
4
|
+
const transpileMDZ=(Markdown)=>{
|
|
5
|
+
const ast = parseMDZ(Markdown);
|
|
6
|
+
const {attrs, props, esm, statements}= processMDZAST(ast)
|
|
7
|
+
console.log({props})
|
|
8
|
+
const body = [
|
|
9
|
+
'import {h, HTMLWrapper, Flex} from "ziko"',
|
|
10
|
+
attrs,
|
|
11
|
+
...esm,
|
|
12
|
+
`export default (${props})=>{`,
|
|
13
|
+
'const __items__ = []',
|
|
14
|
+
...statements,
|
|
15
|
+
"const UI = Flex(...__items__).vertical(0, 0)",
|
|
16
|
+
"return UI }"
|
|
17
|
+
]
|
|
18
|
+
return body.join("\n");
|
|
19
|
+
}
|
|
20
|
+
export{
|
|
21
|
+
transpileMDZ
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
|
|
3
|
+
const parseYml = yml => {
|
|
4
|
+
const {__props__, ...__attrs__} = parse(yml) ;
|
|
5
|
+
const HasAttributs = Object.keys(__attrs__).length > 0
|
|
6
|
+
return {
|
|
7
|
+
props : __props__
|
|
8
|
+
?`{${Object.entries(__props__).map(([key, value]) => `${key} = ${JSON.stringify(value)}`).join(", ")}}={}`
|
|
9
|
+
:"",
|
|
10
|
+
attrs : HasAttributs
|
|
11
|
+
?[
|
|
12
|
+
`const {${Object.keys(__attrs__).join(",")}} = ${JSON.stringify(__attrs__,"",2)}`,
|
|
13
|
+
`export {${Object.keys(__attrs__).join(", ")}}`
|
|
14
|
+
].join("\n")
|
|
15
|
+
: ""
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {parseYml}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const processAttribute = (attributes) =>{
|
|
2
|
+
if(attributes.length === 0) return "{}"
|
|
3
|
+
let attr = []
|
|
4
|
+
for(let i=0; i<attributes.length ; i++){
|
|
5
|
+
let {name, value} = attributes[i]
|
|
6
|
+
attr.push({
|
|
7
|
+
name,
|
|
8
|
+
value : typeof value === "string" ? value : value.value,
|
|
9
|
+
isExpression : typeof value !== "string"
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
return `{${attr.map(({name, value, isExpression})=>`${name}:${isExpression ? value : `"${value}"`}`).join(", ")}}`
|
|
13
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|