CodeHighlighterCodeHighlighter is an attribute directive to highlight code blocks using PrismJS

CodeHighlighter - 图1

Documentation

PrismJS

  1. npm install prismjs --save
  2.  

Include the javascript and a theme css from Prism. Example for angular.json configuration of a CLI project would be as follows. Refer to the PrismJS documentation for the list of available languages.

  1. "styles": [
  2. "./node_modules/prism/themes/prism.css",
  3. //...
  4. ],
  5. "scripts": [
  6. "node_modules/prismjs/prism.js",
  7. //...
  8. ]
  9.  

Import

  1. import {CodeHighlighterModule} from 'primeng/codehighlighter';
  2.  

Getting Started

CodeHighlighter is applied to a code element with [pCode] directive. The <code> should have a style class having language- prefix to specify the language to highlight. See Prismjs docs for the list of available languages. An example block with css code would be as follows.

  1. <pre>
  2. <code class="language-css" pCode>
  3. .ui-datatable table {
  4. border-collapse:collapse;
  5. width: 100%;
  6. table-layout: fixed;
  7. }
  8. </code>
  9. </pre>
  10.  

Dependencies

Prismjs

Source

View on GitHub