van-mdx 0.4.0 → 0.6.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 +1 -1
- package/package.json +39 -38
- package/src/loaders/vite/index.js +35 -0
- package/src/transpiler/index.js +33 -2
- package/src/bundlers/astro/entry-client.js +0 -20
- package/src/bundlers/astro/entry-server.js +0 -19
- package/src/bundlers/astro/index.js +0 -39
- package/src/bundlers/vite/index.js +0 -15
- package/src/index.js +0 -0
- package/src/transpiler/process.js +0 -172
- package/src/transpiler/transpile.js +0 -23
- package/src/utils/component-type.js +0 -5
- package/src/utils/hyperscript.js +0 -30
- package/src/utils/index.js +0 -4
- package/src/utils/parse-yml.js +0 -23
- package/src/utils/process-attributes.js +0 -13
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ It combines the simplicity of Markdown syntax with the power and flexibility of
|
|
|
6
6
|
## Demos :
|
|
7
7
|
- ***Hello World*** :
|
|
8
8
|
[](https://stackblitz.com/fork/github/zakarialaoui10/van-mdx/tree/main/examples/hello-world?file=src%2Fcontent%2FArticle.mdx)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
## Install :
|
|
11
11
|
|
|
12
12
|
```bash
|
package/package.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "van-mdx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Markdown preprocessor for Vanjs",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"vanjs",
|
|
9
|
-
"astro-integration",
|
|
10
|
-
"mdx",
|
|
11
|
-
"markdown",
|
|
12
|
-
"preprocessor"
|
|
13
|
-
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
-
},
|
|
17
|
-
"exports": {
|
|
18
|
-
".": "./src/index.js",
|
|
19
|
-
"
|
|
20
|
-
"./astro": "./src/bundlers/astro/index.js",
|
|
21
|
-
"./astro/entry-client": "./src/bundlers/astro/entry-client.js",
|
|
22
|
-
"./astro/entry-server": "./src/bundlers/astro/entry-server.js"
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "van-mdx",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Markdown preprocessor for Vanjs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"vanjs",
|
|
9
|
+
"astro-integration",
|
|
10
|
+
"mdx",
|
|
11
|
+
"markdown",
|
|
12
|
+
"preprocessor"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.js",
|
|
19
|
+
"./*": "./src/loaders/*/index.js",
|
|
20
|
+
"./astro": "./src/bundlers/astro/index.js",
|
|
21
|
+
"./astro/entry-client": "./src/bundlers/astro/entry-client.js",
|
|
22
|
+
"./astro/entry-server": "./src/bundlers/astro/entry-server.js"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/zakarialaoui10/van-mdx.git"
|
|
27
|
+
},
|
|
28
|
+
"author": "zakaria elalaoui",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/zakarialaoui10/van-mdx/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/zakarialaoui10/van-mdx#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"mdzjs": "^0.15.1",
|
|
36
|
+
"vanjs-core": "^1.6.0",
|
|
37
|
+
"ziko": "^0.64.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { transpileMD } from '../../transpiler/index.js';
|
|
2
|
+
|
|
3
|
+
export default function ViteMDVan({ extensions = ['.mdx'], plugins } = {}) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'van-mdx',
|
|
6
|
+
async transform(src, id) {
|
|
7
|
+
if (id.endsWith('.mdv') || extensions.some((ext) => id.endsWith(ext))) {
|
|
8
|
+
const code = await transpileMD(src, {plugins});
|
|
9
|
+
return {
|
|
10
|
+
code,
|
|
11
|
+
map: null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
handleHotUpdate({ file, server }) {
|
|
17
|
+
if (file.endsWith('.mdv')) {
|
|
18
|
+
// console.log({file})
|
|
19
|
+
server.ws.send({
|
|
20
|
+
type : 'full-reload'
|
|
21
|
+
})
|
|
22
|
+
// server.ws.send({
|
|
23
|
+
// type: 'custom',
|
|
24
|
+
// event: 'custom-update',
|
|
25
|
+
// data: {
|
|
26
|
+
// file,
|
|
27
|
+
// timestamp: Date.now(),
|
|
28
|
+
// },
|
|
29
|
+
// });
|
|
30
|
+
|
|
31
|
+
return [file];
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/transpiler/index.js
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import{
|
|
2
|
+
parseMD,
|
|
3
|
+
processMDAST,
|
|
4
|
+
stringifyProps,
|
|
5
|
+
transformeAttrs
|
|
6
|
+
} from 'mdzjs'
|
|
7
|
+
|
|
8
|
+
const transpileMD = async (Markdown, {plugins = []} = {})=>{
|
|
9
|
+
const {ast, frontmatter} = await parseMD(Markdown.trimStart(), ...plugins);
|
|
10
|
+
const {esm, statements, hasCode, Tags}= processMDAST(ast);
|
|
11
|
+
|
|
12
|
+
const { 'Van.Props': props, ...attrs } = frontmatter;
|
|
13
|
+
|
|
14
|
+
const body = [
|
|
15
|
+
"import van from 'vanjs-core'",
|
|
16
|
+
hasCode ?? "import {HTMLWrapper as _HTMLWrapper} from 'ziko/ui';",
|
|
17
|
+
hasCode ?? "const HTMLWrapper = (html) => _HTMLWrapper(html).element;",
|
|
18
|
+
...esm,
|
|
19
|
+
transformeAttrs(attrs),
|
|
20
|
+
`export default (${stringifyProps(props)})=>{`,
|
|
21
|
+
`const {${[...Tags].join(', ')}} = van.tags`,
|
|
22
|
+
'const __items__ = []',
|
|
23
|
+
...statements,
|
|
24
|
+
'return __items__',
|
|
25
|
+
'}',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
// if(hasCode) body.unshift(`import("highlight.js/styles/${CodeStyle}.css")`);
|
|
29
|
+
return body.filter(Boolean).join("\n");
|
|
30
|
+
}
|
|
31
|
+
export{
|
|
32
|
+
transpileMD
|
|
33
|
+
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export default function (wrapper) {
|
|
2
|
-
return (Component, props, { default: children, ...slotted }, {client}) => {
|
|
3
|
-
// if (!wrapper.hasAttribute("ssr")){
|
|
4
|
-
// console.log("ssr")
|
|
5
|
-
// return
|
|
6
|
-
// }
|
|
7
|
-
console.log({wrapper})
|
|
8
|
-
console.log(`Client ...`)
|
|
9
|
-
wrapper.setAttribute("data-engine","van-mdx")
|
|
10
|
-
const properties = props ?? {};
|
|
11
|
-
switch(client){
|
|
12
|
-
case "only" : wrapper.append(Component(properties)); break;
|
|
13
|
-
default : {
|
|
14
|
-
wrapper.innerHTML = ""
|
|
15
|
-
console.log(`Client Hydration : ${Component}`)
|
|
16
|
-
wrapper.append(Component(properties)); break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {renderDomToString } from "ziko-server/server-only-utils"
|
|
2
|
-
function check(Component, attributes) {
|
|
3
|
-
if (typeof Component !== "function") return false;
|
|
4
|
-
return true
|
|
5
|
-
}
|
|
6
|
-
async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
|
|
7
|
-
console.log(`renderToStaticMarkup : ${Component}`)
|
|
8
|
-
const UI = Component(props)
|
|
9
|
-
const html = renderDomToString(UI)
|
|
10
|
-
return {
|
|
11
|
-
html,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
name : "astro-van-mdx",
|
|
17
|
-
check,
|
|
18
|
-
renderToStaticMarkup
|
|
19
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import ViteVanMdx from "../vite/index.js"
|
|
2
|
-
const AstroVanMdx = () => ({
|
|
3
|
-
name: "astro-van-mdx",
|
|
4
|
-
hooks: {
|
|
5
|
-
"astro:config:setup": async ({ updateConfig, addRenderer }) => {
|
|
6
|
-
updateConfig({
|
|
7
|
-
vite : {
|
|
8
|
-
plugins : [
|
|
9
|
-
ViteVanMdx()
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
addRenderer({
|
|
14
|
-
name: "astro-van-mdx",
|
|
15
|
-
serverEntrypoint: "van-mdx/astro/entry-server",
|
|
16
|
-
clientEntrypoint: "van-mdx/astro/entry-client",
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
export default AstroVanMdx;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// import ViteVanMdx from "../vite/index.js";
|
|
25
|
-
// const AstroVanMdx = () => ({
|
|
26
|
-
// name: "astro-mdzjs",
|
|
27
|
-
// hooks: {
|
|
28
|
-
// "astro:config:setup": async ({ updateConfig }) => {
|
|
29
|
-
// updateConfig({
|
|
30
|
-
// vite : {
|
|
31
|
-
// plugins : [
|
|
32
|
-
// ViteVanMdx()
|
|
33
|
-
// ]
|
|
34
|
-
// }
|
|
35
|
-
// })
|
|
36
|
-
// },
|
|
37
|
-
// },
|
|
38
|
-
// });
|
|
39
|
-
// export default AstroVanMdx;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { transpileMD } from "../../transpiler/index.js";
|
|
2
|
-
export default function VanMdx(){
|
|
3
|
-
return {
|
|
4
|
-
name: 'VanMdx',
|
|
5
|
-
transform(src, id) {
|
|
6
|
-
if (id.endsWith('.mdx')) {
|
|
7
|
-
return {
|
|
8
|
-
code: transpileMD(src),
|
|
9
|
-
map: null,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
package/src/index.js
DELETED
|
File without changes
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
componentType,
|
|
3
|
-
processAttribute,
|
|
4
|
-
parseYml,
|
|
5
|
-
hyperscript
|
|
6
|
-
} from "../utils/index.js"
|
|
7
|
-
import hljs from "highlight.js"
|
|
8
|
-
const processMDAST = (markdownAST) => {
|
|
9
|
-
let hasCode = false;
|
|
10
|
-
const transformNode = (node) => {
|
|
11
|
-
switch(node.type){
|
|
12
|
-
case 'mdxjsEsm' : {
|
|
13
|
-
return {
|
|
14
|
-
type : "script",
|
|
15
|
-
value : node.value
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
case 'text' : {
|
|
19
|
-
const text = node.value;
|
|
20
|
-
const escaped = text.replace(/"/g, '\\"');
|
|
21
|
-
return `"${escaped}"`;
|
|
22
|
-
};
|
|
23
|
-
case 'mdxTextExpression' : {
|
|
24
|
-
const {value} = node
|
|
25
|
-
return value
|
|
26
|
-
};
|
|
27
|
-
case 'heading' : {
|
|
28
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
29
|
-
return hyperscript(`h${node.depth}`,"{}", childNodes);
|
|
30
|
-
};
|
|
31
|
-
case 'paragraph' : {
|
|
32
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
33
|
-
return hyperscript("p","{}", childNodes)
|
|
34
|
-
};
|
|
35
|
-
case 'strong': {
|
|
36
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
37
|
-
return hyperscript("strong","{}", childNodes);
|
|
38
|
-
};
|
|
39
|
-
case 'emphasis': {
|
|
40
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
41
|
-
return hyperscript("em","{}", childNodes);
|
|
42
|
-
};
|
|
43
|
-
case 'link': {
|
|
44
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
45
|
-
return hyperscript("a", `{ href: "${node.url}" }`, childNodes);
|
|
46
|
-
};
|
|
47
|
-
case 'image': {
|
|
48
|
-
hyperscript("img", `{ src: "${node.url}", alt: "${node.alt || ''}`)
|
|
49
|
-
return `h('img', { src: "${node.url}", alt: "${node.alt || ''}" })`;
|
|
50
|
-
};
|
|
51
|
-
case 'list': {
|
|
52
|
-
const listTag = node.ordered ? 'ol' : 'ul';
|
|
53
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
54
|
-
return hyperscript(listTag, "{}", childNodes);
|
|
55
|
-
};
|
|
56
|
-
case 'listItem': {
|
|
57
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
58
|
-
return hyperscript("li", "{}", childNodes);
|
|
59
|
-
};
|
|
60
|
-
case 'inlineCode' : {
|
|
61
|
-
return `van.tags.code("${node.value}")`
|
|
62
|
-
}
|
|
63
|
-
case 'code': {
|
|
64
|
-
hasCode = true;
|
|
65
|
-
// const language = node.lang ? `{ 'data-lang': '${node.lang}' }` : '';
|
|
66
|
-
const highlightedCode = hljs.highlightAuto(node.value, [node.lang || '']).value;
|
|
67
|
-
const formatedCode = highlightedCode.replace(/(\r\n|\n|\r)/g, "<br>")
|
|
68
|
-
return `HTMLWrapper('<pre><code>${formatedCode}</code></pre>').element`
|
|
69
|
-
}
|
|
70
|
-
case 'blockquote': {
|
|
71
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
72
|
-
return hyperscript("blockquote", "{}", childNodes);
|
|
73
|
-
}
|
|
74
|
-
case 'thematicBreak': {
|
|
75
|
-
return `van.tags.hr()`;
|
|
76
|
-
}
|
|
77
|
-
case 'table': {
|
|
78
|
-
const headerRows = node.children[0].children.map(transformNode).join(', ');
|
|
79
|
-
const bodyRows = node.children.slice(1).map(transformNode).join(', ');
|
|
80
|
-
const thead = hyperscript("thead", "{}", hyperscript("tr", "{}", headerRows));
|
|
81
|
-
const tbody = hyperscript("tbody", "{}", bodyRows);
|
|
82
|
-
return hyperscript("table", "{}", [thead, tbody].join(","))
|
|
83
|
-
}
|
|
84
|
-
case 'tableRow': {
|
|
85
|
-
const cells = node.children.map(transformNode).join(', ');
|
|
86
|
-
return `${hyperscript("tr", "{}", cells)}`
|
|
87
|
-
return `${hyperscript("tr", "{}", cells)}.style({border : "1px solid darkblue", borderCollapse: "collapse"})`
|
|
88
|
-
}
|
|
89
|
-
case 'tableCell': {
|
|
90
|
-
const childNodes = node.children.map(transformNode).join(', ');
|
|
91
|
-
return `${hyperscript("td", "{}", childNodes)}`
|
|
92
|
-
return `${hyperscript("td", "{}", childNodes)}.style({border : "1px solid darkblue", borderCollapse: "collapse", padding : "5px"})`
|
|
93
|
-
}
|
|
94
|
-
case 'yaml':{
|
|
95
|
-
const {props, attrs} = parseYml(node.value)
|
|
96
|
-
return {
|
|
97
|
-
type : "yaml",
|
|
98
|
-
props,
|
|
99
|
-
attrs
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
case 'mdxJsxTextElement': {
|
|
103
|
-
const {name, attributes, children} = node;
|
|
104
|
-
const childNodes = children.map(transformNode).join(', ');
|
|
105
|
-
const hasChildren = childNodes.length > 0;
|
|
106
|
-
return `van.tags.${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
107
|
-
};
|
|
108
|
-
case 'mdxJsxFlowElement':{
|
|
109
|
-
const {name, attributes, children} = node;
|
|
110
|
-
const childNodes = children.map(transformNode).join(', ');
|
|
111
|
-
const hasChildren = childNodes.length > 0;
|
|
112
|
-
switch(componentType(name)){
|
|
113
|
-
case "jsx" : {
|
|
114
|
-
console.log({
|
|
115
|
-
Component : name,
|
|
116
|
-
children,
|
|
117
|
-
})
|
|
118
|
-
const f = `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`
|
|
119
|
-
console.log({f})
|
|
120
|
-
return `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
121
|
-
}
|
|
122
|
-
case "html" : {
|
|
123
|
-
return `van.tags.${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
124
|
-
}
|
|
125
|
-
case "script" : {
|
|
126
|
-
const statements = [];
|
|
127
|
-
for(let i=0; i<node.children.length; i++) statements.push(node.children[i].children[0].value)
|
|
128
|
-
return {
|
|
129
|
-
type : "script",
|
|
130
|
-
isScript : true,
|
|
131
|
-
value : statements.join("\n")
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
default : {
|
|
137
|
-
console.log(node.type)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return 'null';
|
|
141
|
-
};
|
|
142
|
-
let esm = [];
|
|
143
|
-
let props = "";
|
|
144
|
-
let attrs = "";
|
|
145
|
-
|
|
146
|
-
const statements = []
|
|
147
|
-
markdownAST.children.forEach((node) => {
|
|
148
|
-
switch(node.type){
|
|
149
|
-
case 'yaml' : {
|
|
150
|
-
const Transformed = transformNode(node)
|
|
151
|
-
props = Transformed.props;
|
|
152
|
-
attrs = Transformed.attrs;
|
|
153
|
-
} break;
|
|
154
|
-
case 'mdxjsEsm' : esm.push(node.value); break;
|
|
155
|
-
default : {
|
|
156
|
-
const Transformed = transformNode(node);
|
|
157
|
-
if(Transformed.isScript) statements.push(Transformed.value);
|
|
158
|
-
else statements.push(`__items__.push(${Transformed})`)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
return {
|
|
163
|
-
attrs,
|
|
164
|
-
props,
|
|
165
|
-
esm,
|
|
166
|
-
statements,
|
|
167
|
-
hasCode
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
export {
|
|
171
|
-
processMDAST
|
|
172
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { parseMarkdown } from "mdzjs";
|
|
2
|
-
import { processMDAST } from "./process.js";
|
|
3
|
-
import { stringifyProps } from "../utils/parse-yml.js";
|
|
4
|
-
|
|
5
|
-
const transpileMD=(Markdown)=>{
|
|
6
|
-
const ast = parseMarkdown(Markdown);
|
|
7
|
-
const {attrs, props, esm, statements, hasCode}= processMDAST(ast)
|
|
8
|
-
const body = [
|
|
9
|
-
'import van from "vanjs-core"',
|
|
10
|
-
'import { HTMLWrapper } from "ziko"',
|
|
11
|
-
attrs,
|
|
12
|
-
...esm,
|
|
13
|
-
`export default (${stringifyProps(props)})=>{`,
|
|
14
|
-
'const __items__ = []',
|
|
15
|
-
...statements,
|
|
16
|
-
"const UI = van.tags.div(...__items__)",
|
|
17
|
-
"return UI }"
|
|
18
|
-
]
|
|
19
|
-
return body.join("\n");
|
|
20
|
-
}
|
|
21
|
-
export{
|
|
22
|
-
transpileMD
|
|
23
|
-
}
|
package/src/utils/hyperscript.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const hyperscript = (tag, attrs, children="") => {
|
|
2
|
-
const HasChildren = !!children;
|
|
3
|
-
|
|
4
|
-
if(tag){
|
|
5
|
-
children = ',""' + children + ',""'
|
|
6
|
-
const splitted = splitQuotedLines(children);
|
|
7
|
-
children = insertBetween(splitted, 'van.tags.br()')
|
|
8
|
-
children[children.length - 1] = children.at(-1).slice(0, -3)
|
|
9
|
-
children[0] = children.at(0).slice(3)
|
|
10
|
-
}
|
|
11
|
-
return `van.tags.${tag}(${attrs}${HasChildren ?`, ${children}` : ""})`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function splitQuotedLines(str) {
|
|
15
|
-
return str
|
|
16
|
-
.slice(1, -1)
|
|
17
|
-
.split(/\r\n|\r|\n/)
|
|
18
|
-
.map(line => `"${line}"`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function insertBetween(arr, value) {
|
|
22
|
-
const result = [];
|
|
23
|
-
for (let i = 0; i < arr.length; i++) {
|
|
24
|
-
result.push(arr[i]);
|
|
25
|
-
if (i < arr.length - 1) {
|
|
26
|
-
result.push(value);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
package/src/utils/index.js
DELETED
package/src/utils/parse-yml.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { parse } from 'yaml';
|
|
2
|
-
|
|
3
|
-
const parseYml = yml => {
|
|
4
|
-
const {__props__, ...__attrs__} = yml ? parse(yml) : {__props__ : {}} ;
|
|
5
|
-
const HasAttributs = Object.keys(__attrs__).length > 0
|
|
6
|
-
return {
|
|
7
|
-
props : __props__,
|
|
8
|
-
attrs : HasAttributs
|
|
9
|
-
?[
|
|
10
|
-
`const {${Object.keys(__attrs__).join(",")}} = ${JSON.stringify(__attrs__,"",2)}`,
|
|
11
|
-
`export {${Object.keys(__attrs__).join(", ")}}`
|
|
12
|
-
].join("\n")
|
|
13
|
-
: "",
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const stringifyProps = (props) =>{
|
|
18
|
-
return props
|
|
19
|
-
?`{${Object.entries(props).map(([key, value]) => `${key} = ${JSON.stringify(value)}`).join(", ")}}={}`
|
|
20
|
-
:""
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {parseYml, stringifyProps}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|