Skip to content

Commit 6f3b4e1

Browse files
add props and fix multiline components
1 parent 450b66a commit 6f3b4e1

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ isProduction &&
5757
);
5858

5959
export default {
60-
input: "src/index.js",
60+
input: "v2/index.js",
6161
output,
6262
external: ["ziko"],
6363
plugins: [

v2/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { transpileMDZ } from "./transpiler/index.js"
2+
export {ViteMDZ} from "./transformers/vite/index.js"

v2/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## features :
2+
3+
✅ Frontmatter
4+
✅ Props
5+
✅ Markdown
6+
✅ Html
7+
✅ Zikojs Components
8+
9+
## To Do
10+
11+
Async Directive
12+
Expressions
13+
Smart Links
14+
Latex
15+
Math

v2/test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ const Markdown = `
44
title: "Example Page"
55
author: "John Doe"
66
count : 10
7+
__Props__ : {
8+
color : "red",
9+
id : 10
10+
}
711
---
812
913
import Button from './Button.js';
1014
11-
# Hello World <Button data = "100"/>
15+
# Hello World
16+
<Button
17+
data="100"
18+
p="kkk"
19+
/>
1220
1321
This is a paragraph with <Button data="hello"/>
1422
@@ -26,4 +34,5 @@ This is a paragraph with <Button data="hello"/>
2634
console.log(transpileMDZ(Markdown))
2735

2836
// const md2 = "```js \n console.log(1) \n ```"
29-
// console.log(transpileMDZ(md2))
37+
// console.log(transpileMDZ(md2))
38+

v2/transformers/vite/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { transpileMDZ } from "../../transpiler/index.js";
2-
export function MDZ(){
2+
export function ViteMDZ(){
33
return {
44
name: 'MDZ',
55
transform(src, id) {

v2/transpiler/index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ const transformMDZ = (markdownAST) => {
8686
}
8787
case 'html' : {
8888
const component = node.value.trim();
89+
console.log({component})
8990
const type = getComponentType(component);
9091
switch (type) {
9192
case 'jsx':
92-
return ` ${jsx2js(component)}`;
93+
return ` ${jsx2js(component.replaceAll("\n",""))}`;
9394
case 'html':
9495
return ` HTMLWrapper("${component}")`;
9596
default:
@@ -103,22 +104,36 @@ const transformMDZ = (markdownAST) => {
103104
};
104105

105106
const body = markdownAST.children.map(transformNode).join(',\n');
106-
return `()=>Flex(
107-
${body}
108-
).vertical(0,0)`
107+
return body
108+
// return `const UI=()=>Flex(
109+
// ${body}
110+
// ).vertical(0,0)
111+
// export default UI
112+
// `
109113
};
110114

111115
const transpileMDZ= markdown =>{
112116
const { imports, frontmatter, cleanedMarkdown } = processMDZ(markdown);
113117
const ast = parseMDZ(cleanedMarkdown);
114-
const jsFunction = transformMDZ(ast);
118+
const {__Props__, ...Attr} = frontmatter
119+
const body = transformMDZ(ast);
120+
const defaultProps = __Props__
121+
? Object.entries(__Props__)
122+
.map(([key, value]) => `${key} = ${JSON.stringify(value)}`)
123+
.join(', ')
124+
: '';
125+
let ui = `const UI=({${defaultProps}})=>Flex(
126+
${body}
127+
).vertical(0,0);
128+
export default UI;
129+
`
115130
let exports = `
116-
const attributes = ${JSON.stringify(frontmatter)};
117-
export {${Object.keys(frontmatter)}} = attributes;
131+
const Attr = ${JSON.stringify(Attr)};
132+
export {${Object.keys(Attr)}} = Attr;
118133
`
119134
const Output = [
120135
...imports,
121-
jsFunction,
136+
ui,
122137
exports,
123138
].join('\n');
124139

0 commit comments

Comments
 (0)