1.2.1 • Published 2 years ago

prismize v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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:

AttributeTypeDescription
data-action-*StringSpecify 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-copyableBoolean | StringIf 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-downloadableBoolean | StringIf 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-downloadableStringThe file name for the file that will be downloaded.
data-info-textStringUsed to show specific text after the language tag but before the buttons in the info bar.
data-info-htmlStringUsed to evaluate HTML that will appear after the language tag but before the buttons in the info bar.
data-languageStringAlternative to data-language. Used to indicate the language to be used to highlight the syntax.
data-match-bracesBooleanIndicates whether to use the match-braces plugin.
data-max-heightIntegerIndicates the maximum height of the containing element (IFRAME) of the syntax highlighted code.
data-number-linesBoolean | IntegerIf 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-placementStringIndicates 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-colorsBooleanIndicates whether to use the inline-color plugin.
data-prismizeStringUsed to indicate the language to be used to highlight the syntax.
data-remove-marginsBooleanIndicates 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-rateIntegerIndicates how often (in milliseconds) to try to resize the containing element (IFRAME) based on the rendered syntax highlighted code's height.
data-show-languageBoolean | StringIf 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-sizeIntegerIndicates how many spaces a tab character should resolve to.
data-template-pathStringIndicates 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-themeStringIndicates 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.

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago