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

subttribute

v0.0.2

Published

JavaScript to extract HTML element attributes from the content of other attributes.

Downloads

8

Readme

subttribute

Build Status

A sub-attribute system for constrained markup environments.

Use JavaScript to extract HTML element attributes from the content of other attributes. Primary use case at this time is to add other attributes to a and img tags on Markdown files in GitHub Pages.

This is a JavaScript way to solve the problem of adding class names to links in Markdown, and other similar problems when you want to, or have to, write Markdown but need to put in some more information for styling purposes.

Examples

HTML

See the HTML example or run it live:

The attributes are defined within the title or alt attributes on any element. They are seperated by the ~ character. The section preceding the first ~ is the actual content you want to end up in that attribute. The other are a series of : seperated attribute:value pairs. These will be attached to the same element.

<html>
  <head></head>
  <body>
    <img id="image-one" src="http://lorempixel.com/g/200/100/" title="title text ~ class: border border-purple ~ alt: Some new alt tag">
    <img id="image-two" src="http://lorempixel.com/g/200/100/" alt="alt text ~ class: border border-red ~ title: Some new title tag">
    </p>
    <script src="https://rawgit.com/tleen/subttribute/master/dist/subttribute.min.js"></script>
  </body>
</html>

Would (after JavaScript execution) end up looking like:

<html>
  <head></head>
  <body>
    <img id="image-one" src="http://lorempixel.com/g/200/100/" class="border border-purple" alt="Some new alt tag" title="title text">
    <img id="image-two" src="http://lorempixel.com/g/200/100/" class="border border-red" alt="alt text" title="Some new title tag">
    </p>
    <script src="https://rawgit.com/tleen/subttribute/master/dist/subttribute.min.js"></script>
  </body>
</html>

Although you can set the attributes yourself in HTML the place where subttribute really shines is in:

Markdown

Assuming the subttribute JavaScript included elsewhere in the template:

![some alt tag](http://lorempixel.com/g/200/100/ "title text ~ id: image-one ~ class: border border-purple ~ title: Some new title tag")
![alt text ~ id: image-two ~ class: border border-red](http://lorempixel.com/g/200/100/ "Some title tag")

Will eventually set the attributes on the images:

<p><img src="http://lorempixel.com/g/200/100/" alt="some alt tag" title="Some new title tag" id="image-one" class="border border-purple"></p>
<p><img src="http://lorempixel.com/g/200/100/" alt="alt text" title="Some title tag" id="image-two" class="border border-red"></p>

See the example for Jekyll/Markdown (GitHub Pages-style) usage.