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

gatsby-remark-prismjs-title

v1.0.0

Published

コードスニペットの前にコードのタイトルを追加します。

Downloads

141

Readme

gatsby-remark-prismjs-add-title

コードスニペットの前にコードのタイトルを追加します。

例

インストール

npm install gatsby-remark-prismjs-add-title --save-dev

使い方

プラグインの登録

gatsby-config.jsに以下の設定を追加します。

plugins: [
  {
    resolve: 'gatsby-transformer-remark',
    options: {
      plugins: [
        {
          resolve: 'gatsby-remark-prismjs-title',
          options: {
            className: 'your-custom-class-name'
          }
        } // 重要: コードブロックを使用する他のプラグインより前に定義する必要があります。
      ]
    }
  }
]

CSSの追加

タイトルのタグにはgatsby-code-titleクラスが設定されます。 コードに設定しているスタイルに合わせて、スタイルを設定して下さい。

以下は、prism.jsのスタイルにokaidiaを使用している場合の例です。

.gatsby-code-title {
  display: block;
  position: relative;
  background: #272822;
  width: 100%;
  top: 10px;
  border-top-left-radius: 0.3em;
  border-top-right-radius: 0.3em;
}

.gatsby-code-title span {
  display: inline;
  position: relative;
  font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
  color: #eee;
  background: #777;
  border-top-left-radius: 0.3em;
  border-bottom-right-radius: 0.3em;
  padding: 3px;
  top: 1px;
}

マークダウンでの使い方

マークダウンには:title=表示するタイトルの形式で設定します。

```js:title=example-file.js
alert('how cool is this!');
```js

このプラグインは Markdown ASTを解析し、以下のような構造に変換します。

<div class="gatsby-code-title"><span>example-file.js</span></div>
```js
alert('how cool is this');
```

また、gatsby-remark-prismjsのハイライトや行番号表示と組み合わせて使用する事が可能です。

```go{numberLines: true}{4,8-9}:title=example.go
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello")
	fmt.Println("World")
}
```

gatsby-remark-code-titlesとの違い

gatsby-remark-prismjsのLine Highlightの指定と同時に使用可能。 また、タイトルをspanタグで囲う。

  • gatsby-remark-code-titles

    <div class="gatsby-code-title">title</div>

  • このプラグイン

    <div class="gatsby-code-title"><span>title</span></div>