mikel-markdown 0.26.0 → 0.26.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/index.js +12 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -80,14 +80,14 @@ const allExpressions = {
|
|
|
80
80
|
replace: (args, cn) => {
|
|
81
81
|
return render("ul", {class: cn.list}, render("li", {class: cn.listItem}, args[1]));
|
|
82
82
|
},
|
|
83
|
-
afterRegex: /(<\/ul>\n(?:.*)<ul ?(?:class="
|
|
83
|
+
afterRegex: /(<\/ul>\n(?:.*)<ul ?(?:class="[^"]*")?>*)+/g
|
|
84
84
|
},
|
|
85
85
|
orderedList: {
|
|
86
86
|
regex: /^[\t\s]*?(?:\d(?:\)|\.))\s(.*)/gm,
|
|
87
87
|
replace: (args, cn) => {
|
|
88
88
|
return render("ol", {class: cn.list}, render("li", {class: cn.listItem}, args[1]));
|
|
89
89
|
},
|
|
90
|
-
afterRegex: /(<\/ol>\n(?:.*)<ol ?(?:class="
|
|
90
|
+
afterRegex: /(<\/ol>\n(?:.*)<ol ?(?:class="[^"]*")?>*)+/g
|
|
91
91
|
},
|
|
92
92
|
strong: {
|
|
93
93
|
regex: /(?:\*\*|__)([^\n]+?)(?:\*\*|__)/g,
|
|
@@ -101,8 +101,8 @@ const allExpressions = {
|
|
|
101
101
|
regex: /^((?:.+(?:\n|$))+)/gm,
|
|
102
102
|
replace: (args, cn) => {
|
|
103
103
|
const line = args[0].trim();
|
|
104
|
-
// check if the line starts with a block tag
|
|
105
|
-
if (/^\<(\/? *(ul|ol|bl|h\d|p|
|
|
104
|
+
// check if the line starts with a block tag or is an empty line
|
|
105
|
+
if (!line || /^\<(\/? *(ul|ol|bl|h\d|p|div|sty|scr|t)|!--)/.test(line.slice(0, 4))) {
|
|
106
106
|
return line;
|
|
107
107
|
}
|
|
108
108
|
return render("p", {class: cn.paragraph}, line.replace(/\n/g, ""));
|
|
@@ -110,10 +110,13 @@ const allExpressions = {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
// @description inline expressions
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
// @description get only inline expressions
|
|
114
|
+
const getInlineExpressions = expressions => {
|
|
115
|
+
const fields = ["code", "link", "strong", "emphasis", "image"].filter(key => !!expressions[key]);
|
|
116
|
+
return Object.fromEntries(fields.map(key => {
|
|
117
|
+
return [key, expressions[key]];
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
117
120
|
|
|
118
121
|
// @description markdown parser
|
|
119
122
|
const parser = (str = "", options = {}) => {
|
|
@@ -160,8 +163,8 @@ const markdownPlugin = (options = {}) => {
|
|
|
160
163
|
},
|
|
161
164
|
inlineMarkdown: params => {
|
|
162
165
|
return parser(params.fn(params.data) || "", {
|
|
163
|
-
expressions: inlineExpressions,
|
|
164
166
|
...options,
|
|
167
|
+
expressions: getInlineExpressions(options.expressions || allExpressions),
|
|
165
168
|
});
|
|
166
169
|
},
|
|
167
170
|
},
|