npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markdown-it-gallery

v0.1.6

Published

A markdown-it plugin for wrapping a sequence of images with a custom block element

Downloads

15

Readme

markdown-it-gallery

NPM Stable Version Build Status Test Coverage Dependency Status Node.js Version License

A markdown-it plugin for wrapping a sequence of images with a custom block element.

Usage

Options

  • galleryClass: String
  • galleryTag: String Default: figure
  • imgClass: String
  • wrapImagesInLinks: Boolean Default: false
  • linkClass: String
  • linkTarget: String Link target attribute
  • imgTokenType: String Default: image
  • linkTokenType: String Default: link
  • imageFilterFn: function(token) { ... } => Boolean token argument is a Token instance
  • imageSrcFn: function(token) { ... } => String token argument is a Token instance
  • linkHrefFn: function(token) { ... } => String token argument is a Token instance

Example

const Md = require('markdown-it');
const galleryPlugin = require('markdown-it-gallery');

const md = Md().use(galleryPlugin, {
    galleryClass: 'md-gallery',
    galleryTag: 'figure',
    imgClass: 'md-gallery__image',
    wrapImagesInLinks: true,
    linkClass: 'md-gallery__link',
    linkTarget: '_blank',
    imgTokenType: 'image',
    linkTokenType: 'link',
    imageFilterFn: token => /example.com/.test(token.attrGet('src')),
    imageSrcFn: token => token.attrGet('src').replace(/(\.\w+$)/, '-320x320$1'),
    linkHrefFn: token => token.attrGet('src').replace(/(\.\w+$)/, '-1920x1920$1'),
});

/**
 * @param {string} markdown
 * @returns {string} HTML
 */
function render(markdown) {
    return md.render(markdown);
}

Input markdown:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

![Gallery Image 1](http://example.com/image-1.jpg)
![Gallery Image 2](http://example.com/image-2.jpg)

Aliquam elit felis, varius non ligula et, vestibulum pulvinar libero.

![Gallery Image 3](http://example.com/image-3.jpg)

![Filtered Image 3](http://example.net/image-4.jpg)

Cras ut rutrum est, sodales porta orci. ![Inline image 1](http://example.com/inline-image-1.jpg) Quisque aliquet ipsum sit amet lacus consequat varius.

![Inline image 2](http://example.com/inline-image-2.jpg)
Proin pretium tortor in turpis tristique, in pharetra ipsum maximus.

Output HTML:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

<figure class="md-gallery">
    <a href="http://example.com/image-1-1920x1920.jpg" class="md-gallery__link" target="_blank">
        <img src="http://example.com/image-1-320x320.jpg" alt="Gallery Image 1" class="md-gallery__image">
    </a>
    <a href="http://example.com/image-2-1920x1920.jpg" class="md-gallery__link" target="_blank">
        <img src="http://example.com/image-2-320x320.jpg" alt="Gallery Image 2" class="md-gallery__image">
    </a>
</figure>

<p>Aliquam elit felis, varius non ligula et, vestibulum pulvinar libero.</p>

<figure class="md-gallery">
    <a href="http://example.com/image-3-1920x1920.jpg" class="md-gallery__link" target="_blank">
        <img src="http://example.com/image-3-320x320.jpg" alt="Gallery Image 3" class="md-gallery__image">
    </a>
</figure>

<p>
    <img src="http://example.net/image-4.jpg" alt="Filtered Image 3">
</p>

<p>
    Cras ut rutrum est, sodales porta orci. <img src="http://example.com/inline-image-1.jpg" alt="Inline image 1"> Quisque aliquet ipsum sit amet lacus consequat varius.
</p>

<p>
    <img src="http://example.com/inline-image-2.jpg" alt="Inline image 2">
    Proin pretium tortor in turpis tristique, in pharetra ipsum maximus.
</p>