vaderjs 1.2.5 → 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 +52 -24
- package/vaderRouter.js +1 -3
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
|
|
|
@@ -181,8 +193,18 @@ export class Component {
|
|
|
181
193
|
},
|
|
182
194
|
});
|
|
183
195
|
this.snapshots = [];
|
|
196
|
+
|
|
184
197
|
}
|
|
185
198
|
|
|
199
|
+
/**
|
|
200
|
+
* @method adapter
|
|
201
|
+
* @description Allows you to create an adapter - this is used to create custom logic
|
|
202
|
+
*
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
adapter() {
|
|
206
|
+
return
|
|
207
|
+
}
|
|
186
208
|
init() {
|
|
187
209
|
this.registerComponent();
|
|
188
210
|
}
|
|
@@ -825,6 +847,10 @@ export class Component {
|
|
|
825
847
|
result += args[i];
|
|
826
848
|
}
|
|
827
849
|
}
|
|
850
|
+
|
|
851
|
+
result = result.replace(/\\n/g, '\n').trim()
|
|
852
|
+
// replace `
|
|
853
|
+
result = result.replace(/`/g, '\`').trim()
|
|
828
854
|
|
|
829
855
|
result = new Function("useRef", `return \`${result}\``)(useRef)
|
|
830
856
|
|
|
@@ -860,8 +886,10 @@ export class Component {
|
|
|
860
886
|
throw new SyntaxError(
|
|
861
887
|
`Image: ${element.outerHTML} alt attribute cannot be empty`
|
|
862
888
|
);
|
|
889
|
+
|
|
863
890
|
} else if (
|
|
864
891
|
element.hasAttribute("src") &&
|
|
892
|
+
!element.getAttribute("src")?.includes("http") || !element.getAttribute("src")?.includes("https") &&
|
|
865
893
|
!document.documentElement.outerHTML
|
|
866
894
|
.trim()
|
|
867
895
|
.includes("<!-- #vader-disable_accessibility -->")
|
|
@@ -955,16 +983,17 @@ export class Component {
|
|
|
955
983
|
}
|
|
956
984
|
|
|
957
985
|
if (
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
.
|
|
963
|
-
|
|
986
|
+
element.hasAttribute("src") &&
|
|
987
|
+
// @ts-ignore
|
|
988
|
+
!element.getAttribute("src").includes("http") &&
|
|
989
|
+
// @ts-ignore
|
|
990
|
+
!element.getAttribute("src").includes("https") &&
|
|
991
|
+
!document.documentElement.outerHTML.includes(`<!-- #vader-disable_relative-paths -->`)
|
|
964
992
|
) {
|
|
965
993
|
element.setAttribute(
|
|
966
994
|
"src",
|
|
967
|
-
|
|
995
|
+
// @ts-ignore
|
|
996
|
+
`./public/${element.getAttribute("src")}`
|
|
968
997
|
);
|
|
969
998
|
}
|
|
970
999
|
break;
|
|
@@ -1107,7 +1136,6 @@ export const include = async (path) => {
|
|
|
1107
1136
|
}
|
|
1108
1137
|
return include(includePath).then((includeData) => {
|
|
1109
1138
|
data = data.replace(e, includeData);
|
|
1110
|
-
console.log("included", includePath);
|
|
1111
1139
|
});
|
|
1112
1140
|
});
|
|
1113
1141
|
|
|
@@ -1124,4 +1152,4 @@ export const include = async (path) => {
|
|
|
1124
1152
|
});
|
|
1125
1153
|
};
|
|
1126
1154
|
|
|
1127
|
-
export default Vader
|
|
1155
|
+
export default Vader;
|