Coder Social home page Coder Social logo

gatsby-remark-code-selector's Introduction

gatsby-remark-code-selector

Transform equivalent code blocks in Gatsby markdown files into a selector.

Example in the API Platform website:

Example in the API Platform website

Dependencies

  • gatsby-transformer-remark
  • gatsby-remark-prismjs

Features

  • Selecting a language in a selector select the language for all the selectors in the page as well, if the language is available for them.
  • The chosen language is kept in the local storage: if the page is refreshed or if another page is loaded, the language will be selected for all the selectors.

How to install

Add the plugin to your project:

npm install --save gatsby-remark-code-selector

Configure the plugin:

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          // gatsby-remark-prismjs must go
          // before gatsby-remark-code-selector
          `gatsby-remark-prismjs`,
          `gatsby-remark-code-selector`,
        ],
      },
    },
  ],
};

Restart Gatsby.

How to use

In your markdown files:

[codeSelector]
```php
<?php
use ApiPlatform\Core\Annotation\ApiResource;

/**
 * @ApiResource(itemOperations={"get"})
 */
class Book
{
    //...
}
```

```yaml
App\Entity\Book:
    itemOperations:
        get: ~
```

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="https://api-platform.com/schema/metadata
           https://api-platform.com/schema/metadata/metadata-2.0.xsd">
    <resource class="App\Entity\Book">
        <itemOperations>
            <itemOperation name="get" />
        </itemOperations>
    </resource>
</resources>
```
[/codeSelector]

The code selector is not stylized by default. You can add your own CSS by using the following class names:

  • code-selector for the whole selector
  • code-selector-toolbar for the container of the select buttons
  • code-selector-select-php for a particular button
  • code-selector-code-php for a particular code block

gatsby-remark-code-selector's People

Contributors

alanpoulain avatar

Watchers

 avatar

Forkers

devgir

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.