markdown-it-link-attributes

A markdown-it plugin to configure the attributes for links

MIT License

Downloads
212.1K
Stars
60
Committers
7

Bot releases are hidden (Show)

markdown-it-link-attributes - Latest Release

Published by crookedneighbor about 5 years ago

Breaking Changes from v2.1.0

Drop Support for Markdown-it v8 and lower

New Features

Built version of file is available on npm in the /dist directory

markdown-it-link-attributes -

Published by crookedneighbor over 6 years ago

  • Support strings for pattern option (#18)
markdown-it-link-attributes -

Published by crookedneighbor about 7 years ago

Breaking Changes from v1.0.0

  • Attributes are now nested under an attrs property.
    v1.0.0:

     md.use(mila, {
       target: '_blank',
       rel: 'noopener'
     })
    

    v2.0.0:

     md.use(mila, {
       attrs: {
         target: '_blank',
         rel: 'noopener'
      }
    })
    

    This allows us to support things like pattern

New features

  • Add pattern property to specify a regex to apply config to links conditionally if the href of the link matches it

    md.use(mila, {
      pattern: /^https?:\/\//,
      attrs: {
        target: '_blank',
        rel: 'noopener'
      }
    })
    
  • Add an array of configs for multiple config options, the first pattern to match will use that config

    md.use(mila, [{
      pattern: /^https?:\/\//, // apply target and rel properties for external links
      attrs: {
        target: '_blank',
        rel: 'noopener'
      }, {
      attrs: { // otherwise, apply a class to internal links
        className: 'internal-link'
      }
    })
    
Package Rankings
Top 2.47% on Npmjs.org
Related Projects