mdzjs 0.0.7 → 0.0.9
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
> This project is part of the [ZikoJS](https://github.com/zakarialaoui10/ziko.js) ecosystem.
|
|
3
3
|
|
|
4
4
|
# MDZjs
|
|
5
|
-
A Markdown preprocessor for Zikojs.
|
|
5
|
+
A Markdown preprocessor for Zikojs.
|
|
6
6
|
It combines the simplicity of Markdown syntax with the power and flexibility of ***Javascript***
|
|
7
7
|
|
|
8
8
|
## Install
|
|
@@ -25,7 +25,7 @@ export default defineConfig({
|
|
|
25
25
|
|
|
26
26
|
*Article.mdz :*
|
|
27
27
|
|
|
28
|
-
```
|
|
28
|
+
```jsx
|
|
29
29
|
---
|
|
30
30
|
title : MDZ
|
|
31
31
|
name : world
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdzjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"markdown",
|
|
23
23
|
"remark",
|
|
24
24
|
"mdx",
|
|
25
|
-
"preprocessor"
|
|
25
|
+
"preprocessor",
|
|
26
|
+
"astro-integrations"
|
|
26
27
|
],
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"dependencies": {
|
package/src/transpiler/index.js
CHANGED
package/src/transpiler/parser.js
CHANGED
|
@@ -4,11 +4,11 @@ import remarkFrontmatter from 'remark-frontmatter';
|
|
|
4
4
|
import remarkGFM from "remark-gfm";
|
|
5
5
|
import remarkMdx from "remark-mdx"
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const parseMarkdown = (markdown) => unified()
|
|
8
8
|
.use(remarkParse)
|
|
9
9
|
.use(remarkGFM)
|
|
10
10
|
.use(remarkFrontmatter, ['yaml'])
|
|
11
11
|
.use(remarkMdx)
|
|
12
12
|
.parse(markdown)
|
|
13
13
|
|
|
14
|
-
export{
|
|
14
|
+
export{parseMarkdown}
|
|
@@ -62,7 +62,9 @@ const processMDZAST = (markdownAST) => {
|
|
|
62
62
|
const childNodes = node.children.map(transformNode).join(', ');
|
|
63
63
|
return hyperscript("li", "{}", childNodes);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
case 'inlineCode' : {
|
|
66
|
+
return hyperscript("code", "{}", `"${node.value}"`)
|
|
67
|
+
}
|
|
66
68
|
case 'code': {
|
|
67
69
|
hasCode = true;
|
|
68
70
|
// const language = node.lang ? `{ 'data-lang': '${node.lang}' }` : '';
|
|
@@ -74,7 +76,7 @@ const processMDZAST = (markdownAST) => {
|
|
|
74
76
|
// language,
|
|
75
77
|
// JSON.stringify(node.value)
|
|
76
78
|
// ));
|
|
77
|
-
return `HTMLWrapper('<pre>${formatedCode}</pre>')`
|
|
79
|
+
return `HTMLWrapper('<pre><code>${formatedCode}</code></pre>')`
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
case 'blockquote': {
|
|
@@ -114,12 +116,16 @@ const processMDZAST = (markdownAST) => {
|
|
|
114
116
|
attrs
|
|
115
117
|
}
|
|
116
118
|
}
|
|
119
|
+
case 'mdxJsxTextElement': {
|
|
120
|
+
const {name, attributes, children} = node;
|
|
121
|
+
const childNodes = children.map(transformNode).join(', ');
|
|
122
|
+
const hasChildren = childNodes.length > 0;
|
|
123
|
+
return `h("${name}", ${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
124
|
+
};
|
|
117
125
|
case 'mdxJsxFlowElement':{
|
|
118
126
|
const {name, attributes, children} = node;
|
|
119
127
|
const childNodes = children.map(transformNode).join(', ');
|
|
120
128
|
const hasChildren = childNodes.length > 0;
|
|
121
|
-
// console.log({name})
|
|
122
|
-
// console.log(componentType(name))
|
|
123
129
|
switch(componentType(name)){
|
|
124
130
|
case "jsx" : {
|
|
125
131
|
return `${name}(${processAttribute(attributes)}${hasChildren ?`, ${childNodes}`:""})`;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseMarkdown } from "./parser.js";
|
|
2
2
|
import { processMDZAST } from "./process.js";
|
|
3
3
|
import { stringifyProps } from "../utils/parse-yml.js";
|
|
4
4
|
|
|
5
5
|
const transpileMDZ=(Markdown, useVanJs = false, CodeStyle = "1c-light")=>{
|
|
6
|
-
const ast =
|
|
6
|
+
const ast = parseMarkdown(Markdown);
|
|
7
7
|
const {attrs, props, esm, statements, hasCode}= processMDZAST(ast)
|
|
8
8
|
const body = [
|
|
9
9
|
'import {h, HTMLWrapper, Flex} from "ziko"',
|
package/src/utils/parse-yml.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
2
|
|
|
3
3
|
const parseYml = yml => {
|
|
4
|
-
const {__props__, ...__attrs__} = parse(yml) ;
|
|
4
|
+
const {__props__, ...__attrs__} = yml ? parse(yml) : {__props__ : {}} ;
|
|
5
5
|
const HasAttributs = Object.keys(__attrs__).length > 0
|
|
6
6
|
return {
|
|
7
7
|
props : __props__,
|