@justinribeiro/code-block

2.0.0 • Public • Published

npm version

<code-block>

A web component that displays colorfully formatted code with Prism.js and Lit.

screenshot of code-block

Features

  • Loads Prism.js language definitions on demand via dynamic imports from node_modules/prismjs/components/
  • Loads Prism.js custom themes
  • Built as a web component on Lit

Install

This web component is built with ES modules in mind and is available on NPM:

Install code-block:

npm i @justinribeiro/code-block
# or
yarn add @justinribeiro/code-block

After install, import into your project:

import '@justinribeiro/code-block';

Finally, use as required:

<code-block language="javascript">
function helloWorld(say) {
  console.log(say);
}

helloWorld('Hi there!');
</code-block>

Attributes

The web component allows certain attributes to be give a little additional flexibility.

Name Description Default
language Code language you wish to utilize from Prism clike
theme Path to Prism CSS theme file /node_modules/prismjs/themes/prism.css

Building

If you want the ability to load the full spectrum of languages that Prism supports, you'll want to make sure your build script includes the /node_modules/prismjs/**, as there are many many language resources (and you don't want them all in your bundle, utilize the dynamic loading).

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    1
  • 1.0.0
    8
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i @justinribeiro/code-block

Weekly Downloads

5

Version

2.0.0

License

MIT

Unpacked Size

8.69 kB

Total Files

7

Last publish

Collaborators

  • justinribeiro