All Projects β†’ chrisg86 β†’ gatsby-remark-classes

chrisg86 / gatsby-remark-classes

Licence: MIT license
Automatically add class attributes to markdown elements

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gatsby-remark-classes

gatsby-plugin-prettier-build
prettify gatsby build output
Stars: ✭ 30 (+150%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-disqus
πŸ’¬ A plugin for adding Disqus comments to GatsbyJS
Stars: ✭ 40 (+233.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-apollo-client
πŸ“‘Inject a Shopify Apollo Client into the browser.
Stars: ✭ 20 (+66.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-stripe
Gatsby source plugin for building websites using Stripe as a data source
Stars: ✭ 71 (+491.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-deck-n-blog
Create a deck (with mdx-deck) and a blog post from the same MDX
Stars: ✭ 17 (+41.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-i18n
Gatsby plugin that provides i18n support
Stars: ✭ 25 (+108.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-optimize-svgs
A Gatsby Plugin to minify SVGs output to the filesystem during the build.
Stars: ✭ 39 (+225%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-behance
Gatsby source plugin for loading information from Behance
Stars: ✭ 17 (+41.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (+16.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-gallery
🏞 A Gatsby Theme for adding a gallery to your site.
Stars: ✭ 40 (+233.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-remark-embedded-codesandbox
A Gatsby Remark plugin for embedding Codesandbox given a folder of files
Stars: ✭ 31 (+158.33%)
Mutual labels:  gatsby-plugin, gatsby-remark
gatsby-theme-nehalem
A Gatsby blog theme.
Stars: ✭ 168 (+1300%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-attila-theme-ghost
A Gatsby theme plugin for creating blogs from headless Ghost CMS.
Stars: ✭ 16 (+33.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-lunr
Gatsby plugin for full text search implementation based on lunr client-side index. Supports multilanguage search.
Stars: ✭ 69 (+475%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-directus7
Source plugin for pulling data into GatsbyJS from Directus CMS (https://directus.io)
Stars: ✭ 17 (+41.67%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-firestore
Gatsby source plugin for building websites using the Firestore as a data source.
Stars: ✭ 30 (+150%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-printful
Printful store data for your Gatsby projects
Stars: ✭ 19 (+58.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-tailwindcss
Plug Tailwind CSS to your Gatsby website
Stars: ✭ 46 (+283.33%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-moltin
πŸš€ Gatsby source plugin for building Elastic Path Commerce Cloud powered eCommerce websites
Stars: ✭ 21 (+75%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-robots-txt
Gatsby plugin that automatically creates robots.txt for your site
Stars: ✭ 105 (+775%)
Mutual labels:  gatsby, gatsby-plugin

gatsby-remark-classes

Automatically add class attributes to markdown elements.

This is a plugin for gatsby-transformer-remark.

Install

npm install --save gatsby-remark-classes

Configure

In your gatsby-config.js:

{
  resolve: `gatsby-transformer-remark`,
  options: {
    plugins: [
      {
        resolve: `gatsby-remark-classes`,
        options: {
          classMap: {
            "heading[depth=1]": "title",
            "heading[depth=2]": "subtitle",
            paragraph: "para",
          }
        }
      }
    ]
  }
}

The rules above applied to the following markdown

# Main heading

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.

## Sub header

Lorem ipsum dolor sit amet, consectetur adipisicing.

Will result in this HTML output:

<h1 class="title">Main heading</h1>
<p class="para">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.
</p>

<h2 class="subtitle">Sub header</h2>
<p class="para">Lorem ipsum dolor sit amet, consectetur adipisicing.</p>

The classMap

For supported selectors please please consult syntax-tree/mdast for the node list and have a look at the Support section of unist-util-select

Motivation

Applying custom styles is also possible by just wrapping your converted markdown in a parent element and write the styles for that. This will however not work if you use atomic css in your project or a framework like Semantic UI or Tailwind CSS.

With this project you define which classes get assigned to which element.

Upgrade guide

When upgrading from version 0.x.x to 1.x.x, you will have to update the selectors in your gatsby-config.js file.

Some common selectors:

  • h1 is now heading[depth=1]
  • h2 is now heading[depth=2]
  • ul is now list[ordered=false]
  • ol is now list[ordered=true]
  • li is now listItem
  • paragraph is still paragraph

Additionally you have now the chance to target child elements code > pre or even adjacent elements paragraph + paragraph. As stated above, please consult syntax-tree/mdast for the node list and syntax-tree/unist-util-select for pseudo selectors and syntax.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].