mikel-markdown 0.32.0 → 0.33.0

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.
Files changed (2) hide show
  1. package/index.js +25 -32
  2. 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
- return {
210
- helpers: {
211
- markdown: params => {
212
- const tableOfContents = [];
213
- const result = parser(params.fn(params.data) || "", {
214
- ...options,
215
- hooks: {
216
- beforeRender: (key, args) => {
217
- if (key === "heading") {
218
- tableOfContents.push({
219
- level: args[1].length,
220
- text: args[2],
221
- slug: args[2].toLowerCase().replaceAll(" ", "-"),
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
- // create a new variable @toc with the generated table of contents
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel-markdown",
3
3
  "description": "A mikel helper for parsing markdown content.",
4
- "version": "0.32.0",
4
+ "version": "0.33.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {