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

remark-image-attributes

v0.2.1

Published

Parses markdown for images with attributes (lead by a `#`) and puts those attributes on a mdAST `image` node with key `attributes` and value of type `Object.<string,string>`.

Downloads

35

Readme

remark-image-attributes

Parses markdown for images with attributes (lead by a #) and puts those attributes on a mdAST image node with key attributes and value of type Object.<string,string>.

The returned nodes also have an inline flag.

{
  type: 'image',
  ...
  attributes: { border: '3px dashed blue', cursor: 'pointer'},
  inline: false
}

Since this parser has been written to feed styles to gatsby-remark-image-attributes, the examples revolve around CSS properties; yet the parser does not care about the keys nor values, as long as the key=value; format is met.

Installation

npm install --save remark-image-attributes

How to use

Run this example with npm run example

Have an .md file with some images:

Add style attributes to the image

![some oranges](https://images.pexels.com/photos/2090903/pexels-photo-2090903.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260#width=1260;height=740)

You don't need an alt text

![](https://images.pexels.com/photos/3104856/pexels-photo-3104856.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260#box-shadow=0 1px 5px 5px;border-radius=50%;border-color=rgb(120,120,120))

Put your image wherever you want

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at ![happy](https://images.pexels.com/photos/2728493/pexels-photo-2728493.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940#width=200px;float=right) Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32

Have it parsed or processed by remark, using this plugin:

const vfile = require("to-vfile");
const remark = require("remark");
const remarkParser = require("remark-parse");
const remarkImageAttributes = require("../index.js");
const visit = require("unist-util-visit");

const markdown = vfile.readSync(`${__dirname}/example.md`);

const markdownAST = remark()
  .use(remarkParser, { position: false })
  .use(remarkImageAttributes)
  .parse(markdown);

visit(markdownAST, "image", node => console.log(node));

Get these 'image' type nodes:

{
  type: 'image',
  alt: 'some oranges',
  title: 'some oranges',
  url: 'https://images.pexels.com/photos/2090903/pexels-photo-2090903.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260',
  attributes: { width: '1260', height: '740' },
  inline: false
},
{
  type: 'image',
  alt: null,
  title: null,
  url: 'https://images.pexels.com/photos/3104856/pexels-photo-3104856.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260',
  attributes: {
    'box-shadow': '0 1px 5px 5px',
    'border-radius': '50%',
    'border-color': 'rgb(120,120,120)'
  },
  inline: false
},
{
  type: 'image',
  alt: 'happy',
  title: 'happy',
  url: 'https://images.pexels.com/photos/2728493/pexels-photo-2728493.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
  attributes: { width: '200px', float: 'right' },
  inline: true
}

Caveats

  • The plugin doesn't recognize the title syntax but rather copies the [altText] to the title field.

    Beware: '<space>title' will become part of the last attribute!

    ![altText](https://image.com/foo.png#attribute=yes title)

    results in

    {
      type: 'image',
      alt: 'altText',
      title: 'altText',
      url: 'https://image.com/foo.png',
      attributes: { attribute: 'yes title' },
      inline: false
    }