Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue mixing figures with markdown-it-attrs #18

Closed
felixsanz opened this issue May 19, 2017 · 18 comments 路 Fixed by arve0/markdown-it-attrs#35
Closed

Issue mixing figures with markdown-it-attrs #18

felixsanz opened this issue May 19, 2017 · 18 comments 路 Fixed by arve0/markdown-it-attrs#35

Comments

@felixsanz
Copy link

felixsanz commented May 19, 2017

Hi there!

I'm having an issue mixing this plugin with markdown-it-attrs (monopoly! 馃槤 ).

This works: [![](fig.png)](page.html)

But if you do this: [![](fig.png)](page.html){target="_blank"} , now there is no <figure>. It becomes a plain <p><a><img> :/

I want to do it because i want the linked image to open on a separate window if possible

Thanks!

BTW: i have no idea of how to fix it!

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Ref #13

@felixsanz
Copy link
Author

@arve0 Oh, i didn't look at closed issues. I confirm is still present at latest version

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Yes. I haven't looked into it yet.

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Regression added in a7aab96, md.core.ruler.after('inline', 'implicit_figures', implicitFigures); forces plugin to be run before markdown-it-attrs.

@felixsanz
Copy link
Author

This is the order that i was using:

const md = new MarkdownIt({
  html: true,
})

md.use(MarkdownItSamp)

md.use(MarkdownItImplicitFigures, {
  figcaption: true,
})

md.use(MarkdownItAttrs)

arve0 added a commit to arve0/markdown-it-attrs that referenced this issue May 19, 2017
plugin markdown-it-implicit-figures is added before linkify,
so to assure that attrs plugin is added before implicit-figures
.use() attrs first, then implicit-figures:

md.use(attrs).use(implicitFigures)

ref: arve0/markdown-it-implicit-figures#18
@arve0
Copy link
Owner

arve0 commented May 19, 2017

After arve0/markdown-it-attrs#35 is merged and published, change the order you load the plugins:

const md = new MarkdownIt({
  html: true,
})

md.use(MarkdownItSamp)

md.use(MarkdownItAttrs)

md.use(MarkdownItImplicitFigures, {
  figcaption: true,
})

arve0 added a commit to arve0/markdown-it-attrs that referenced this issue May 19, 2017
* fix typography test

* add plugin before linkify

plugin markdown-it-implicit-figures is added before linkify,
so to assure that attrs plugin is added before implicit-figures
.use() attrs first, then implicit-figures:

md.use(attrs).use(implicitFigures)

ref: arve0/markdown-it-implicit-figures#18

* output in runkit.com is last line, fix demo
@felixsanz
Copy link
Author

@arve0 Sadly i can't confirm its working! It's still the same result using 0.9.0. It produces <p><a target="_blank"><img> in both orders (attrs->figures or figures->attrs).

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Please link to an example which reproduces your error, like in runkit.com or jsfiddle.

@felixsanz
Copy link
Author

@arve0 arve0 reopened this May 19, 2017
@arve0
Copy link
Owner

arve0 commented May 19, 2017

I'm unable to reproduce this locally. Are you sure you have done npm install markdown-it-attr to update package? Can you confirm package version with grep version node_modules/markdown-it-attr/package.json?

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Wait a minute!

@arve0
Copy link
Owner

arve0 commented May 19, 2017

Please update markdown-it-implicit-figures to v0.6.0.

@arve0
Copy link
Owner

arve0 commented May 19, 2017

@arve0 arve0 closed this as completed May 19, 2017
@felixsanz
Copy link
Author

Now it works! Thanks! (sorry for the deleted message)

@egardner
Copy link

Hi there! It looks like I'm having the same issue (I can have attributes, or implicit figures, but not both for the same image). The only difference in my use case is that I'm using the markdown-it-loader in Webpack 2. The loader requires the various markdown-it plugins to be passed in during configuration, so I'm not sure if I have much control over the order here. I'm using the latest versions of all packages.

Here's an abbreviated version of the webpack config file:

var webpack = require('webpack')

// Markdown-it Plugins
var footnotes = require('markdown-it-footnote')
var subscript = require('markdown-it-sub');
var superscript = require('markdown-it-sup');
var figures = require('markdown-it-implicit-figures')
var attrs = require('markdown-it-attrs')

module.exports = {

  // various other rules, etc. omitted for brevity 
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: 'html-loader'
          },
          {
            loader: 'markdown-it-loader'
          }
        ]
      }
    ]
  },
  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        'markdown-it': {
          preset: 'default',
          html: true,
          typographer: true,
          use: [
            footnotes,
            superscript,
            subscript,
            attrs,
            [figures, { figcaption: true }]
          ]
        }
      }
    })
  ]
}

When I require a Markdown file into the build pipeline, implicit figures OR attributes work for a given image, but adding say a class to an image means that the figure markup gets dropped.

<!-- This creates an image wrapped in <figure> tags with a <figcaption> -->
![Dick Higgins in Copenhagen, 1962][fig2]

<!-- This outputs an <img> tag with class="foo" -->
![George Maciunas in Dusseldorf][fig3]{.foo}

Any ideas on what might be happening here? I can try to put a small app together to illustrate the use case if this would be helpful.

@arve0
Copy link
Owner

arve0 commented Sep 14, 2017

markdown-it-attrs just had a major rewrite, so the bug may have been reintroduced. I'll have to investigate.

@arve0
Copy link
Owner

arve0 commented Sep 15, 2017

@egardner Thanks for reporting. Should be fixed in markdown-it-attrs v1.1.1. Make sure you have the correct version installed with npm ls.

@egardner
Copy link

Perfect, I updated markdown-it-attrs from v1.1.0 to v1.1.1 and everything works correctly now. Thanks for creating these libraries聽鈥撀爃aving support for basic scholarly features in Markdown is enormously useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants