vuepress / vuepress-community

:bulb: Community supported ecosystem for VuePress
https://vuepress-community.netlify.app
MIT License
81 stars 62 forks source link

[Bug Report] Container plugin, after function always get defaultTitle #24

Closed sambonbonne closed 4 years ago

sambonbonne commented 4 years ago

Environment

Package version: vuepress-plugin-container@2.0.2 VuePress version: vuepress@1.4.0 Markdown It version: markdown-it@8.4.2 Node version: 13.11.0 npm version: 6.14.2 OS: Arch Linux Browser: Firefox 74.0 (but problem is on server-side rendering)

Describe the bug

When using the container plugin, the custom after function isn't called with the block title.

Steps To Reproduce

Following this documentation: https://vuepress.github.io/en/plugins/container/#after

Configure the container plugin with a custom after function:

module.exports = {
  plugins: [
    [
      'vuepress-plugin-container',
      {
        type: 'caption',
        before: '<figure>',
        after: title => `<figcaption>${title}</figcaption></figure>`
      }
    ]
  ]
}

And use it in a Markdown file (let's say README.md or index.md):

::: caption This is my title
This is my content
:::

The This is my title sentence is not given to the after function so the figcaption contains CAPTION (the type of the block). The This is my content sentence is rendered correctly. If you set a before function when configuring the plugin, the title will be given correctly.

Expected behavior

The given title should be used as argument when calling after function so it can be rendered.

Additional context

I did not search a lot but I found that the vuepress-plugin-container/src/index.ts calls renderAfter(info) (line 106) with a wrong info value, but the renderBefore(info) (line 104) contains the correct block's title. It seems the token.info passed to render (line 70) contains only the closing tag, the token has no link to the opening tag so no way to find back the title.

Maybe the "bug" is the documentation which should not tell users that it's possible to get block title in the after function.

meteorlxy commented 4 years ago

Thanks for report. You are right, the block title is not available in after function now.

meteorlxy commented 4 years ago

Fixed in vuepress-plugin-container@2.1.3