astro-lilypond 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/LilyPond.astro +13 -11
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/rehype-plugin.d.ts +3 -1
- package/dist/rehype-plugin.d.ts.map +1 -1
- package/dist/rehype-plugin.js +11 -5
- package/dist/rehype-plugin.js.map +1 -1
- package/dist/remark-plugin.d.ts.map +1 -1
- package/dist/remark-plugin.js +11 -5
- package/dist/remark-plugin.js.map +1 -1
- package/dist/render.d.ts +12 -4
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +46 -24
- package/dist/render.js.map +1 -1
- package/dist/satteri-plugin.d.ts.map +1 -1
- package/dist/satteri-plugin.js +11 -5
- package/dist/satteri-plugin.js.map +1 -1
- package/dist/util.d.ts +8 -10
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +13 -6
- package/dist/util.js.map +1 -1
- package/package.json +17 -10
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
---
|
|
2
2
|
const HTML_ENTITIES: Record<string, string> = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"&": "&",
|
|
4
|
+
"<": "<",
|
|
5
|
+
">": ">",
|
|
6
|
+
'"': """,
|
|
7
|
+
"'": "'",
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
function escapeHtml(text: unknown): string {
|
|
11
|
-
|
|
11
|
+
return String(text).replace(/[&<>"']/g, (c) => HTML_ENTITIES[c] ?? c);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
content: string;
|
|
16
|
+
class?: string | undefined;
|
|
17
|
+
style?: string | undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const { content, class: className, style } = Astro.props;
|
|
21
21
|
|
|
22
22
|
let html = content;
|
|
23
|
-
if (className)
|
|
24
|
-
|
|
23
|
+
if (className)
|
|
24
|
+
html = html.replace('class="lilypond"', `class="lilypond ${className}"`);
|
|
25
|
+
if (style)
|
|
26
|
+
html = html.replace(/<(svg|img)\b/, `<$1 style="${escapeHtml(style)}"`);
|
|
25
27
|
---
|
|
26
28
|
|
|
27
29
|
<Fragment set:html={html} />
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
|
-
import type { LilypondPluginOptions
|
|
3
|
-
export type { OutputFormat };
|
|
2
|
+
import type { LilypondPluginOptions } from "./util.js";
|
|
4
3
|
export type { LilypondPluginOptions };
|
|
5
4
|
export interface LilypondOptions extends LilypondPluginOptions {
|
|
6
5
|
/**
|
|
@@ -14,10 +13,13 @@ export interface LilypondOptions extends LilypondPluginOptions {
|
|
|
14
13
|
* Output format. Defaults to `"svg"`.
|
|
15
14
|
*
|
|
16
15
|
* - `"svg"` — inline SVG embedded directly in the HTML (default)
|
|
17
|
-
* - `"png"` — `<img>` element with a base64 data URI
|
|
18
|
-
* - `{ type: "png", resolution: number }` — PNG at a specific DPI
|
|
16
|
+
* - `"png"` — `<img>` element with a base64 data URI
|
|
19
17
|
*/
|
|
20
|
-
format?:
|
|
18
|
+
format?: "svg" | "png";
|
|
19
|
+
/**
|
|
20
|
+
* Resolution in DPI (only applies to PNG). Defaults to `144`.
|
|
21
|
+
*/
|
|
22
|
+
resolution?: number;
|
|
21
23
|
/**
|
|
22
24
|
* Crop the output tightly to the content bounding box. Defaults to `true`.
|
|
23
25
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAS9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAS9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAMvD,YAAY,EAAE,qBAAqB,EAAE,CAAC;AAEtC,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC7D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAqBD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,gBAAgB,CAiGhF"}
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { promisify } from "util";
|
|
|
3
3
|
import { remarkLilypondPlugin } from "./remark-plugin.js";
|
|
4
4
|
import { rehypeLilypondPlugin } from "./rehype-plugin.js";
|
|
5
5
|
import { satteriLilypondPlugin } from "./satteri-plugin.js";
|
|
6
|
-
import { render } from "./render.js";
|
|
7
|
-
import { prependVersion, renderToHtml
|
|
6
|
+
import { defaultOptions, render } from "./render.js";
|
|
7
|
+
import { includePathsFor, prependVersion, renderToHtml } from "./util.js";
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
9
|
const LY_EXTENSIONS = [".ly", ".lilypond", ".ily"];
|
|
10
10
|
function lyFilePlugin(options) {
|
|
@@ -15,8 +15,13 @@ function lyFilePlugin(options) {
|
|
|
15
15
|
if (!LY_EXTENSIONS.some(ext => id.endsWith(ext)))
|
|
16
16
|
return;
|
|
17
17
|
const src = options.version ? prependVersion(source, options.version) : source;
|
|
18
|
-
const
|
|
19
|
-
const buf = await render(src, {
|
|
18
|
+
const format = options.format ?? defaultOptions.format;
|
|
19
|
+
const buf = await render(src, {
|
|
20
|
+
format,
|
|
21
|
+
resolution: options.resolution,
|
|
22
|
+
crop: options.crop,
|
|
23
|
+
includePaths: includePathsFor(id),
|
|
24
|
+
});
|
|
20
25
|
return { code: `export default ${JSON.stringify(renderToHtml(buf, format))}` };
|
|
21
26
|
},
|
|
22
27
|
};
|
|
@@ -48,7 +53,7 @@ export default function lilypond(options = {}) {
|
|
|
48
53
|
...existingOptions,
|
|
49
54
|
mdastPlugins: [
|
|
50
55
|
...(existingOptions.mdastPlugins ?? []),
|
|
51
|
-
satteriLilypondPlugin(
|
|
56
|
+
satteriLilypondPlugin(options),
|
|
52
57
|
],
|
|
53
58
|
}),
|
|
54
59
|
},
|
|
@@ -69,11 +74,11 @@ export default function lilypond(options = {}) {
|
|
|
69
74
|
...existingOptions,
|
|
70
75
|
remarkPlugins: [
|
|
71
76
|
...(existingOptions.remarkPlugins ?? []),
|
|
72
|
-
[remarkLilypondPlugin,
|
|
77
|
+
[remarkLilypondPlugin, options],
|
|
73
78
|
],
|
|
74
79
|
rehypePlugins: [
|
|
75
80
|
...(existingOptions.rehypePlugins ?? []),
|
|
76
|
-
[rehypeLilypondPlugin,
|
|
81
|
+
[rehypeLilypondPlugin, options],
|
|
77
82
|
],
|
|
78
83
|
}),
|
|
79
84
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAA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M,GAAG,CAC5D,CAAC;YACH,CAAC;YAED,mBAAmB,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;gBACxC,WAAW,CAAC;oBACX,QAAQ,EAAE,eAAe;oBACzB,OAAO,EAAE,aAAa;yBACpB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,GAAG,uDAAuD,CAAC;yBAC1F,IAAI,CAAC,IAAI,CAAC;iBACZ,CAAC,CAAC;YACJ,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
|
package/dist/rehype-plugin.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { LilypondPluginOptions } from "./util.js";
|
|
2
2
|
export type RehypePluginOptions = LilypondPluginOptions;
|
|
3
|
-
export declare function rehypeLilypondPlugin(options?: RehypePluginOptions): (tree: any
|
|
3
|
+
export declare function rehypeLilypondPlugin(options?: RehypePluginOptions): (tree: any, file?: {
|
|
4
|
+
path?: string;
|
|
5
|
+
}) => Promise<void>;
|
|
4
6
|
//# sourceMappingURL=rehype-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-plugin.d.ts","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAKxD,wBAAgB,oBAAoB,CACnC,OAAO,GAAE,mBAAwB,GAC/B,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"rehype-plugin.d.ts","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAKxD,wBAAgB,oBAAoB,CACnC,OAAO,GAAE,mBAAwB,GAC/B,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAqDxD"}
|
package/dist/rehype-plugin.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
import { render } from "./render.js";
|
|
3
|
-
import { isLilypondLang, prependVersion, renderToHtml
|
|
2
|
+
import { defaultOptions, render } from "./render.js";
|
|
3
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml } from "./util.js";
|
|
4
4
|
// Typed loosely so it's assignable to both RehypePlugin and the unified
|
|
5
5
|
// Plugin generic regardless of which @types/hast version the host project pins.
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
7
|
export function rehypeLilypondPlugin(options = {}) {
|
|
8
|
-
return async (tree) => {
|
|
8
|
+
return async (tree, file) => {
|
|
9
9
|
const promises = [];
|
|
10
|
+
const includePaths = includePathsFor(file?.path);
|
|
10
11
|
visit(tree, "element", (node, index, parent) => {
|
|
11
12
|
if (node.tagName !== "pre" ||
|
|
12
13
|
node.children?.length !== 1 ||
|
|
@@ -29,8 +30,13 @@ export function rehypeLilypondPlugin(options = {}) {
|
|
|
29
30
|
const source = options.version
|
|
30
31
|
? prependVersion(raw, options.version)
|
|
31
32
|
: raw;
|
|
32
|
-
const
|
|
33
|
-
const promise = render(source, {
|
|
33
|
+
const format = options.format ?? defaultOptions.format;
|
|
34
|
+
const promise = render(source, {
|
|
35
|
+
format,
|
|
36
|
+
resolution: options.resolution,
|
|
37
|
+
crop: options.crop,
|
|
38
|
+
includePaths,
|
|
39
|
+
})
|
|
34
40
|
.then((buf) => {
|
|
35
41
|
const rawNode = {
|
|
36
42
|
type: "raw",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-plugin.js","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-plugin.d.ts","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAExD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"remark-plugin.d.ts","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAExD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAkCrE,CAAC"}
|
package/dist/remark-plugin.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
import { render } from "./render.js";
|
|
3
|
-
import { isLilypondLang, prependVersion, renderToHtml
|
|
2
|
+
import { defaultOptions, render } from "./render.js";
|
|
3
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml } from "./util.js";
|
|
4
4
|
export const remarkLilypondPlugin = (options = {}) => {
|
|
5
|
-
return async (tree) => {
|
|
5
|
+
return async (tree, file) => {
|
|
6
6
|
const promises = [];
|
|
7
|
+
const includePaths = includePathsFor(file?.path);
|
|
7
8
|
visit(tree, "code", (node, index, parent) => {
|
|
8
9
|
if (!isLilypondLang(node.lang) || index === undefined || !parent)
|
|
9
10
|
return;
|
|
10
11
|
const source = options.version
|
|
11
12
|
? prependVersion(node.value, options.version)
|
|
12
13
|
: node.value;
|
|
13
|
-
const
|
|
14
|
-
const promise = render(source, {
|
|
14
|
+
const format = options.format ?? defaultOptions.format;
|
|
15
|
+
const promise = render(source, {
|
|
16
|
+
format,
|
|
17
|
+
resolution: options.resolution,
|
|
18
|
+
crop: options.crop,
|
|
19
|
+
includePaths,
|
|
20
|
+
})
|
|
15
21
|
.then((buf) => {
|
|
16
22
|
const htmlNode = {
|
|
17
23
|
type: "html",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-plugin.js","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"remark-plugin.js","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAK1F,MAAM,CAAC,MAAM,oBAAoB,GAAyC,CACzE,OAAO,GAAG,EAAE,EACX,EAAE;IACH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAEjD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM;gBAAE,OAAO;YAEzE,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO;gBAC7B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;gBAC7C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACd,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC;YAEvD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE;gBAC9B,MAAM;gBACN,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY;aACZ,CAAC;iBACA,IAAI,CAAC,CAAC,GAAG,EAAQ,EAAE;gBACnB,MAAM,QAAQ,GAAS;oBACtB,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC;iBAChC,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;YACnC,CAAC,CAAC,CAAC;YAEJ,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC;AACH,CAAC,CAAC"}
|
package/dist/render.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
declare const FORMATS: readonly ["png", "svg"];
|
|
2
|
+
export type Format = (typeof FORMATS)[number];
|
|
2
3
|
export interface RenderOptions {
|
|
3
4
|
/** Output format. Defaults to `"svg"`. */
|
|
4
5
|
format?: Format;
|
|
@@ -7,11 +8,18 @@ export interface RenderOptions {
|
|
|
7
8
|
/** Path to the `lilypond` binary. Defaults to `"lilypond"`. */
|
|
8
9
|
binaryPath?: string;
|
|
9
10
|
/**
|
|
10
|
-
* Crop the output
|
|
11
|
-
*
|
|
11
|
+
* Crop the output tightly to the content bounding box.
|
|
12
|
+
* Disable if full-page renders are preferred.
|
|
13
|
+
* Defaults to `true`.
|
|
12
14
|
*/
|
|
13
15
|
crop?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Extra directories LilyPond should search for `\include`d files.
|
|
18
|
+
* Typically the directory containing the source `.ly`/Markdown file.
|
|
19
|
+
*/
|
|
20
|
+
includePaths?: string[];
|
|
14
21
|
}
|
|
15
|
-
export declare const defaultOptions: Required<RenderOptions
|
|
22
|
+
export declare const defaultOptions: Required<Omit<RenderOptions, "includePaths">>;
|
|
16
23
|
export declare function render(source: string, options?: RenderOptions): Promise<Buffer>;
|
|
24
|
+
export {};
|
|
17
25
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAQA,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,OAAO,YAAI,KAAK,EAAE,KAAK,CAAU,CAAC;AAExC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC7B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAKxE,CAAC;AAEF,wBAAsB,MAAM,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,MAAM,CAAC,CAiEjB"}
|
package/dist/render.js
CHANGED
|
@@ -4,14 +4,7 @@ import { join } from "path";
|
|
|
4
4
|
import { tmpdir } from "os";
|
|
5
5
|
import { promisify } from "util";
|
|
6
6
|
const execFileAsync = promisify(execFile);
|
|
7
|
-
const
|
|
8
|
-
midi: null,
|
|
9
|
-
pdf: "--pdf",
|
|
10
|
-
png: "--png",
|
|
11
|
-
ps: "--ps",
|
|
12
|
-
svg: "--svg",
|
|
13
|
-
eps: "--eps",
|
|
14
|
-
};
|
|
7
|
+
const FORMATS = ["png", "svg"];
|
|
15
8
|
export const defaultOptions = {
|
|
16
9
|
format: "svg",
|
|
17
10
|
resolution: 144,
|
|
@@ -19,10 +12,9 @@ export const defaultOptions = {
|
|
|
19
12
|
crop: true,
|
|
20
13
|
};
|
|
21
14
|
export async function render(source, options = {}) {
|
|
22
|
-
const { format = defaultOptions.format, resolution = defaultOptions.resolution, binaryPath = defaultOptions.binaryPath, crop = defaultOptions.crop, } = options;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new Error(`${opts.format} is not a supported format`);
|
|
15
|
+
const { format = defaultOptions.format, resolution = defaultOptions.resolution, binaryPath = defaultOptions.binaryPath, crop = defaultOptions.crop, includePaths = [], } = options;
|
|
16
|
+
if (!FORMATS.includes(format)) {
|
|
17
|
+
throw new Error(`${format} is not a supported format`);
|
|
26
18
|
}
|
|
27
19
|
const dir = await mkdtemp(join(tmpdir(), "astro-lilypond-"));
|
|
28
20
|
const inputPath = join(dir, "input.ly");
|
|
@@ -30,19 +22,43 @@ export async function render(source, options = {}) {
|
|
|
30
22
|
try {
|
|
31
23
|
await writeFile(inputPath, source, "utf8");
|
|
32
24
|
const args = [
|
|
33
|
-
|
|
34
|
-
`--
|
|
25
|
+
// Render the correct format
|
|
26
|
+
`--format=${format}`,
|
|
27
|
+
// Define defaults — these can be overridden with the appropriate flags
|
|
28
|
+
// inside of individual .ly files
|
|
29
|
+
// Disable point-and-click behavior on SVGs when clicking noteheads
|
|
35
30
|
"--define-default=no-point-and-click",
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
// Use the `cairo` backend for graphics rendering; faster than the default `ps` backend
|
|
32
|
+
// https://lilypond.org/doc/v2.26/Documentation/usage/advanced-command_002dline-options-for-lilypond
|
|
33
|
+
"--define-default=backend=cairo",
|
|
34
|
+
// Resolution for generating PNGs (set in DPI)
|
|
35
|
+
`--define-default=resolution=${resolution}`,
|
|
36
|
+
// Set cropping
|
|
37
|
+
`--define-default=crop=${crop ? "#t" : "#f"}`,
|
|
38
|
+
// If the LilyPond file imports from others via \include, make sure those files are included
|
|
39
|
+
...includePaths.map((p) => `--include=${p}`),
|
|
38
40
|
"--output",
|
|
39
41
|
outputBase,
|
|
40
42
|
inputPath,
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
+
];
|
|
44
|
+
// LilyPond writes its progress log, and any warnings/errors, to stderr
|
|
45
|
+
// even on success — surface it in the build output so it's visible,
|
|
46
|
+
// but let the exit code (not stderr content) decide pass/fail.
|
|
47
|
+
let stderr;
|
|
48
|
+
try {
|
|
49
|
+
({ stderr } = await execFileAsync(binaryPath, args));
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
const errStderr = err && typeof err === "object" && "stderr" in err
|
|
53
|
+
? String(err.stderr)
|
|
54
|
+
: undefined;
|
|
55
|
+
if (errStderr)
|
|
56
|
+
process.stderr.write(errStderr);
|
|
57
|
+
throw new Error(errStderr || (err instanceof Error ? err.message : String(err)));
|
|
58
|
+
}
|
|
43
59
|
if (stderr)
|
|
44
|
-
|
|
45
|
-
return await readOutputFile(outputBase,
|
|
60
|
+
process.stderr.write(stderr);
|
|
61
|
+
return await readOutputFile(outputBase, format, crop);
|
|
46
62
|
}
|
|
47
63
|
finally {
|
|
48
64
|
await rm(dir, { recursive: true, force: true });
|
|
@@ -54,16 +70,22 @@ async function readOutputFile(base, format, crop) {
|
|
|
54
70
|
try {
|
|
55
71
|
return await readFile(`${base}.cropped.${format}`);
|
|
56
72
|
}
|
|
57
|
-
catch {
|
|
58
|
-
|
|
73
|
+
catch (err) {
|
|
74
|
+
throw new Error(`expected cropped output at ${base}.cropped.${format} but it was not found: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
|
-
// Regular output: single page → <base>.<format>, multi-page →
|
|
77
|
+
// Regular output: single page → <base>.<format>, multi-page →
|
|
78
|
+
// <base>-1.<format> (svg) or <base>-page1.<format> (png).
|
|
62
79
|
try {
|
|
63
80
|
return await readFile(`${base}.${format}`);
|
|
64
81
|
}
|
|
65
82
|
catch {
|
|
66
|
-
|
|
83
|
+
try {
|
|
84
|
+
return await readFile(`${base}-1.${format}`);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return await readFile(`${base}-page1.${format}`);
|
|
88
|
+
}
|
|
67
89
|
}
|
|
68
90
|
}
|
|
69
91
|
//# sourceMappingURL=render.js.map
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eA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,oBAAoB,GAAG,qBAAqB,CAAC;AAEzD,wBAAgB,qBAAqB,CACpC,OAAO,GAAE,oBAAyB,GAChC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"satteri-plugin.d.ts","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,qBAAqB,EAErB,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAEzD,wBAAgB,qBAAqB,CACpC,OAAO,GAAE,oBAAyB,GAChC,qBAAqB,CAyBvB"}
|
package/dist/satteri-plugin.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { render } from "./render.js";
|
|
2
|
-
import { isLilypondLang, prependVersion, renderToHtml
|
|
1
|
+
import { defaultOptions, render } from "./render.js";
|
|
2
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml } from "./util.js";
|
|
3
3
|
export function satteriLilypondPlugin(options = {}) {
|
|
4
4
|
return {
|
|
5
5
|
name: "astro-lilypond",
|
|
6
6
|
// Returning an mdast Html node (type: 'html') emits the value verbatim.
|
|
7
7
|
// Sätteri's { rawHtml } escape hatch applies MDX brace-escaping which
|
|
8
8
|
// would corrupt SVG content, so we use the plain html node form instead.
|
|
9
|
-
async code(node,
|
|
9
|
+
async code(node, ctx) {
|
|
10
10
|
if (!isLilypondLang(node.lang))
|
|
11
11
|
return undefined;
|
|
12
12
|
const source = options.version
|
|
13
13
|
? prependVersion(node.value, options.version)
|
|
14
14
|
: node.value;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const format = options.format ?? defaultOptions.format;
|
|
16
|
+
const includePaths = includePathsFor(ctx.fileURL);
|
|
17
|
+
const buf = await render(source, {
|
|
18
|
+
format,
|
|
19
|
+
resolution: options.resolution,
|
|
20
|
+
crop: options.crop,
|
|
21
|
+
includePaths,
|
|
22
|
+
});
|
|
17
23
|
return { type: "html", value: renderToHtml(buf, format) };
|
|
18
24
|
},
|
|
19
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satteri-plugin.js","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"satteri-plugin.js","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAK1F,MAAM,UAAU,qBAAqB,CACpC,OAAO,GAAyB,EAAE;IAElC,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,wEAAwE;QACxE,sEAAsE;QACtE,yEAAyE;QACzE,KAAK,CAAC,IAAI,CACT,IAAoB,EACpB,GAAwB;YAExB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,SAAS,CAAC;YACjD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO;gBAC7B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;gBAC7C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACd,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC;YACvD,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE;gBAChC,MAAM;gBACN,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY;aACZ,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QAC3D,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
export type OutputFormat = "svg" | "png" | {
|
|
2
|
-
type: "png";
|
|
3
|
-
resolution: number;
|
|
4
|
-
};
|
|
5
1
|
export interface LilypondPluginOptions {
|
|
6
2
|
version?: string;
|
|
7
|
-
format?:
|
|
3
|
+
format?: "svg" | "png";
|
|
4
|
+
resolution?: number;
|
|
8
5
|
crop?: boolean;
|
|
9
6
|
}
|
|
10
7
|
/** Returns true for the fenced-block language identifiers that trigger SVG rendering. */
|
|
11
8
|
export declare function isLilypondLang(lang: string | null | undefined): boolean;
|
|
12
|
-
/** Normalises an OutputFormat value into a plain format string and optional resolution (DPI). */
|
|
13
|
-
export declare function resolveFormat(format: OutputFormat): {
|
|
14
|
-
format: "svg" | "png";
|
|
15
|
-
resolution?: number;
|
|
16
|
-
};
|
|
17
9
|
/**
|
|
18
10
|
* If `version` is provided and the source doesn't already declare `\version`,
|
|
19
11
|
* prepend `\version "X.X.X"` so users don't need to write it manually.
|
|
20
12
|
*/
|
|
21
13
|
export declare function prependVersion(source: string, version: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Derives `render()`'s `includePaths` from the source file's path or URL, so
|
|
16
|
+
* `\include`d sibling files resolve even though rendering happens in a temp
|
|
17
|
+
* directory. Returns `[]` when the source location is unknown.
|
|
18
|
+
*/
|
|
19
|
+
export declare function includePathsFor(source: string | URL | null | undefined): string[];
|
|
22
20
|
/** Converts a rendered LilyPond buffer to an HTML string suitable for inline embedding. */
|
|
23
21
|
export declare function renderToHtml(buf: Buffer, format: "svg" | "png"): string;
|
|
24
22
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAIjF;AAED,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAMvE"}
|
package/dist/util.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import { dirname } from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
1
3
|
/** Returns true for the fenced-block language identifiers that trigger SVG rendering. */
|
|
2
4
|
export function isLilypondLang(lang) {
|
|
3
5
|
return lang === "lilypond" || lang === "ly" || lang === "ily";
|
|
4
6
|
}
|
|
5
|
-
/** Normalises an OutputFormat value into a plain format string and optional resolution (DPI). */
|
|
6
|
-
export function resolveFormat(format) {
|
|
7
|
-
if (typeof format === "string")
|
|
8
|
-
return { format };
|
|
9
|
-
return { format: format.type, resolution: format.resolution };
|
|
10
|
-
}
|
|
11
7
|
/**
|
|
12
8
|
* If `version` is provided and the source doesn't already declare `\version`,
|
|
13
9
|
* prepend `\version "X.X.X"` so users don't need to write it manually.
|
|
@@ -17,6 +13,17 @@ export function prependVersion(source, version) {
|
|
|
17
13
|
return source;
|
|
18
14
|
return `\\version "${version}"\n${source}`;
|
|
19
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Derives `render()`'s `includePaths` from the source file's path or URL, so
|
|
18
|
+
* `\include`d sibling files resolve even though rendering happens in a temp
|
|
19
|
+
* directory. Returns `[]` when the source location is unknown.
|
|
20
|
+
*/
|
|
21
|
+
export function includePathsFor(source) {
|
|
22
|
+
if (!source)
|
|
23
|
+
return [];
|
|
24
|
+
const path = typeof source === "string" ? source : fileURLToPath(source);
|
|
25
|
+
return [dirname(path)];
|
|
26
|
+
}
|
|
20
27
|
/** Converts a rendered LilyPond buffer to an HTML string suitable for inline embedding. */
|
|
21
28
|
export function renderToHtml(buf, format) {
|
|
22
29
|
if (format === "png") {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AASpC,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAAC,IAA+B;IAC7D,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,OAAe;IAC7D,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,OAAO,cAAc,OAAO,MAAM,MAAM,EAAE,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuC;IACtE,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,MAAqB;IAC9D,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,OAAO,oDAAoD,GAAG,4BAA4B,CAAC;IAC5F,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;AACzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-lilypond",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "An Astro integration for rendering Lilypond
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "An Astro integration for rendering Lilypond markup to music notation.",
|
|
5
|
+
"homepage": "https://lilypond.ky.fyi",
|
|
6
|
+
"author": "Ky Decker",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/kydecker/astro-lilypond"
|
|
11
|
+
},
|
|
5
12
|
"type": "module",
|
|
6
13
|
"main": "./dist/index.js",
|
|
7
14
|
"types": "./dist/index.d.ts",
|
|
@@ -24,15 +31,14 @@
|
|
|
24
31
|
"images",
|
|
25
32
|
"lilypond",
|
|
26
33
|
"markdown",
|
|
34
|
+
"media",
|
|
27
35
|
"music",
|
|
28
|
-
"
|
|
36
|
+
"renderer",
|
|
37
|
+
"score",
|
|
38
|
+
"tooling",
|
|
39
|
+
"withastro",
|
|
40
|
+
"utils"
|
|
29
41
|
],
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "https://github.com/kydecker/astro-lilypond"
|
|
33
|
-
},
|
|
34
|
-
"author": "Ky Decker",
|
|
35
|
-
"license": "MIT",
|
|
36
42
|
"peerDependencies": {
|
|
37
43
|
"astro": ">=7.0.0"
|
|
38
44
|
},
|
|
@@ -53,6 +59,7 @@
|
|
|
53
59
|
},
|
|
54
60
|
"scripts": {
|
|
55
61
|
"build": "tsc --project tsconfig.json",
|
|
56
|
-
"test": "vitest"
|
|
62
|
+
"test": "vitest --project unit",
|
|
63
|
+
"test:integration": "vitest run --project integration"
|
|
57
64
|
}
|
|
58
65
|
}
|