0.35.3 • Published 7 days ago

expressive-code v0.35.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

expressive-code NPM version NPM downloads

A framework-agnostic wrapper package that provides convenient access to the key packages of Expressive Code, an engine for presenting source code on the web.

Instead of having to install and manage multiple Expressive Code packages separately, this package includes both the core engine and all default plugins as dependencies and exports them.

Included packages:

When should I use this?

Using this package directly is only recommended for advanced use cases, e.g. to create integrations of Expressive Code into other tools and frameworks.

If you just want to render code blocks on your website, you should use one of the higher-level packages instead, e.g. astro-expressive-code or rehype-expressive-code for code blocks in markdown / MDX documents.

Documentation

Read the Expressive Code docs to learn more about the features provided by Expressive Code.

Installation

npm install expressive-code

Usage example

import { ExpressiveCode, ExpressiveCodeConfig } from 'expressive-code'
import { toHtml } from 'expressive-code/hast'

const ec = new ExpressiveCode()

// Get base styles that should be included on the page
// (they are independent of the rendered code blocks)
const baseStyles = await ec.getBaseStyles()

// Render some example code to AST
const { renderedGroupAst, styles } = await ec.render({
  code: 'console.log("Hello world!")',
  language: 'js',
  meta: '',
})

// Convert the rendered AST to HTML
let htmlContent = toHtml(renderedGroupAst)

// Collect styles and add them before the HTML content
const stylesToPrepend: string[] = []
stylesToPrepend.push(baseStyles)
stylesToPrepend.push(...styles)
if (stylesToPrepend.length) {
  htmlContent = `<style>${[...stylesToPrepend].join('')}</style>${htmlContent}`
}

// Output HTML to the console
console.log(htmlContent)
0.35.3

7 days ago

0.35.2

21 days ago

0.35.1

22 days ago

0.34.2

24 days ago

0.35.0

23 days ago

0.34.1

1 month ago

0.34.0

1 month ago

0.33.5

2 months ago

0.33.4

2 months ago

0.33.3

2 months ago

0.33.2

3 months ago

0.33.1

3 months ago

0.33.0

3 months ago

0.32.4

3 months ago

0.32.3

3 months ago

0.32.2

4 months ago

0.32.1

4 months ago

0.32.0

4 months ago

0.31.0

4 months ago

0.30.2

4 months ago

0.30.1

5 months ago

0.30.0

5 months ago

0.29.4

5 months ago

0.29.0

6 months ago

0.27.1

6 months ago

0.27.0

6 months ago

0.29.3

5 months ago

0.29.2

5 months ago

0.29.1

6 months ago

0.28.1

6 months ago

0.28.0

6 months ago

0.28.2

6 months ago

0.26.2

7 months ago

0.26.1

8 months ago

0.26.0

8 months ago

0.25.0

8 months ago

0.24.0

8 months ago

0.23.0

8 months ago

0.21.0

9 months ago

0.22.2

9 months ago

0.22.1

9 months ago

0.22.0

9 months ago

0.8.4

10 months ago

0.20.0

9 months ago

0.19.0

10 months ago

0.18.1

10 months ago

0.19.1

9 months ago

0.19.2

9 months ago

0.11.0

10 months ago

0.12.0

10 months ago

0.13.0

10 months ago

0.12.1

10 months ago

0.14.0

10 months ago

0.12.2

10 months ago

0.15.0

10 months ago

0.16.0

10 months ago

0.17.0

10 months ago

0.18.0

10 months ago

0.10.0

10 months ago

0.9.0

10 months ago

0.8.1

10 months ago

0.8.0

10 months ago

0.8.3

10 months ago

0.9.1

10 months ago

0.8.2

10 months ago

0.6.0

11 months ago

0.5.0

12 months ago

0.4.2

12 months ago

0.3.0

12 months ago

0.2.1

12 months ago

0.2.0

12 months ago

0.4.1

12 months ago

0.4.0

12 months ago

0.1.0

1 year ago