enarratio-astro 0.4.3 → 0.4.4
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/CHANGELOG.md +7 -0
- package/dist/figure.js +12 -2
- package/package.json +1 -1
- package/src/figure.ts +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ every such change is listed here.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.4] - 2026-11-07
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Escapes the "could not be drawn" note itself instead of using Enarratio's `escapeHtml`, which Enarratio 0.9.0 stops exporting.
|
|
15
|
+
Output is unchanged, and the package works with Enarratio 0.7.3 and 0.9.0 alike.
|
|
16
|
+
|
|
10
17
|
## [0.4.3] - 2026-11-07
|
|
11
18
|
|
|
12
19
|
### Changed
|
package/dist/figure.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
const ESCAPES = {
|
|
2
|
+
"&": "&",
|
|
3
|
+
"<": "<",
|
|
4
|
+
">": ">",
|
|
5
|
+
'"': """,
|
|
6
|
+
"'": "'",
|
|
7
|
+
};
|
|
8
|
+
/** Escapes text for HTML. Local because Enarratio no longer exports its own (0.9.0). */
|
|
9
|
+
function escapeText(value) {
|
|
10
|
+
return value.replace(/[&<>"']/g, (ch) => ESCAPES[ch] ?? ch);
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
13
|
* The markup that goes on the page for a drawn chart, or for one that could not be drawn: the
|
|
4
14
|
* chart in a wrapper (marked when it is interactive), or a note saying why.
|
|
5
15
|
*/
|
|
6
16
|
export function chartMarkup(result, interactive) {
|
|
7
17
|
if (!result.ok) {
|
|
8
|
-
return `<p class="enarratio-chart-error" role="note">This chart could not be drawn. ${
|
|
18
|
+
return `<p class="enarratio-chart-error" role="note">This chart could not be drawn. ${escapeText(result.error)}</p>`;
|
|
9
19
|
}
|
|
10
20
|
const mark = interactive ? " data-enarratio-interactive-chart" : "";
|
|
11
21
|
return `<div class="enarratio-chart"${mark}>${result.html}</div>`;
|
package/package.json
CHANGED
package/src/figure.ts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { escapeHtml } from "enarratio";
|
|
2
1
|
import type { ChartResult } from "./chart.js";
|
|
3
2
|
|
|
3
|
+
const ESCAPES: Readonly<Record<string, string>> = {
|
|
4
|
+
"&": "&",
|
|
5
|
+
"<": "<",
|
|
6
|
+
">": ">",
|
|
7
|
+
'"': """,
|
|
8
|
+
"'": "'",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Escapes text for HTML. Local because Enarratio no longer exports its own (0.9.0). */
|
|
12
|
+
function escapeText(value: string): string {
|
|
13
|
+
return value.replace(/[&<>"']/g, (ch) => ESCAPES[ch] ?? ch);
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
/**
|
|
5
17
|
* The markup that goes on the page for a drawn chart, or for one that could not be drawn: the
|
|
6
18
|
* chart in a wrapper (marked when it is interactive), or a note saying why.
|
|
7
19
|
*/
|
|
8
20
|
export function chartMarkup(result: ChartResult, interactive: boolean): string {
|
|
9
21
|
if (!result.ok) {
|
|
10
|
-
return `<p class="enarratio-chart-error" role="note">This chart could not be drawn. ${
|
|
22
|
+
return `<p class="enarratio-chart-error" role="note">This chart could not be drawn. ${escapeText(result.error)}</p>`;
|
|
11
23
|
}
|
|
12
24
|
const mark = interactive ? " data-enarratio-interactive-chart" : "";
|
|
13
25
|
return `<div class="enarratio-chart"${mark}>${result.html}</div>`;
|