Skip to content

Component Reference

This page documents the options accepted and values returned from the <Score> component and getScore() function.

import { Score } from "astro-lilypond";
interface ScoreProps {
content: LilypondScore;
format?: "svg" | "png";
crop?: boolean;
pageLimit?: number;
class?: string;
style?: string;
alt?: string;
}
MyComponent.astro
---
import { Score } from "astro-lilypond";
import bachInvention from "./bach-invention.ly";
---
<Score content={bachInvention} />

Type: LilypondScore

The score’s source text and derived metadata. You get one from:

  • Importing a .ly/.ily/.lilypond file directly.
  • A lilypondLoader() content-collection entry; entry.data is a LilypondScore.

Type: "svg" | "png"
Default: the integration’s defaults.format ("svg" unless configured otherwise)

Output format for the rendered image.

Type: boolean
Default: false

Crops the score to a single tightly-fit image instead of full pages — see cropping.

Type: number

Render only the first n pages. If omitted, all pages render. See limiting rendered pages.

Type: string

Class name(s) applied to the rendered <img> (or <ol>, for multi-page scores). See the styling guide.

Type: string

Inline styles applied directly to the rendered element.

Type: string

Overrides the automatically-derived alt text. Takes precedence over any title/composer found in the .ly file’s \header block. See also: alt text.

import { getScore } from "astro-lilypond";
function getScore(
score: LilypondScore,
options?: GetScoreOptions,
): Promise<GetScoreResult>;

Type: LilypondScore

Same as <Score />’s content above.

Type: GetScoreOptions

Type: "svg" | "png"
Default: the integration’s defaults.format ("svg" unless configured otherwise)

Output format for Score.

Type: boolean
Default: false

Crops Score to a single tightly-fit image instead of returning full pages. See the component guide.

Type: boolean
Default: false

When true, also renders a downloadable PDF of the same score, returned as pdf.

ScoreWithPdf.astro
---
import { getScore } from "astro-lilypond";
import bachInvention from "./bach-invention.ly";
const { Score, pdf, meta } = await getScore(
bachInvention,
{ crop: true, pdf: true }
);
---
<h3>{meta.title}</h3>
<Score />
<a href={pdf.src} download>Download PDF</a>

Type: GetScoreResult

interface GetScoreResult {
Score: AstroComponentFactory;
pages: LilypondPage[];
meta: LilypondMetadata;
raw: string;
pdf?: LilypondPdfResult;
}

Type: AstroComponentFactory

Accepts all the same props as <Score>, except for format and crop; pass those to the options argument of getScore().

Type: LilypondPage[]

interface LilypondPage {
src: string;
width?: number;
height?: number;
}

Every rendered page’s src/width/height, exposed so you can compose your own markup instead of using the markup from Score.

Type: LilypondMetadata

Fields parsed from the score’s \header block(s) — see the LilypondMetadata type below.

Type: string

Your LilyPond source code as a string, exactly as passed to getScore() (including any \version prepended via defaults.version). Use it wherever you need to show the text itself, rather than the rendered image.

Type: LilypondPdfResult | undefined

interface LilypondPdfResult {
src: string;
}

Present only when options.pdf is true.

Fields parsed from the score’s \header block(s) — the shape of meta on getScore() results.

interface LilypondMetadata {
arranger?: string;
composer?: string;
copyright?: string;
dedication?: string;
instrument?: string;
meter?: string;
opus?: string;
piece?: string;
poet?: string;
subsubtitle?: string;
subtitle?: string;
tagline?: string;
title?: string;
// Any other unknown or uncommon fields
[field: string]: string | undefined;
}