marked-abc 0.0.0 → 0.1.1
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/README.md +2 -1
- package/lib/index.esm.js +2 -1
- package/lib/index.esm.js.map +2 -2
- package/lib/index.umd.js +2 -1
- package/lib/index.umd.js.map +2 -2
- package/package.json +2 -2
- package/src/index.ts +16 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marked-abc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Render sheet music with ABCjs in Markdown documents using Marked.",
|
|
5
5
|
"main": "./lib/index.esm.js",
|
|
6
6
|
"module": "./lib/index.esm.js",
|
|
7
7
|
"browser": "./lib/index.umd.js",
|
package/src/index.ts
CHANGED
|
@@ -68,6 +68,12 @@ export type MarkedAbcOptions = {
|
|
|
68
68
|
sanitizer?: (text: string) => string,
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
type AbcToken = {
|
|
72
|
+
type: 'abcScore',
|
|
73
|
+
raw: string,
|
|
74
|
+
abc: string,
|
|
75
|
+
};
|
|
76
|
+
|
|
71
77
|
export default function(options: MarkedAbcOptions = {}): MarkedExtension {
|
|
72
78
|
return {
|
|
73
79
|
extensions: [{
|
|
@@ -83,7 +89,7 @@ export default function(options: MarkedAbcOptions = {}): MarkedExtension {
|
|
|
83
89
|
}
|
|
84
90
|
const endMatch = SCORE_CLOSE.exec(src);
|
|
85
91
|
if (endMatch === null) {
|
|
86
|
-
|
|
92
|
+
return undefined;
|
|
87
93
|
}
|
|
88
94
|
const end = endMatch.index + endMatch[0].length;
|
|
89
95
|
const raw = src.slice(0, end);
|
|
@@ -92,7 +98,7 @@ export default function(options: MarkedAbcOptions = {}): MarkedExtension {
|
|
|
92
98
|
type: 'abcScore',
|
|
93
99
|
raw,
|
|
94
100
|
abc,
|
|
95
|
-
};
|
|
101
|
+
} satisfies AbcToken;
|
|
96
102
|
},
|
|
97
103
|
renderer(token) {
|
|
98
104
|
// Increment score counter for each score rendered to ensure ID uniqueness
|
|
@@ -103,12 +109,18 @@ export default function(options: MarkedAbcOptions = {}): MarkedExtension {
|
|
|
103
109
|
// JS moment: the coverage ignore comment is not included in its own ignore meaning I need
|
|
104
110
|
// to place it before this if statement, meaning the coverage of the if statement itself is
|
|
105
111
|
// not measured.
|
|
106
|
-
/* node:coverage
|
|
112
|
+
/* node:coverage disable */
|
|
107
113
|
if ('document' in globalThis) {
|
|
108
114
|
waitForElement(`#${eleId}`).then((ele: Element) => {
|
|
109
|
-
abcjs.renderAbc(
|
|
115
|
+
abcjs.renderAbc(
|
|
116
|
+
ele,
|
|
117
|
+
// Trim all leading whitespace or ABCjs freaks out and fails to render it all
|
|
118
|
+
(token as AbcToken).abc.split('\n').map((line: string) => line.trim()).join(),
|
|
119
|
+
options.abcOptions,
|
|
120
|
+
);
|
|
110
121
|
});
|
|
111
122
|
}
|
|
123
|
+
/* node:coverage enable */
|
|
112
124
|
|
|
113
125
|
return dedent`<div class="abc-score" id="${eleId}">
|
|
114
126
|
${indent(sanitize(token.abc), ' ')}
|