Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/justinribeiro/code-block

A web component that displays colorfully formatted code with Prism.js and LitElement.
https://github.com/justinribeiro/code-block

code-block lit prismjs webcomponent

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

[![npm version](https://badge.fury.io/js/%40justinribeiro%2Fcode-block.svg)](https://badge.fury.io/js/%40justinribeiro%2Fcode-block)

# \

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

![screenshot of code-block](https://user-images.githubusercontent.com/643503/56254054-0ce02600-6074-11e9-9caf-e9dcc25b3ab1.png)

## Features

* Loads [Prism.js](https://prismjs.com/) language definitions on demand via dynamic imports from `node_modules/prismjs/components/`
* Loads Prism.js custom themes
* Built as a web component on [Lit](https://lit.dev/)

## Install

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

Install code-block:

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

After install, import into your project:

```js
import '@justinribeiro/code-block';
```

Finally, use as required:

```html

function helloWorld(say) {
console.log(say);
}

helloWorld('Hi there!');

```

## 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).