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

@rakutentech/docsify-code-inline

v1.0.5

Published

Syntax highlighting for inline code

Downloads

639

Readme

npm size

@rakutentech/docsify-code-inline

A Docsify plugin that enables syntax highlighting for inline code.

Install

The plugin automatically loads itself, unless the data-no-autoload attribute is set. It also automatically injects CSS in the DOM, unless the data-no-css-inject attribute is set:

<!-- autoloads, injects CSS -->
<script
  src="//unpkg.com/@rakutentech/docsify-code-inline/dist/index.min.js"
></script>

<!-- autoloads, doesn't inject CSS -->
<script
  src="//unpkg.com/@rakutentech/docsify-code-inline/dist/index.min.js"
  data-no-css-inject
></script>

<!-- doesn't load, doesn't inject CSS -->
<script
  src="//unpkg.com/@rakutentech/docsify-code-inline/dist/index.min.js"
  data-no-autoload
  data-no-css-inject
></script>

You can also import it as an ES module, if using the .esm build:

<script type="module" src="//unpkg.com/@rakutentech/docsify-code-inline/dist/index.esm.min.js"></script>

The module also supports Node. See the API below.

npm install --save-dev @rakutentech/docsify-code-inline

Usage

If you wrap `code` with square brackets and add a language identifier, e.g.
[`<link href="foo">` html], then the produced markup will enable syntax
highlighting using PrismJS like in code fences.

…gets transformed by this plugin into:

If you wrap `code` with square brackets and add a language identifier, e.g. <code class="language-html">&lt;link href="foo"&gt;</code>, then the produced markup will
enable syntax highlighting using PrismJS like in code fences.

…which produces the following DOM tree when PrismJS is active and supports HTML:

<p>
  If you wrap
  <code>
    code
  </code>
  with square brackets and add a language identifier, e.g.
  <code class="language-html">
    <span class="token tag">
      <span class="token tag">
        <span class="token punctuation">
          &lt;
        </span>
        link
      </span>

      <span class="token attr-name">
        href
      </span>
      <span class="token attr-value">
        <span class="token punctuation attr-equals">
          =
        </span>
        <span class="token punctuation">
          "
        </span>
        foo
        <span class="token punctuation">
          "
        </span>
      </span>
      <span class="token punctuation">
        &gt;
      </span>
    </span>
  </code>
  , then the produced markup will enable syntax highlighting using PrismJS like in code fences.
</p>

Styling

The plugin uses the styles defined by docsify-themeable.

Typescript

Types are included in the library.

API

Two things are exported:

  • const DEFAULT_CSS: string, the CSS rules that are normally added to the DOM when the library is loaded in a browser and data-no-css-inject not used.
  • function transform(markdown: string): string, the method used by the plugin to replace inline code with syntax-highlighted spans in a markdown document.

License

MIT