mikel-markdown 0.32.0 → 0.33.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 +25 -32
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -205,40 +205,33 @@ const parser = (str = "", options = {}) => {
|
|
|
205
205
|
|
|
206
206
|
// @description markdown plugin
|
|
207
207
|
// @param options {object} options for this plugin
|
|
208
|
-
const markdownPlugin = (options = {}) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
},
|
|
208
|
+
const markdownPlugin = (options = {}) => ({
|
|
209
|
+
helpers: {
|
|
210
|
+
markdown: params => {
|
|
211
|
+
params.state.toc = []; // variable to save table of contents
|
|
212
|
+
return parser(params.fn(params.data) || "", {
|
|
213
|
+
...options,
|
|
214
|
+
hooks: {
|
|
215
|
+
beforeRender: (key, args) => {
|
|
216
|
+
if (key === "heading") {
|
|
217
|
+
params.state.toc.push({
|
|
218
|
+
level: args[1].length,
|
|
219
|
+
text: args[2],
|
|
220
|
+
slug: args[2].toLowerCase().replaceAll(" ", "-"),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
225
223
|
},
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
Object.assign(params.variables, {
|
|
229
|
-
"toc": tableOfContents,
|
|
230
|
-
});
|
|
231
|
-
return result;
|
|
232
|
-
},
|
|
233
|
-
inlineMarkdown: params => {
|
|
234
|
-
return parser(params.fn(params.data) || "", {
|
|
235
|
-
...options,
|
|
236
|
-
expressions: getInlineExpressions(options.expressions || allExpressions),
|
|
237
|
-
});
|
|
238
|
-
},
|
|
224
|
+
},
|
|
225
|
+
});
|
|
239
226
|
},
|
|
240
|
-
|
|
241
|
-
|
|
227
|
+
inlineMarkdown: params => {
|
|
228
|
+
return parser(params.fn(params.data) || "", {
|
|
229
|
+
...options,
|
|
230
|
+
expressions: getInlineExpressions(options.expressions || allExpressions),
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
242
235
|
|
|
243
236
|
// assign additional options for this plugin
|
|
244
237
|
markdownPlugin.parser = parser;
|