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

posthtml-bemify

v1.0.7

Published

Bemify – PostHTML plugin to transform custom elements tags into HTML with BEM methodology class names

Downloads

7

Readme

PostHTML Bemify plugin

This Posthtml plugin transform custom tags with specific attributes to BEM-like HTML

Install

npm i mayoujin/posthtml-bemify#1.0.0 --save-dev
// or
npm i posthtml-bemify@1 --save-dev

Usage

// posthtml.config.js
module.exports = {
  plugins: {
    "posthtml-bemify": {
      skipTags: ["svg"],
    },
  }
}

Example

Blocks

Default

<page bem:b>
    <header></header>
    <article></article>
    <footer></footer>
</page>

Would be transformed to html:

<div class="page">
    <div class="page__header"></div>
    <div class="page__article"></div>
    <div class="page__footer"></div>
</div>

Named blocks

<section bem:b="page">
    <header></header>
    <article></article>
    <footer></footer>
</section>

Would be transformed to html:

<section class="page">
    <div class="page__header"></div>
    <div class="page__article"></div>
    <div class="page__footer"></div>
</section>

Multiple names of block

<section bem:b="page|page-main">
    <header></header>
    <article></article>
    <footer></footer>
</section>

Would be transformed to html:

<section class="page page-main">
    <div class="page__header page-main__header"></div>
    <div class="page__article page-main__article"></div>
    <div class="page__footer page-main__footer"></div>
</section>

Nested blocks

<section bem:b="page">
    <article bem:b>
        <text tag="p">Content</textp>
    </article>
</section>

Would be transformed to html:

<section class="page">
    <div class="page__article article">
        <p class="article__text">Content</p>
    </div>
</section>

Elements

With custom name

<page bem:b>
    <header bem:e="top"></header>
    <article bem:e="content"></article>
    <footer bem:e="bottom"></footer>
</page>

Would be transformed to html:

<div class="page">
    <header class="page__top"></header>
    <article class="page__content"></article>
    <footer class="page__bottom"></footer>
</div>

With selective element name of multiple names block

<section bem:b="page|page-main">
    <header bem:e="top" bem:e:of="page"></header>
    <article bem:e="content" bem:e:of="page-main"></article>
    <footer bem:e="bottom" bem:e:of="page"></footer>
</section>

Would be transformed to html:

<div class="page page-main">
    <header class="page__top"></header>
    <article class="page-main__content"></article>
    <footer class="page__bottom"></footer>
</div>

Modifiers

<block bem:b bem:m.bordered.rounded>
    <custom-element bem:m.active></custom-element>
</block>

Would be transformed to html:

<div class="block block--bordered block--rounded">
    <div class="block__custom-element block__custom-element--active"></div>
</div>

Tag attr

<submit bem:b tag="button">
    <text tag="span"></text>
</submit>

Transformed to:

<button class="submit">
    <span class="submit__text"></span>
</button>

Skip attrs

Skip element with children

<block bem:b>
    <h1>Heading</h1>
    <ul bem:skip>
        <li>1</li>
        <li>2</li>
    </ul>
</block>

Transformed to:

<div class="block">
    <h1 class="block__h1">Heading</h1>
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
</div>

Skip elements children only

<block bem:b>
    <h1>Heading</h1>
    <list tag="ul" bem:skip.children>
        <li>1</li>
        <li>2</li>
    </list>
</block>

Transformed to:

<div class="block">
    <h1 class="block__h1">Heading</h1>
    <ul class="block__list">
        <li>1</li>
        <li>2</li>
    </ul>
</div>

Options

{
    /**
    * Default block HTML tag
    * @type {string}
    * @default
    */
    blockTag: 'div',
    
    /**
    * Default element HTML tag
    * @type {string}
    * @default
    */
    elementTag: 'div',
    
    /**
    * Skip HTML tags list
    * @type {string[]}
    * @default
    */
    skipTags: ['b', 'strong', 'i', 'span', 'div', 'section'],

    /**
    * Overrides bem separators
    * @type {{ blockPrefix: string, element: string, modifier: string, modifierValue: string }|false} 
    * @default
    */
    bem: {
        blockPrefix: "",
        element: "__",
        modifier: "--",
        modifierValue: "_"
    },

    /**
     * Pattern to ignore node tag transformation
     *
     * @type {{ tag?: /^[a-z-]{3}$/ } | null}
     * @default
     */
    ignoreTransformTag: null,
      
    /**
     * Match target nodes
     * 
     * @type {{ BLOCK?: { tag: RegExp } | string, ELEMENT?: string | MODIFIER?: string} | null }
     * @default
     */
    matcher: { 
      BLOCK: 'bem:b' | { tag: /^[a-z-]{3}$/ },
      ELEMENT: 'bem:e',
      MODIFIER: 'bem:m'
    },
  
    /**
     * Custom node visitor 
     *
     * @type {function(node: { tag: string, attrs: object }, { b: string, e: string, m: string } ): void|null}
     * @default
     */
    nodeVisitor({ tag: /^[a-z-]{3}$/ })

}