mdzjs 0.0.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/LICENSE +21 -0
- package/README.md +84 -0
- package/package.json +37 -0
- package/preview/InteractiveBlock.js +21 -0
- package/preview/__main2.js +49 -0
- package/preview/index.html +27 -0
- package/preview/main.js +12 -0
- package/preview/package-lock.json +864 -0
- package/preview/package.json +17 -0
- package/preview/public/vite.svg +1 -0
- package/preview/src/pages/[blog]/[lang]/index.js +3 -0
- package/preview/src/pages/[blog]/index.js +3 -0
- package/preview/src/pages/about.js +6 -0
- package/preview/src/pages/articles/[data]/[color]/index.js +6 -0
- package/preview/src/pages/articles/a1.js +6 -0
- package/preview/src/pages/index.js +20 -0
- package/preview/src/pages/me.js +3 -0
- package/preview/test.mdz +21 -0
- package/preview/vite.config.js +5 -0
- package/rollup.config.js +67 -0
- package/src/converter/index.js +17 -0
- package/src/index.js +2 -0
- package/src/parser/get-component-type.js +17 -0
- package/src/parser/index.js +30 -0
- package/src/parser/jsx2js.js +23 -0
- package/src/parser/parser-markdown.js +18 -0
- package/src/parser/smart-join.js +18 -0
- package/src/test.js +21 -0
- package/src/vite/index.js +16 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "preview",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"vite": "^5.4.8"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"ziko": "^0.0.16"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { p,App,Flex } from "ziko"
|
|
2
|
+
|
|
3
|
+
const {QueryParams} = __Ziko__
|
|
4
|
+
export default ()=>{
|
|
5
|
+
return App({
|
|
6
|
+
head : {
|
|
7
|
+
title : "ziko",
|
|
8
|
+
},
|
|
9
|
+
wrapper : ()=>Flex(p("Hello world").style({
|
|
10
|
+
color : QueryParams.color ?? "black"
|
|
11
|
+
})).size("100vw","100vh").vertical(0,0)
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
document.body.style.overflow = "hidden"
|
|
15
|
+
// export default ()=>{
|
|
16
|
+
// return p("Hello from zikojs File based routing ").style({
|
|
17
|
+
// color:"red",
|
|
18
|
+
// fontFamily : "Gloria Hallelujah"
|
|
19
|
+
// })
|
|
20
|
+
// }
|
package/preview/test.mdz
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
modules :
|
|
3
|
+
- import InteractiveBlock from "./InteractiveBlock.js"
|
|
4
|
+
title : MDZ
|
|
5
|
+
background : tomato
|
|
6
|
+
---
|
|
7
|
+
**MDZ** (Markdown for ***zikojs***) is a format that allows you to append Zikojs Elements directly within Markdown.
|
|
8
|
+
|
|
9
|
+
It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
|
|
10
|
+
|
|
11
|
+
Here’s an example of an interactive block rendered within this MDZ file:
|
|
12
|
+
|
|
13
|
+
<InteractiveBlock data="Hello from MDZ" color="cyan"/>
|
|
14
|
+
|
|
15
|
+
### Features of MDZ:
|
|
16
|
+
1- **Simple Integration :** Write Markdown as usual, and inject ZikoJS elements wherever needed.
|
|
17
|
+
2- **Frontmatter Support :** In this example, the title of the document is set dynamically through the frontmatter.
|
|
18
|
+
|
|
19
|
+
3- **Extensible :** Create custom components like InteractiveBlock and use them in any Markdown file.
|
|
20
|
+
|
|
21
|
+
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Str } from "ziko";
|
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
|
|
5
|
+
import terser from "@rollup/plugin-terser";
|
|
6
|
+
|
|
7
|
+
const Addon_name = "mdz";
|
|
8
|
+
const Author = "";
|
|
9
|
+
|
|
10
|
+
const banner = `
|
|
11
|
+
/*
|
|
12
|
+
Project: ${Addon_name}
|
|
13
|
+
Author: ${Author}
|
|
14
|
+
Date : ${new Date()}
|
|
15
|
+
*/
|
|
16
|
+
`;
|
|
17
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
18
|
+
|
|
19
|
+
const output = [
|
|
20
|
+
{
|
|
21
|
+
file: `dist/${Addon_name}.mjs`,
|
|
22
|
+
format: "es",
|
|
23
|
+
banner,
|
|
24
|
+
exports: "named",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
file: `dist/${Addon_name}.js`,
|
|
28
|
+
format: "umd",
|
|
29
|
+
name: Str.hyphen2pascalcase(Addon_name),
|
|
30
|
+
banner,
|
|
31
|
+
exports: "named",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
isProduction &&
|
|
35
|
+
output.push(
|
|
36
|
+
{
|
|
37
|
+
file: `dist/${Addon_name}.min.mjs`,
|
|
38
|
+
format: "es",
|
|
39
|
+
banner,
|
|
40
|
+
exports: "named",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
file: `dist/${Addon_name}.min.js`,
|
|
44
|
+
format: "umd",
|
|
45
|
+
name: Str.hyphen2pascalcase(Addon_name),
|
|
46
|
+
banner,
|
|
47
|
+
exports: "named",
|
|
48
|
+
plugins: [
|
|
49
|
+
terser({
|
|
50
|
+
output: {
|
|
51
|
+
comments: (node, { type, value }) =>
|
|
52
|
+
type === "comment2" && value.includes("Author"),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
input: "src/index.js",
|
|
61
|
+
output,
|
|
62
|
+
external: ["ziko"],
|
|
63
|
+
plugins: [
|
|
64
|
+
resolve(),
|
|
65
|
+
commonjs(),
|
|
66
|
+
],
|
|
67
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseMDZ } from "../parser/index.js"
|
|
2
|
+
const getZikoScript=(MDZ)=>{
|
|
3
|
+
let {modules,attributes,components}=parseMDZ(MDZ)
|
|
4
|
+
return `
|
|
5
|
+
import {Flex, HTMLWrapper} from "ziko";
|
|
6
|
+
${modules?.join(";\n")};
|
|
7
|
+
|
|
8
|
+
export const attributes = ${JSON.stringify(attributes)}
|
|
9
|
+
|
|
10
|
+
export default ()=> Flex(
|
|
11
|
+
${components.join(",\n ")}
|
|
12
|
+
).vertical(0, "space-around")
|
|
13
|
+
`
|
|
14
|
+
}
|
|
15
|
+
export{
|
|
16
|
+
getZikoScript
|
|
17
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function getComponentType(component) {
|
|
2
|
+
const trimmedComponent = component.trim();
|
|
3
|
+
const tagRegex = /^<([a-zA-Z][a-z0-9]*)/;
|
|
4
|
+
const match = trimmedComponent.match(tagRegex);
|
|
5
|
+
if (match) {
|
|
6
|
+
const tagName = match[1];
|
|
7
|
+
if (tagName[0] === tagName[0].toUpperCase()) {
|
|
8
|
+
return "jsx";
|
|
9
|
+
} else {
|
|
10
|
+
return "html";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return "unknown";
|
|
14
|
+
}
|
|
15
|
+
export{
|
|
16
|
+
getComponentType
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { smartJoin } from './smart-join.js';
|
|
2
|
+
import { jsx2js } from './jsx2js.js';
|
|
3
|
+
import { getComponentType } from './get-component-type.js';
|
|
4
|
+
import { parseMarkdown } from './parser-markdown.js';
|
|
5
|
+
function parseMDZ(markdown) {
|
|
6
|
+
const { body, attributes } = parseMarkdown(markdown.trim(""));
|
|
7
|
+
const {modules, ...props} = attributes
|
|
8
|
+
let JSXIndexesBefore = [], JSXIndexesAfter = [];
|
|
9
|
+
const Output = body.split("\n").filter((n) => n !== "");
|
|
10
|
+
Output.filter((n, i) => {
|
|
11
|
+
if (getComponentType(n) === "jsx") JSXIndexesBefore.push(i);
|
|
12
|
+
});
|
|
13
|
+
const JoinedTags = smartJoin(Output, JSXIndexesBefore);
|
|
14
|
+
JoinedTags.filter((n, i) => {
|
|
15
|
+
if (getComponentType(n) === "jsx") JSXIndexesAfter.push(i);
|
|
16
|
+
});
|
|
17
|
+
let components = [];
|
|
18
|
+
JoinedTags.forEach((n, i) => {
|
|
19
|
+
if (JSXIndexesAfter.includes(i)) components.push(jsx2js(n));
|
|
20
|
+
else components.push(`HTMLWrapper("${n}")`);
|
|
21
|
+
});
|
|
22
|
+
return{
|
|
23
|
+
components,
|
|
24
|
+
modules,
|
|
25
|
+
attributes : props
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export{
|
|
29
|
+
parseMDZ
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function jsx2js(component) {
|
|
2
|
+
const regex = /<(\w+)([^>]*)\/?>/;
|
|
3
|
+
const match = component.match(regex);
|
|
4
|
+
if (!match) {
|
|
5
|
+
throw new Error("Invalid component format");
|
|
6
|
+
}
|
|
7
|
+
const componentName = match[1];
|
|
8
|
+
const attributesString = match[2];
|
|
9
|
+
const attributes = {};
|
|
10
|
+
const attrRegex = /(\w+)="([^"]*)"/g;
|
|
11
|
+
let attrMatch;
|
|
12
|
+
while ((attrMatch = attrRegex.exec(attributesString)) !== null) {
|
|
13
|
+
attributes[attrMatch[1]] = attrMatch[2];
|
|
14
|
+
}
|
|
15
|
+
const attributesArray = Object.entries(attributes).map(([key, value]) => {
|
|
16
|
+
return `${key}:${JSON.stringify(value)}`;
|
|
17
|
+
});
|
|
18
|
+
const attributesStringFormatted = attributesArray.join(',');
|
|
19
|
+
return `${componentName}({${attributesStringFormatted}})`;
|
|
20
|
+
}
|
|
21
|
+
export{
|
|
22
|
+
jsx2js
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { marked } from 'marked';
|
|
2
|
+
import fm from 'front-matter';
|
|
3
|
+
|
|
4
|
+
function parseMarkdown(markdown) {
|
|
5
|
+
let FMProps = {};
|
|
6
|
+
function preprocess(markdown) {
|
|
7
|
+
const { attributes, body } = fm(markdown);
|
|
8
|
+
FMProps = { ...attributes };
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
marked.use({ hooks: { preprocess } });
|
|
12
|
+
const body = marked.parse(markdown);
|
|
13
|
+
return { body, attributes: FMProps };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export{
|
|
17
|
+
parseMarkdown,
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function smartJoin(strings = [], indexes = []) {
|
|
2
|
+
const result = [];
|
|
3
|
+
let lastIndex = 0;
|
|
4
|
+
indexes.forEach(index => {
|
|
5
|
+
if (index > lastIndex) {
|
|
6
|
+
result.push(strings.slice(lastIndex, index).join(''));
|
|
7
|
+
}
|
|
8
|
+
result.push(strings[index]);
|
|
9
|
+
lastIndex = index + 1;
|
|
10
|
+
});
|
|
11
|
+
if (lastIndex < strings.length) {
|
|
12
|
+
result.push(...strings.slice(lastIndex));
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
smartJoin
|
|
18
|
+
}
|
package/src/test.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getZikoScript } from "./converter/index.js";
|
|
2
|
+
const markdownContent = `
|
|
3
|
+
---
|
|
4
|
+
modules:
|
|
5
|
+
- import Component from "./Component"
|
|
6
|
+
- import OtherComponent from "./OtherComponent"
|
|
7
|
+
- import OtherComonenetWithProps from "./OtherComonenetWithProps"
|
|
8
|
+
title: MDZ
|
|
9
|
+
---
|
|
10
|
+
Para
|
|
11
|
+
[Link](#hi)
|
|
12
|
+
|
|
13
|
+
<Component />
|
|
14
|
+
|
|
15
|
+
line2
|
|
16
|
+
|
|
17
|
+
<OtherComponent />
|
|
18
|
+
<OtherComonenetWithProps data="hello" />
|
|
19
|
+
`;
|
|
20
|
+
const script = getZikoScript(markdownContent);
|
|
21
|
+
console.log(script)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getZikoScript } from "../converter/index.js";
|
|
2
|
+
export function MDZ(){
|
|
3
|
+
return {
|
|
4
|
+
name: 'MDZ',
|
|
5
|
+
transform(src, id) {
|
|
6
|
+
if (id.endsWith('.mdz')) {
|
|
7
|
+
console.log(src)
|
|
8
|
+
return {
|
|
9
|
+
code: getZikoScript(src),
|
|
10
|
+
map: null,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|