vaderjs 1.2.6 → 1.2.7
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/package.json +1 -1
- package/vader.js +31 -16
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -6,7 +6,8 @@ let states = {};
|
|
|
6
6
|
* @description Allows you to convert markdown to html
|
|
7
7
|
*/
|
|
8
8
|
function markdown(content) {
|
|
9
|
-
const lines = content.split('\n');
|
|
9
|
+
const lines = content.split('\n').filter((line) => line !== '').map((line) => line.trim());
|
|
10
|
+
|
|
10
11
|
let result = '';
|
|
11
12
|
|
|
12
13
|
lines.forEach((line) => {
|
|
@@ -16,7 +17,8 @@ function markdown(content) {
|
|
|
16
17
|
|
|
17
18
|
let link = line.match(/\[(.*?)\]\((.*?)\)/g);
|
|
18
19
|
let ul = line.match(/^\-\s/);
|
|
19
|
-
let ol =
|
|
20
|
+
let ol = line.match(/^\d\.\s/);
|
|
21
|
+
|
|
20
22
|
let li = line.match(/^\s/);
|
|
21
23
|
let hr = line.match(/^\-\-\-\s/);
|
|
22
24
|
let blockquote = line.match(/^\>\s/);
|
|
@@ -25,6 +27,8 @@ function markdown(content) {
|
|
|
25
27
|
|
|
26
28
|
let codeBlock = line.match(/\`\`\`/g);
|
|
27
29
|
let codeBlockEnd = line.match(/\`\`\`/g);
|
|
30
|
+
let code = line.match(/\`(.*?)\`/g);
|
|
31
|
+
|
|
28
32
|
|
|
29
33
|
|
|
30
34
|
if (heading) {
|
|
@@ -55,15 +59,11 @@ function markdown(content) {
|
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
61
|
if (ul) {
|
|
58
|
-
line = line.replace(ul[0], `<li
|
|
59
|
-
style="list-style-type: disc;"
|
|
60
|
-
>`);
|
|
62
|
+
line = line.replace(ul[0], `<li style="list-style-type: disc;">`);
|
|
61
63
|
line += `</li>`;
|
|
62
64
|
}
|
|
63
65
|
if (ol) {
|
|
64
|
-
line = line.replace(ol[0], `<li
|
|
65
|
-
style="list-style-type: decimal;"
|
|
66
|
-
>`);
|
|
66
|
+
line = line.replace(ol[0], `<li style="list-style-type: decimal;">`);
|
|
67
67
|
line += `</li>`;
|
|
68
68
|
}
|
|
69
69
|
if (hr) {
|
|
@@ -83,15 +83,27 @@ function markdown(content) {
|
|
|
83
83
|
line = line.replace(i, `<img src="${src}" alt="${alt}"/>`).replace('!','')
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
if(
|
|
87
|
-
line = line.replace(
|
|
88
|
-
|
|
86
|
+
if (li) {
|
|
87
|
+
line = line.replace(li[0], `<li>`);
|
|
88
|
+
line += `</li>`;
|
|
89
|
+
}
|
|
90
|
+
if (codeBlock) {
|
|
91
|
+
line = line.replace(codeBlock[0], `<pre><code>`);
|
|
89
92
|
}
|
|
90
|
-
if(codeBlockEnd){
|
|
91
|
-
line = line.replace(codeBlockEnd[0], `</code>`);
|
|
92
|
-
// remove spaces
|
|
93
|
-
line = line.replace(/^\s+/g, '');
|
|
93
|
+
if (codeBlockEnd) {
|
|
94
|
+
line = line.replace(codeBlockEnd[0], `</code></pre>`);
|
|
94
95
|
}
|
|
96
|
+
|
|
97
|
+
if (code) {
|
|
98
|
+
code.forEach((c) => {
|
|
99
|
+
line = line.replace(c, `<code
|
|
100
|
+
style="background-color: #f5f5f5; padding: 5px; border-radius: 5px;
|
|
101
|
+
|
|
102
|
+
"
|
|
103
|
+
>${c.replace(/\`/g, "")}</code>`);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
|
|
96
108
|
|
|
97
109
|
|
|
@@ -835,6 +847,10 @@ export class Component {
|
|
|
835
847
|
result += args[i];
|
|
836
848
|
}
|
|
837
849
|
}
|
|
850
|
+
|
|
851
|
+
result = result.replace(/\\n/g, '\n').trim()
|
|
852
|
+
// replace `
|
|
853
|
+
result = result.replace(/`/g, '\`').trim()
|
|
838
854
|
|
|
839
855
|
result = new Function("useRef", `return \`${result}\``)(useRef)
|
|
840
856
|
|
|
@@ -1120,7 +1136,6 @@ export const include = async (path) => {
|
|
|
1120
1136
|
}
|
|
1121
1137
|
return include(includePath).then((includeData) => {
|
|
1122
1138
|
data = data.replace(e, includeData);
|
|
1123
|
-
console.log("included", includePath);
|
|
1124
1139
|
});
|
|
1125
1140
|
});
|
|
1126
1141
|
|