Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@astropub/code

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astropub/code

A lightweight Astro component for syntax highlighting and rendering beautifully formatted code blocks.

  • 0.4.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
339
decreased by-28.03%
Maintainers
1
Weekly downloads
 
Created
Source

Astro Code

Astro Code enables code syntax highlighting and rendering in Astro projects.

NPM Version NPM Downloads

  • Syntax Highlighting: Beautifully highlight code blocks in various programming languages.
    • Syntax highlighting for popular languages like JavaScript, TypeScript, HTML, CSS, and more.
  • Lightweight: Minimal dependency footprint for faster builds.
    • A fully optimized ESM version of Prism for modern web apps.
  • Customizable: Easily adapt the component to your project's needs.
    • Customize styles and themes using your own CSS.

Installation

Install the component via npm:

npm install @astropub/code

Import and use the component in your Astro files:

---
import Code from "@astropub/code"
---
<Code lang="js" code="const str = 'string'">

Usage

To display a syntax-highlighted code block:

---
import Code from "@astropub/code"
---
<Code lang="html" code="<h1>Hello, Astro!</h1>"></Code>
Multi-Line Code

Pass an array of strings to the code prop:

---
import Code from "@astropub/code"
---
<Code lang="css" code={[
  "body {",
  "  margin: 0;",
  "}"
]}></Code>

Supported Languages

Out of the box, Astro Code supports these languages via Prism.js:

LanguageType Value
Scriptingjs jsx ts tsx
Contenthtml json svg xml
Stylingcss
Shellsh

API Reference

AtttributeTypeDescription
codestring string[]Code to render.
langstringLanguage of highlighting.

Utility Usage

The highlightText method can be used to highlight a given plain text string with a language.

import { highlightText } from "@astropub/code/highlight"

export const usage = () => {
  highlightText("const a = true", "js)
}

The highlightTextNode method can be used to highlight a Text node with a language.

import { highlightTextNode } from "@astropub/code/highlight"

export const usage = (node: Text) => {
  highlightText(node, "js)
}

License

Licensed under the MIT-0 License.


Enjoy!

Keywords

FAQs

Package last updated on 12 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc