mdzjs 0.0.1 → 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 +70 -56
- package/__src__/index.js +2 -0
- package/__src__/test.js +21 -0
- package/{v2/test.js → __v2__/_test.js} +1 -1
- package/__v2__/clean.js +67 -0
- package/__v2__/hast.js +70 -0
- package/__v2__/html2js.js +59 -0
- package/__v2__/pre-parse/clean-md.js +93 -0
- package/__v2__/test.js +19 -0
- package/{v2 → __v2__}/transpiler/index.js +17 -12
- package/__v2__/utils/is-object.js +11 -0
- package/__v2__/utils/split-between.js +47 -0
- package/package.json +12 -6
- package/preview/Components/Dom.js +6 -0
- package/preview/index.html +10 -1
- package/preview/main.js +8 -17
- package/preview/package-lock.json +712 -8
- package/preview/package.json +6 -2
- package/preview/test.mdz +27 -49
- package/preview/vite.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/v2/pre-parse/clean-md.js +0 -93
- /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/{v2 → __v2__}/index.js +0 -0
- /package/{v2 → __v2__}/readme.md +0 -0
- /package/{v2 → __v2__}/transformers/vite/index.js +0 -0
- /package/{v2 → __v2__}/transpiler/get-component-type.js +0 -0
- /package/{v2 → __v2__}/transpiler/import-plugin.js +0 -0
- /package/{v2 → __v2__}/transpiler/jsx2js.js +0 -0
- /package/{v2 → __v2__}/transpiler/process-text.js +0 -0
- /package/preview/{Hi.js → Components/Hi.js} +0 -0
- /package/preview/{InteractiveBlock.js → Components/InteractiveBlock.js} +0 -0
- /package/preview/{Scene.js → Components/Scene.js} +0 -0
- /package/preview/{__main2.js → __main2.js.txt} +0 -0
package/preview/package.json
CHANGED
|
@@ -12,8 +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",
|
|
16
19
|
"ziko-gl": "^0.0.3",
|
|
17
|
-
"ziko-lottie": "^0.0.7"
|
|
20
|
+
"ziko-lottie": "^0.0.7",
|
|
21
|
+
"ziko-wrapper": "^0.0.25"
|
|
18
22
|
}
|
|
19
23
|
}
|
package/preview/test.mdz
CHANGED
|
@@ -1,59 +1,37 @@
|
|
|
1
1
|
---
|
|
2
|
-
title : "MDZ"
|
|
2
|
+
title : "MDZ Overview"
|
|
3
3
|
background : "red"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
c : 10
|
|
4
|
+
__props__ : {
|
|
5
|
+
name : World KKK
|
|
7
6
|
}
|
|
8
7
|
---
|
|
8
|
+
import {Dom} from "./Components/Dom"
|
|
9
|
+
import InteractiveBlock from "./Components/InteractiveBlock.js"
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
import InteractiveBlock from "./InteractiveBlock.js";
|
|
12
|
-
import Scene from "./Scene.js";
|
|
11
|
+
# Hello world
|
|
13
12
|
|
|
14
|
-
Hello
|
|
13
|
+
<Dom text="Hello from dom" color="red" />
|
|
14
|
+
<InteractiveBlock />
|
|
15
15
|
|
|
16
|
-
Hello {
|
|
16
|
+
Hello **{name}**
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
var a = 1000
|
|
20
|
-
const b = ()=> Math.random()
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
test {a}
|
|
24
|
-
|
|
25
|
-
<InteractiveBlock data="Hello from MDZ" color="cyan"/>
|
|
26
|
-
|
|
27
|
-
import Hi from "./Hi.js";
|
|
28
|
-
|
|
29
|
-
- <Hi txt="Messi" color="red"/>
|
|
30
|
-
- <Hi txt="Messi" color="red"/>
|
|
31
|
-
- <Hi txt="Messi" color="red"/>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- <Scene data="h"/>
|
|
35
|
-
|
|
36
|
-
|A|B|
|
|
18
|
+
|Addon|Dependncies|
|
|
37
19
|
|-|-|
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let y = cos(x)
|
|
52
|
-
import {sin} from "ziko"
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
- **cos(x[0])** : <Hi txt={1+1} />
|
|
56
|
-
|
|
57
|
-
-->
|
|
20
|
+
|ziko-gl|threejs|
|
|
21
|
+
|ziko-code|codemirror|
|
|
22
|
+
|ziko-lottie|lottie-web|
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
console.log({a:1})
|
|
26
|
+
fuction B(){
|
|
27
|
+
return [
|
|
28
|
+
1,
|
|
29
|
+
2
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
58
33
|
|
|
59
|
-
|
|
34
|
+
```py
|
|
35
|
+
print(10)
|
|
36
|
+
A=[1,2,3]
|
|
37
|
+
```
|
package/preview/vite.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
|
+
}
|
package/v2/pre-parse/clean-md.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
function cleanMD(str) {
|
|
2
|
-
const result = [];
|
|
3
|
-
let currentExpr = '';
|
|
4
|
-
let currentText = '';
|
|
5
|
-
let braceCount = 0;
|
|
6
|
-
for (let i = 0; i < str.length; i++) {
|
|
7
|
-
const char = str[i];
|
|
8
|
-
if (char === '{') {
|
|
9
|
-
if (braceCount === 0 && currentText) {
|
|
10
|
-
result.push(currentText.trim());
|
|
11
|
-
currentText = '';
|
|
12
|
-
}
|
|
13
|
-
braceCount++;
|
|
14
|
-
currentExpr += char;
|
|
15
|
-
} else if (char === '}') {
|
|
16
|
-
braceCount--;
|
|
17
|
-
currentExpr += char;
|
|
18
|
-
if (braceCount === 0) {
|
|
19
|
-
result.push(cleanExpression(currentExpr));
|
|
20
|
-
currentExpr = '';
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
if (braceCount === 0) {
|
|
24
|
-
currentText += char;
|
|
25
|
-
} else {
|
|
26
|
-
currentExpr += char;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (currentText) {
|
|
31
|
-
result.push(currentText.trim());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return result.join('');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function cleanExpression(block) {
|
|
38
|
-
const content = block.slice(1, -1);
|
|
39
|
-
const cleanedContent = content
|
|
40
|
-
.split('\n')
|
|
41
|
-
.map(line => line.trim())
|
|
42
|
-
.filter(line => line)
|
|
43
|
-
.join('\n');
|
|
44
|
-
return `{\n${cleanedContent}\n}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// const text = `
|
|
48
|
-
// const obj = {
|
|
49
|
-
|
|
50
|
-
// key1: 'value1',
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// key2: 'value2',
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// key3: {
|
|
57
|
-
// nestedKey1: 'nestedValue1',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// nestedKey2: 'nestedValue2',
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// nestedKey3: {
|
|
64
|
-
|
|
65
|
-
// deepKey: 'deepValue'
|
|
66
|
-
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
|
-
// }
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// };
|
|
73
|
-
|
|
74
|
-
// export default {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// keyA: 'valueA',
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// keyB: {
|
|
81
|
-
|
|
82
|
-
// nestedKey: 'nestedValue'
|
|
83
|
-
|
|
84
|
-
// }
|
|
85
|
-
|
|
86
|
-
// };
|
|
87
|
-
// `;
|
|
88
|
-
|
|
89
|
-
// console.log(cleanMD(text));
|
|
90
|
-
|
|
91
|
-
export{
|
|
92
|
-
cleanMD
|
|
93
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{v2 → __v2__}/index.js
RENAMED
|
File without changes
|
/package/{v2 → __v2__}/readme.md
RENAMED
|
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
|
|
File without changes
|