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

prismize

v1.2.1

Published

Display code in HTML using Prism.JS to do syntax highlighting.

Downloads

10

Readme

Prismize

Easily use Prism.js on any web page.

Changelog

All of the changes from version to version can be found here.

Usage

You must include prismize.js in your page and then a <pre> tag that contains an attribute named "data-prismize" and a value matching the language that you want to use for the syntax highlighting (eg. apex, css, javascript, etc.). Here is a simple example:

<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/prismize/prismize.min.js"></script>
  </head>
  <body>
    <pre data-prismize="apex">
      System.debug(JSON.serializePretty(new Map&lt;String,Object> {
        'first' => 'John',
        'age' => 23
      }));
    </pre>
  </body>
</html>

Default Options

Default options can be set by including them as URL parameters in the <script> tag:

<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/prismize/prismize.min.js?copyable"></script>
  </head>
  <body>
    <pre data-prismize="javascript">
      const adjective = "crazy";
      console.log(`Hello ${adjective} world!`);
    </pre>
  </body>
</html>

Attribute Options

Options for specific prismized content can be set by including the correct data-* attributes in the <pre> tag. The following are all of the supported data-* attributes that you can use:

Attribute | Type | Description --|--|-- data-action-* | String | Specify an attribute starting with data-action- to add an additional button to the toolbar. These buttons will be ordered by the name of the attributes, not the labels. All custom action buttons will appear before the Copy and Download buttons. data-copyable | Boolean | String | If this is a boolean value it indicates whether or not to show a copy to clipboard button in a info bar in the top-right corner of the code block. If this is a string the code block will appear with a copy to clipboard button in the info bar in the top-right with this string as the button's label. data-downloadable | Boolean | String | If this is a boolean value it indicates whether or not to show a download button in a info bar in the top-right corner of the code block. If this is a string the code block will appear with a download button in the info bar in the top-right with this string as the button's label. data-downloadable | String | The file name for the file that will be downloaded. data-info-text | String | Used to show specific text after the language tag but before the buttons in the info bar. data-info-html | String | Used to evaluate HTML that will appear after the language tag but before the buttons in the info bar. data-language | String | Alternative to data-language. Used to indicate the language to be used to highlight the syntax. data-match-braces | Boolean | Indicates whether to use the match-braces plugin. data-max-height | Integer | Indicates the maximum height of the containing element (IFRAME) of the syntax highlighted code. data-number-lines | Boolean | Integer | If this is a boolean value it indicates whether or not to number the lines. If this is an integer the code block will appear with numbered lines starting with the specified number. data-placement | String | Indicates where to place the prismized syntax highlighted block. Defaults to "replace". Valid values are as follows:"start" - Inserts as the first element of this <pre> tag."end" - Inserts as the last element of this <pre> tag."before" - Inserts as an element directly before this <pre> tag."after" - Inserts as an element directly after this <pre> tag."replace" - Replaces this <pre> tag. data-preview-colors | Boolean | Indicates whether to use the inline-color plugin. data-prismize | String | Used to indicate the language to be used to highlight the syntax. data-remove-margins | Boolean | Indicates whether or not to remove the margins that are ordinarily found before and/or after the main <pre> tag within the prismized content. data-resize-rate | Integer | Indicates how often (in milliseconds) to try to resize the containing element (IFRAME) based on the rendered syntax highlighted code's height. data-show-language | Boolean | String | If this is a boolean it indicates whether to use the show-language plugin. If this is a string the show-language plugin will be used and the specified string will display as the language for this code block. data-tab-size | Integer | Indicates how many spaces a tab character should resolve to. data-template-path | String | Indicates where to pull all of the Prism.js files from. This supports a form of template variables which must be surrounded with 2 sets of square brackets (eg. [[version]]). This defaults to "https://cdn.jsdelivr.net/npm/prismjs@[[version]]/[[path]]". The following are valid template variables:[[path]] - This will be replaced with the relative path of the files that are needed (eg. theme files, plugin files).[[version]] - This will be replaced with "1.X.X". data-theme | String | Indicates the Prism.js theme that should be used for the syntax highlighted code. You can either supply a path to a CSS theme (you can find more themes here) or you can use one of the following valid theme names:"default""coy""dark""funky""okaidia""solarizedlight""tomorrow""twilight"

Invoking Via JavaScript

Three functions are added to the global scope:

  • prismize() - Can be used on a single block of code or a string which contains code.
  • prismize.listenToActions() - Called to listen to actions for all prismized code.
  • prismizeAll() - Called to execute prismize() on all elements on the page that either have a data-prismize attribute or a prismize class name.

These functions are documented with JSDoc syntax which will help you understand how to use them.