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.
Files changed (52) hide show
  1. package/README.md +70 -56
  2. package/__src__/index.js +2 -0
  3. package/__src__/test.js +21 -0
  4. package/{v2/test.js → __v2__/_test.js} +1 -1
  5. package/__v2__/clean.js +67 -0
  6. package/__v2__/hast.js +70 -0
  7. package/__v2__/html2js.js +59 -0
  8. package/__v2__/pre-parse/clean-md.js +93 -0
  9. package/__v2__/test.js +19 -0
  10. package/{v2 → __v2__}/transpiler/index.js +17 -12
  11. package/__v2__/utils/is-object.js +11 -0
  12. package/__v2__/utils/split-between.js +47 -0
  13. package/package.json +12 -6
  14. package/preview/Components/Dom.js +6 -0
  15. package/preview/index.html +10 -1
  16. package/preview/main.js +8 -17
  17. package/preview/package-lock.json +712 -8
  18. package/preview/package.json +6 -2
  19. package/preview/test.mdz +27 -49
  20. package/preview/vite.config.js +1 -1
  21. package/src/bundlers/vite.js +15 -0
  22. package/src/example.md +3 -0
  23. package/src/index.js +1 -2
  24. package/src/test.js +45 -17
  25. package/src/transpiler/index.js +3 -0
  26. package/src/transpiler/parser.js +14 -0
  27. package/src/transpiler/process.js +172 -0
  28. package/src/transpiler/transpile.js +22 -0
  29. package/src/utils/component-type.js +5 -0
  30. package/src/utils/hyperscript.js +4 -0
  31. package/src/utils/index.js +4 -0
  32. package/src/utils/parse-yml.js +19 -0
  33. package/src/utils/process-attributes.js +13 -0
  34. package/v2/pre-parse/clean-md.js +0 -93
  35. /package/{src → __src__}/converter/index.js +0 -0
  36. /package/{src → __src__}/parser/get-component-type.js +0 -0
  37. /package/{src → __src__}/parser/index.js +0 -0
  38. /package/{src → __src__}/parser/jsx2js.js +0 -0
  39. /package/{src → __src__}/parser/parser-markdown.js +0 -0
  40. /package/{src → __src__}/parser/smart-join.js +0 -0
  41. /package/{src → __src__}/vite/index.js +0 -0
  42. /package/{v2 → __v2__}/index.js +0 -0
  43. /package/{v2 → __v2__}/readme.md +0 -0
  44. /package/{v2 → __v2__}/transformers/vite/index.js +0 -0
  45. /package/{v2 → __v2__}/transpiler/get-component-type.js +0 -0
  46. /package/{v2 → __v2__}/transpiler/import-plugin.js +0 -0
  47. /package/{v2 → __v2__}/transpiler/jsx2js.js +0 -0
  48. /package/{v2 → __v2__}/transpiler/process-text.js +0 -0
  49. /package/preview/{Hi.js → Components/Hi.js} +0 -0
  50. /package/preview/{InteractiveBlock.js → Components/InteractiveBlock.js} +0 -0
  51. /package/preview/{Scene.js → Components/Scene.js} +0 -0
  52. /package/preview/{__main2.js → __main2.js.txt} +0 -0
package/README.md CHANGED
@@ -1,16 +1,19 @@
1
- # Markdown for [Zikojs](https://github.com/zakarialaoui10/ziko.js)
1
+ > [!NOTE]
2
+ > This project is part of the [ZikoJS](https://github.com/zakarialaoui10/ziko.js) ecosystem.
3
+
4
+ # MDZjs
5
+ A Markdown preprocessor for Zikojs. Markdown in Zikojs.
6
+ It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
2
7
 
3
8
  ## Install
4
9
  ```bash
5
10
  npm i mdzjs
6
11
  ```
7
-
8
- ## Usage
9
-
10
- ### Config
12
+
13
+ ## Config
11
14
  ```js
12
15
  import {defineConfig} from "vite"
13
- import {MDZ} from "mdzjs"
16
+ import MDZ from "mdzjs/vite"
14
17
  export default defineConfig({
15
18
  plugins : [
16
19
  MDZ()
@@ -18,67 +21,78 @@ export default defineConfig({
18
21
  })
19
22
  ```
20
23
 
21
- ### Example
24
+ ## Usage
25
+
26
+ *Article.mdz :*
22
27
 
23
- ```md
28
+ ```js
24
29
  ---
25
- title : MDZ
26
- background : tomato
30
+ title : MDZ
31
+ name : world
32
+ __props__ :
33
+ background : tomato
34
+ data : []
27
35
  ---
36
+ import data from "./data.js";
37
+ import InteractiveComponent from "./InteractiveComponent.js";
28
38
 
29
- import InteractiveBlock from "./InteractiveBlock.js";
39
+ # Hello {name}
30
40
 
31
- **MDZ** (Markdown for ***zikojs***) is a format that allows you to append Zikojs Elements directly within Markdown.
41
+ <InteractiveComponent data={data} background={tomato}/>
32
42
 
33
- It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
43
+ ```
34
44
 
35
- Here’s an example of an interactive block rendered within this MDZ file:
45
+ ```js
46
+ // main.js
47
+ import Article,{title} from "./Article.mdz"
48
+ ```
36
49
 
37
- <InteractiveBlock data="Hello from MDZ" color="darkblue"/>
50
+ ## Features
51
+ - **Simple Integration :** Write Markdown as usual, and inject Zikojs elements wherever needed.
52
+ - **Extensible :** Create custom interactive components using Zikojs and use them in any Markdown file.
53
+ - **Reusable :** MDZ exports a default functional component, allowing you to call it multiple times with different data, enabling dynamic and versatile use.
54
+ - **Frontmatter Support :** Use `YAML` syntax in to include metadata like titles, descriptions, or configurations in your Markdown files, and define props to pass data dynamically to Zikojs components.
38
55
 
39
- ### Features of MDZ:
40
- 1- **Simple Integration :** Write Markdown as usual, and inject ZikoJS elements wherever needed.
41
- 2- **Frontmatter Support :** In this example, the title of the document is set dynamically through the frontmatter.
56
+ - **Markdown :** Use standard Markdown syntax for writing content.
57
+ - **JSX Syntax :** Write components in JSX within Markdown, enabling easy integration of Zikojs elements with JavaScript and HTML..
58
+ - **Props :** Pass data to components through props, enabling dynamic rendering and customization of content within your Markdown files.
59
+ - **ESM :** Supports ECMAScript Modules (ESM), allowing you to import and export modules
60
+ - **Expressions :** MDZjs lets you use JS expressions inside curly braces, like Hello {name}.
61
+ These expressions can be full JS programs, as long as they evaluate to something renderable. For example, you can use an IIFE like this:
62
+ ```js
63
+ Hello {(()=>{
64
+ const names = ["world", "everyone"];
65
+ const {length} = names
66
+ return names[Math.floor(Math.random()*length)]
67
+ })()}
68
+ ```
69
+ - **Internal scripts :** Include JS logic that runs alongside MDZjs components but isn't rendered in the output.
70
+ They can initialize variables or perform side effects...
42
71
 
43
- 3- **Extensible :** Create custom components like InteractiveBlock and use them in any Markdown file.
72
+ ```html
73
+ <script>
74
+ console.log("Hello from MDZjs")
75
+ let addons = [
76
+ "ziko-gl",
77
+ "ziko-lottie",
78
+ "ziko-chart"
79
+ ]
80
+ // The addons variable can be accessed and used in MDZjs expressions
81
+ </script>
44
82
  ```
83
+ - **Interleaving :** You can use inline markdown elements inside HTML or Zikojs Components
45
84
 
46
- ```js
47
- // InteractiveBlock.js
48
- import {Flex, input, text} from "ziko"
49
- export default ({data, color})=>{
50
- let txt = text(data).style({color})
51
- let inp = input(data).style({
52
- padding : "5px",
53
- background : "transparent",
54
- outline :"none",
55
- boxShadow :"1px 1px 1px white",
56
- fontSize : "inherit"
57
- })
58
- inp.onInput(e=>txt.setValue(e.value))
59
- return Flex(
60
- inp,
61
- txt
62
- ).vertical(0, "space-around").size("60%").style({
63
- border : "2px darkblue solid",
64
- padding : "10px",
65
- minHeight : "100px",
66
- margin : "auto"
67
- })
68
- }
85
+ ```html
86
+ <Header background={background}>
87
+ ***Hello {name}***
88
+ </Header>
69
89
  ```
90
+ # ⭐️ Show your support
70
91
 
71
- ```js
72
- // main.js
73
- import { useTitle } from "ziko"
74
- import UI,{title, background} from "./test.mdz"
75
- title && useTitle(title)
76
- UI().style({
77
- border : "2px darkblue solid",
78
- width : "70%",
79
- margin : "auto",
80
- padding : "10px",
81
- fontFamily : "Cheeronsta",
82
- background : background ?? "orange"
83
- }).vertical(-1, "space-around")
84
- ```
92
+ If you appreciate the project, kindly demonstrate your support by giving it a star!<br>
93
+
94
+ [![Star](https://img.shields.io/github/stars/zakarialaoui10/mdzjs?style=social)](https://github.com/zakarialaoui10/mdzjs)
95
+ <!--## Financial support-->
96
+ # License
97
+ This projet is licensed under the terms of MIT License
98
+ <img src="https://img.shields.io/github/license/zakarialaoui10/mdzjs?color=rgb%2820%2C21%2C169%29" width="100" align="right">
@@ -0,0 +1,2 @@
1
+ export {parseMDZ} from "./parser/index.js"
2
+ export {MDZ} from "./vite/index.js"
@@ -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)
@@ -61,7 +61,7 @@ Test {sayHi()}
61
61
  `;
62
62
 
63
63
  let res = transpileMDZ(Markdown)
64
- // console.log(res)
64
+ console.log(res)
65
65
 
66
66
  // const md2 = "```js \n console.log(1) \n ```"
67
67
  // const md2 = `
@@ -0,0 +1,67 @@
1
+ export function cleanMD(str, openSign, closeSign) {
2
+ const result = [];
3
+ let currentExpr = '';
4
+ let currentText = '';
5
+ let braceCount = 0;
6
+ let isEscaped = false;
7
+
8
+ for (let i = 0; i < str.length; i++) {
9
+ const char = str[i];
10
+
11
+ if (char === '\\' && !isEscaped) {
12
+ // Set escape flag and skip adding the backslash for now
13
+ isEscaped = true;
14
+ continue;
15
+ }
16
+
17
+ if (isEscaped) {
18
+ // If escaped, append the literal character and reset escape flag
19
+ currentText += char;
20
+ isEscaped = false;
21
+ continue;
22
+ }
23
+
24
+ if (char === '{') {
25
+ if (braceCount === 0 && currentText) {
26
+ result.push(currentText.trim());
27
+ currentText = '';
28
+ }
29
+ braceCount++;
30
+ currentExpr += char;
31
+ } else if (char === '}') {
32
+ braceCount--;
33
+ currentExpr += char;
34
+ if (braceCount === 0) {
35
+ result.push(cleanExpression(currentExpr, openSign, closeSign));
36
+ currentExpr = '';
37
+ }
38
+ } else {
39
+ if (braceCount === 0) {
40
+ currentText += char;
41
+ } else {
42
+ currentExpr += char;
43
+ }
44
+ }
45
+ }
46
+
47
+ if (currentText) {
48
+ result.push(currentText.trim());
49
+ }
50
+
51
+ return result.join('');
52
+ }
53
+
54
+ function cleanExpression(block, openSign = "", closeSign = "") {
55
+ const content = block.slice(1, -1);
56
+ const cleanedContent = content
57
+ .split('\n')
58
+ .map(line => line.trim())
59
+ .filter(line => line)
60
+ .join('\n');
61
+ return `${openSign}{${cleanedContent}}${closeSign}`;
62
+ // return `${openSign}{\n${cleanedContent}\n}${closeSign}`;
63
+ }
64
+
65
+ // const input = "Normal text {expression here} and \\{escaped brace\\}";
66
+ // console.log(cleanMD(input, "[", "]"));
67
+
package/__v2__/hast.js ADDED
@@ -0,0 +1,70 @@
1
+ import { parseDocument } from 'htmlparser2';
2
+ import { cleanMD } from './clean.js';
3
+ import { splitBetween } from './utils/split-between.js';
4
+ import { isObject } from './utils/is-object.js';
5
+ const OPEN_SIGN = "\"EXP_START"
6
+ const CLOSE_SIGN = "EXP_END\""
7
+ function transformNode(node) {
8
+ switch (node.type) {
9
+ case 'text': {
10
+ const text = node.data;
11
+ const cleanedText = cleanMD(text, OPEN_SIGN, CLOSE_SIGN)
12
+ const args = splitBetween(cleanedText, OPEN_SIGN, CLOSE_SIGN).map(({type, value})=>{
13
+ if(type === "string") return `"${value}"`
14
+ return value.slice(1,-1)
15
+ })
16
+ return args.length!==0 ? args : null;
17
+ }
18
+ case 'tag': {
19
+ const tagName = node.rawTagName || node.name;
20
+ const isJSXComponent = /^[A-Z]/.test(tagName);
21
+
22
+ const attributes = node.attribs
23
+ ? Object.entries(node.attribs)
24
+ .map(([key, value]) => `${key}: ${
25
+ isObject(value)
26
+ ?value
27
+ :(value.at(0)==="{")?value.slice(1,-1):'"'+value+'"'
28
+ }`)
29
+ .join(', ')
30
+ : '';
31
+ const childNodes = node.children
32
+ .map(transformNode)
33
+ .filter(Boolean)
34
+ .join(', ');
35
+
36
+ if (isJSXComponent) {
37
+ if(node.children.length > 0) return `${tagName}({${attributes}}, ${childNodes})`
38
+ return `${tagName}({${attributes}})`;
39
+ }
40
+ else {
41
+ if(node.children.length > 0) return `tag('${tagName}', {${attributes}}, ${childNodes})`;
42
+ return `tag('${tagName}', {${attributes}})`
43
+ }
44
+ }
45
+ default:
46
+ return '';
47
+ }
48
+ }
49
+
50
+
51
+
52
+ const html = `
53
+ <p ref="ll" id={m} ob={a:1}>Hi {exp} \\{</p>
54
+ <p ref="ll">{exp} \\{</p>
55
+ <p ref="ll" id={m} ob={a:1}>Hi {exp} \\{</p>
56
+ <p ref="ll">{exp} \\{</p>
57
+ <ZikoComp test=1>
58
+ <p> Hi </p>
59
+ </ZikoComp>
60
+ <Void />
61
+ `.trim();
62
+
63
+ const ast = parseDocument(html, { lowerCaseTags: false });
64
+
65
+ const transformedCode = ast.children
66
+ .map(transformNode)
67
+ .filter(Boolean)
68
+ // .join(', ');
69
+
70
+ console.log(transformedCode);
@@ -0,0 +1,59 @@
1
+ import { parseDocument } from 'htmlparser2';
2
+
3
+ function transformNode(node) {
4
+ switch (node.type) {
5
+ case 'text': {
6
+ const text = node.data;
7
+ return processText(text);
8
+ }
9
+ case 'tag': {
10
+ const tagName = node.rawTagName || node.name;
11
+ const isJSXComponent = /^[A-Z]/.test(tagName);
12
+
13
+ const attributes = node.attribs
14
+ ? Object.entries(node.attribs)
15
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
16
+ .join(', ')
17
+ : '';
18
+
19
+ const childNodes = node.children
20
+ .map(transformNode)
21
+ .filter(Boolean) // Remove empty strings from children
22
+ .join(', ');
23
+
24
+ if (isJSXComponent) {
25
+ return `${tagName}({${attributes}}, ${childNodes})`;
26
+ } else {
27
+ return `tag('${tagName}', {${attributes}}, ${childNodes})`;
28
+ }
29
+ }
30
+ default:
31
+ return '';
32
+ }
33
+ }
34
+
35
+ function processText(text) {
36
+ return JSON.stringify(text.trim());
37
+ }
38
+
39
+ const html = `<p>
40
+ Hello world
41
+ <span>
42
+ hi
43
+ </span>
44
+ <JsxComponent data={zikojs} />
45
+
46
+ <JsxComponent>
47
+ <Js />
48
+ <Js />
49
+ </JsxComonent>
50
+ </p>`;
51
+
52
+ const ast = parseDocument(html, { lowerCaseTags: false }); // Disable automatic lowercase conversion
53
+
54
+ const transformedCode = ast.children
55
+ .map(transformNode)
56
+ .filter(Boolean) // Remove empty strings from top-level nodes
57
+ .join(', ');
58
+
59
+ console.log(transformedCode);
@@ -0,0 +1,93 @@
1
+ function cleanMD(str, openSign, closeSign) {
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, openSign, closeSign));
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, openSign="", closeSign ="") {
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 `${openSign}{\n${cleanedContent}\n}${closeSign}`;
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
+ }
package/__v2__/test.js ADDED
@@ -0,0 +1,19 @@
1
+ import { transpileMDZ } from "./transpiler/index.js";
2
+
3
+ const Markdown = `
4
+ ---
5
+ title : hi
6
+ __Props__ :
7
+ m : 1
8
+
9
+ ---
10
+
11
+ # Hi
12
+
13
+ {
14
+ 1+1
15
+ }
16
+ <p> Hi </p>
17
+ `
18
+ let res = transpileMDZ(Markdown)
19
+ console.log(res)
@@ -6,8 +6,9 @@ import { processText } from "./process-text.js"
6
6
  import { parse as parseYaml } from 'yaml';
7
7
  import remarkFrontmatter from 'remark-frontmatter';
8
8
  import remarkGFM from "remark-gfm"
9
+ import { cleanMD } from '../pre-parse/clean-md.js';
9
10
 
10
- const parseMDZ = (markdown) => unified().use(remarkParse).use(remarkGFM).use(remarkFrontmatter).parse(markdown);
11
+ const parseMDZ = (markdown) => unified().use(remarkParse).use(remarkGFM).use(remarkFrontmatter, ['yaml']).parse(markdown);
11
12
 
12
13
  const processMDZ = (markdown) => {
13
14
  const importRegex = /^\s*import\s+[^;]+;$/gm
@@ -27,7 +28,6 @@ const transformMDZ = (markdownAST) => {
27
28
  switch(node.type){
28
29
  case 'text' : {
29
30
  const text = node.value;
30
- // console.log({pr : processText(text)})
31
31
  return processText(text)
32
32
  }
33
33
  case 'paragraph' : {
@@ -78,7 +78,7 @@ const transformMDZ = (markdownAST) => {
78
78
  return `h('blockquote', {}, ${childNodes})`;
79
79
  }
80
80
  case 'thematicBreak': {
81
- return `h('hr', {}, '')`;
81
+ return `h('hr', {})`;
82
82
  }
83
83
  case 'table': {
84
84
  const headerRows = node.children[0].children.map(transformNode).join(', ');
@@ -101,8 +101,11 @@ const transformMDZ = (markdownAST) => {
101
101
  switch (type) {
102
102
  case 'jsx':
103
103
  return ` ${jsx2js(component.replaceAll("\n",""))}`;
104
- case 'html':
105
- return ` HTMLWrapper("${component}")`;
104
+ case 'html':{
105
+ return ` HTMLWrapper("${component}")`
106
+
107
+ // To be replaced by HTML Parser
108
+ }
106
109
  case 'script' : return {
107
110
  type : "script",
108
111
  value : `${component.replace(/<script[^>]*>/g, '').replace(/<\/script>/g, '').trim()}`
@@ -127,7 +130,7 @@ const transformMDZ = (markdownAST) => {
127
130
  }
128
131
  });
129
132
  return {
130
- fm : parseYaml(fm[0].value),
133
+ fm : fm[0] ? parseYaml(fm[0].value) : {},
131
134
  body : mdBody.map(transformNode).map(n=>n instanceof Object? n.value: `__items__.push(${n})`).join("\n")
132
135
  }
133
136
  };
@@ -142,21 +145,23 @@ const transpileMDZ= markdown =>{
142
145
  .map(([key, value]) => `${key} = ${JSON.stringify(value)}`)
143
146
  .join(', ')
144
147
  : '';
145
- let ui = `
146
- const __items__ = [];
148
+
149
+ console.log({defaultProps : fm})
150
+ let ui = `const __items__ = [];
147
151
  ${body}
148
152
  // console.log({__items__})
149
153
  const UI = (${defaultProps ? `{${defaultProps}}={}`: ""}) => Flex(...__items__).vertical(0, 0);
150
154
  export default UI
151
155
  `
152
- let attributs = `const {${Object.keys(Attr).join(",")}} = ${JSON.stringify(Attr,"",2)}`
153
- let exports = `export {${Object.keys(Attr).join(", ")}}`
156
+ const AttrFounded = Object.keys(Attr).length > 0
157
+ let attributs = AttrFounded ? `const {${Object.keys(Attr).join(",")}} = ${JSON.stringify(Attr,"",2)}` : null
158
+ let exports = AttrFounded ? `export {${Object.keys(Attr).join(", ")}}` : null
154
159
  const Output = [
155
160
  imports,
156
161
  attributs,
157
162
  ui,
158
- exports
159
- ].join('\n');
163
+ exports,
164
+ ].filter(Boolean).join('\n');
160
165
  return Output
161
166
 
162
167
  }
@@ -0,0 +1,11 @@
1
+ export function isObject(input) {
2
+ try {
3
+ const parsed = new Function(`return (${input})`)();
4
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
5
+ } catch {
6
+ return false;
7
+ }
8
+ }
9
+
10
+ // console.log(isObject("{a:1}")); // true
11
+ // console.log(isObject("{1+1}")) // false
@@ -0,0 +1,47 @@
1
+ export function splitBetween(input, startToken, endToken) {
2
+ const pattern = new RegExp(`${startToken}(.*?)${endToken}`, "g"); // Match the tokens and capture the content inside
3
+ const result = [];
4
+ let lastIndex = 0;
5
+
6
+ input.replace(pattern, (match, content, offset) => {
7
+ if (offset > lastIndex) {
8
+ result.push({
9
+ type: "string",
10
+ value: input.slice(lastIndex, offset),
11
+ });
12
+ }
13
+ result.push({
14
+ type: "expression",
15
+ value: content,
16
+ });
17
+ lastIndex = offset + match.length;
18
+ });
19
+
20
+ if (lastIndex < input.length) {
21
+ result.push({
22
+ type: "string",
23
+ value: input.slice(lastIndex),
24
+ });
25
+ }
26
+
27
+ return result;
28
+ }
29
+
30
+ // const input = "Text before {token content} text between {another token} end text";
31
+ // console.log(splitBetween(input, "{", "}"));
32
+
33
+
34
+ // export function splitBetween(input, startToken , endToken) {
35
+ // const pattern = new RegExp(`${startToken}|${endToken}`, "g")
36
+ // const arr=input.split(pattern);
37
+ // return arr
38
+ // }
39
+
40
+ // // const input = `
41
+ // // Hi "EXP_START{This is an expression}EXP_END" How are you , {}
42
+ // // `;
43
+
44
+ // // const startToken = "\"EXP_START";
45
+ // // const endToken = "EXP_END\"";
46
+ // // console.log(splitBetween(input, startToken, endToken));
47
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdzjs",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,23 +14,29 @@
14
14
  "import": "./src/index.js"
15
15
  },
16
16
  "./vite": {
17
- "import": "./src/vite/index.js"
17
+ "import": "./src/bundlers/vite.js"
18
18
  },
19
- "author": "",
19
+ "author": "zakaria elalaoui",
20
20
  "keywords": [
21
21
  "zikojs",
22
- "zikojs-addons"
22
+ "zikojs-addons",
23
+ "markdown",
24
+ "remark",
25
+ "mdx",
26
+ "preprocessor"
23
27
  ],
24
28
  "license": "MIT",
25
29
  "dependencies": {
26
- "front-matter": "^4.0.2",
30
+ "acorn": "^8.14.0",
31
+ "htmlparser2": "^9.1.0",
27
32
  "remark-frontmatter": "^5.0.0",
28
33
  "remark-gfm": "^4.0.0",
34
+ "remark-mdx": "^3.1.0",
29
35
  "remark-parse": "^11.0.0",
30
36
  "rollup": "^4.24.0",
31
37
  "unified": "^11.0.5",
32
38
  "yaml": "^2.6.1",
33
- "ziko": "^0.0.22"
39
+ "ziko": "^0.0.27"
34
40
  },
35
41
  "devDependencies": {
36
42
  "@rollup/plugin-commonjs": "^28.0.0",