van-mdx 0.0.0 → 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 CHANGED
@@ -4,6 +4,8 @@ A Markdown preprocessor for [Vanjs](https://vanjs.org/).
4
4
  It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
5
5
 
6
6
  ## Demos :
7
+ - ***Hello World*** :
8
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/zakarialaoui10/van-mdx/tree/main/examples/hello-world?file=src%2Fcontent%2FArticle.mdx)
7
9
 
8
10
  ## Install :
9
11
 
@@ -28,10 +30,10 @@ export default defineConfig({
28
30
  - ***Article.mdx :***
29
31
  ```jsx
30
32
  ---
31
- title : Van-Mdx Starter
32
- name : world
33
+ title : "Van-Mdx Starter"
34
+ name : "world"
33
35
  __props__ :
34
- background : tomato
36
+ background : "tomato"
35
37
  data : []
36
38
  ---
37
39
 
package/package.json CHANGED
@@ -1,27 +1,38 @@
1
1
  {
2
2
  "name": "van-mdx",
3
- "version": "0.0.0",
4
- "description": "Markdown for Vanjs",
3
+ "version": "0.0.2",
4
+ "description": "Markdown preprocessor for Vanjs",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
+ "keywords": [
8
+ "vanjs",
9
+ "astro-integration",
10
+ "mdx",
11
+ "markdown",
12
+ "preprocessor"
13
+ ],
7
14
  "scripts": {
8
15
  "test": "echo \"Error: no test specified\" && exit 1"
9
16
  },
10
17
  "exports": {
11
18
  ".": "./src/index.js",
12
- "./vite": "./src/bundlers/vite.js"
19
+ "./vite": "./src/bundlers/vite/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"
13
23
  },
14
24
  "author": "zakaria elalaoui",
15
25
  "license": "MIT",
16
26
  "dependencies": {
17
27
  "highlight.js": "^11.11.1",
18
- "mdzjs": "^0.0.8",
28
+ "mdzjs": "^0.0.10",
19
29
  "remark-frontmatter": "^5.0.0",
20
30
  "remark-gfm": "^4.0.1",
21
31
  "remark-mdx": "^3.1.0",
22
32
  "remark-parse": "^11.0.0",
23
33
  "unified": "^11.0.5",
24
34
  "vanjs-core": "^1.5.5",
25
- "ziko": "^0.0.27"
35
+ "ziko": "^0.0.29",
36
+ "ziko-server": "^0.0.7"
26
37
  }
27
38
  }
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,39 @@
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,4 +1,4 @@
1
- import { transpileMD } from "../transpiler/index.js";
1
+ import { transpileMD } from "../../transpiler/index.js";
2
2
  export default function VanMdx(){
3
3
  return {
4
4
  name: 'VanMdx',
@@ -57,13 +57,15 @@ const processMDAST = (markdownAST) => {
57
57
  const childNodes = node.children.map(transformNode).join(', ');
58
58
  return hyperscript("li", "{}", childNodes);
59
59
  };
60
-
60
+ case 'inlineCode' : {
61
+ return `van.tags.code("${node.value}")`
62
+ }
61
63
  case 'code': {
62
64
  hasCode = true;
63
65
  // const language = node.lang ? `{ 'data-lang': '${node.lang}' }` : '';
64
66
  const highlightedCode = hljs.highlightAuto(node.value, [node.lang || '']).value;
65
67
  const formatedCode = highlightedCode.replace(/(\r\n|\n|\r)/g, "<br>")
66
- return `HTMLWrapper('<pre>${formatedCode}</pre>').element`
68
+ return `HTMLWrapper('<pre><code>${formatedCode}</code></pre>').element`
67
69
  }
68
70
  case 'blockquote': {
69
71
  const childNodes = node.children.map(transformNode).join(', ');
@@ -78,10 +80,6 @@ const processMDAST = (markdownAST) => {
78
80
  const thead = hyperscript("thead", "{}", hyperscript("tr", "{}", headerRows));
79
81
  const tbody = hyperscript("tbody", "{}", bodyRows);
80
82
  return hyperscript("table", "{}", [thead, tbody].join(","))
81
- // console.log({thead, tbody})
82
- // const thead = `h('thead', {}, h('tr', {}, ${headerRows})`;
83
- // const tbody = `h('tbody', {}, ${bodyRows})`
84
- // return `h('table', {}, ${thead}), ${tbody}).style({border : "1px solid darkblue", borderCollapse: "collapse"}`;
85
83
  }
86
84
  case 'tableRow': {
87
85
  const cells = node.children.map(transformNode).join(', ');
@@ -113,6 +111,12 @@ const processMDAST = (markdownAST) => {
113
111
  const hasChildren = childNodes.length > 0;
114
112
  switch(componentType(name)){
115
113
  case "jsx" : {
114
+ console.log({
115
+ Component : name,
116
+ children,
117
+ })
118
+ const f = `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`
119
+ console.log({f})
116
120
  return `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
117
121
  }
118
122
  case "html" : {