@caganelden/markdjs 1.0.0 → 1.0.1
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/main.js +22 -4
- package/package.json +8 -4
- package/escape.js +0 -9
- package/regex.js +0 -9
package/main.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// This function uses regex to render html elements by markdown
|
|
2
|
+
const inlineRegexParser = (line) => {
|
|
3
|
+
return (line
|
|
4
|
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
5
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
6
|
+
.replace(/\*([^\*]+)\*/g, '<em>$1</em>')
|
|
7
|
+
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g, '<a href="$2">$1</a>')
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// I've written this function for XSS protection
|
|
12
|
+
const escapeHTML = (str) => {
|
|
13
|
+
return str
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// this is the function which does the job
|
|
4
22
|
const rendMD = (mdString) => {
|
|
5
|
-
const lineArr =
|
|
23
|
+
const lineArr = escapeHTML(mdString).split(/\r?\n/);
|
|
6
24
|
const renderedArr = [];
|
|
7
25
|
|
|
8
26
|
let listChecker = false;
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caganelden/markdjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "MarkdJS is a lightweight & easy-to-use markdown to html rendering javascript library with XSS protection.",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
-
"keywords": [
|
|
9
|
+
"keywords": [
|
|
10
|
+
"markdown",
|
|
11
|
+
"markdown-rendering",
|
|
12
|
+
"markdown-to-html"
|
|
13
|
+
],
|
|
10
14
|
"author": "",
|
|
11
15
|
"license": "ISC"
|
|
12
|
-
}
|
|
16
|
+
}
|
package/escape.js
DELETED
package/regex.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// This function uses regex to render html elements by markdown
|
|
2
|
-
const inlineRegexParser = (line) => {
|
|
3
|
-
return (line
|
|
4
|
-
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
5
|
-
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
6
|
-
.replace(/\*([^\*]+)\*/g, '<em>$1</em>')
|
|
7
|
-
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g, '<a href="$2">$1</a>')
|
|
8
|
-
);
|
|
9
|
-
};
|