# prism-dom

> Prism.js syntax highlighter for HTML strings

Latest version **0.4.0** (published 2020-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install prism-dom
pnpm add prism-dom
yarn add prism-dom
bun add prism-dom
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2020-05-11 |
| First published | 2017-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrew Wei |
| Maintainers | andrewscwei |

## Links

- npm: https://www.npmjs.com/package/prism-dom
- Repository: https://github.com/andrewscwei/prism-dom
- Homepage: https://github.com/andrewscwei/prism-dom#readme
- Issues: https://github.com/andrewscwei/prism-dom/issues
- npm.io page: https://npm.io/package/prism-dom

## Dependencies (4)

- [async](https://npm.io/package/async.md) ^3.1.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [jsdom](https://npm.io/package/jsdom.md) ^15.1.1
- [prismjs](https://npm.io/package/prismjs.md) ^1.17.1

## Recent versions

- 0.4.0 (latest) — 2020-05-11
- 0.3.0 — 2019-09-09
- 0.2.0 — 2017-08-31
- 0.1.0 — 2017-08-30

## README

# Prism DOM ![](https://img.shields.io/maintenance/no/2017) [![](https://img.shields.io/github/license/andrewscwei/prism-dom)](https://github.com/andrewscwei/prism-dom/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/prism-dom.svg)](https://www.npmjs.com/package/prism-dom) [![CircleCI](https://img.shields.io/circleci/build/github/andrewscwei/prism-dom.svg)](https://circleci.com/gh/andrewscwei/prism-dom)

Syntax highlights an entire HTML string using [Prism.js](http://prismjs.com/).

## API

```js
/**
 * Parses an HTML string and syntax highlights all code blocks using Prism.js.
 *
 * @param {String} htmlString - HTML string to process.
 * @param {Object} [options] - Additional options.
 * @param {String} [options.defaultLanguage='markup'] - Fallback language for
 *                                                      code blocks.
 * @param {Boolean} [options.lineNumbers=true] - Specifies whether line numbers
 *                                               should show.
 * @param {Boolean} [options.showLanguage=false] - Specifies whether the
 *                                                 language label should show.
 *
 * @return {Promise<String>} - Promise with the output HTML as the fulfillment
 *                             value.
 */
function prismDOM(htmlString, options)
```

## Usage

```sh
$ npm install prism-dom
```

This module crawls the HTML string for two elements:
1. `<code>` elements with `class` set to `language-<programming_language>`, i.e. `<code class='language-javascript'>`. You can also use `lang-` for short in place of `language`.
2. `<code>` elements whose direct parent element has its `class` set to `language-<programming_language>`, i.e. `<code class='language-javascript'>`. You can also use `lang-` for short in place of `language`.

For a list of supported languages or CSS themes, refer to [Prism.js](http://prismjs.com/).

Example:

```js
const prismDOM = require('prism-dom');

prismDOM(`<some_html>`, {}).then(htmlString => {
  // The output HTML string with all code elements syntax highlighted.
  console.log(htmlString);
});
```

## Disclaimer

This is an experimental project driven by internal requirements.

---
_Source: https://npm.io/package/prism-dom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
