Markdownit injected=true option prevents plugins from running

janzheng
0
janzheng
commented 2 years ago

Version

latest

Reproduction link

https://github.com/nuxt-community/modules/tree/master/packages/markdownit

Steps to reproduce

Create a new vue template page with:

<template lang="md">

This is a title{.bold}

</template>

Nuxt config:

markdownit: {
injected: true, // commented out to allow attrs in lang="md" blocks
use: [
'markdown-it-attrs',
],
},

What is expected ?

Expected output:

This is a title

What is actually happening?

Current output when injected is set to true is this:

This is a title{.bold}

But plugins still work when using $md.render, so $md.render("# This is a title{.bold}") still outputs expected output.

If injected is set to false, everything works as expected, and the plugins work.

Additional comments?

I dug through the code and found the culprit. In @nuxtjs/markdownit/index.js:

  if (_options.injected === true) {
    delete _options.injected
    // Register plugin
    this.addPlugin({
      src: path.resolve(__dirname, 'plugin.js'),
      fileName: 'markdown-it.js',
      options: _options // <--- this needs an object assignment: Object.assign({}, options, this.options.markdownit)
    })
  }

options: _options needs an object assignment because in plugin.js, you perform a .shift() on options in the for of loop that gets rid of the plugins and prevents them from being rendered properly.

bug
0

Cancelled

2 years ago by manniL

Informations
Bug Report โ€ข Cancelled
#c133 - Created 2 years ago