@mirrordown/core 0.1.2 → 0.1.3
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/index.d.mts +39 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +79 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
## 0.1.3
|
|
7
|
+
<sub>2026-11-02</sub>
|
|
8
|
+
|
|
9
|
+
- *(patch)*
|
|
10
|
+
Add the copy-code plugin set: every fenced and indented code block gets a copy button, in its `<pre>` after the `<code>`, with no wrapper element. The button is an invoker command (`command="--copy"`) aimed at the `<pre>`, which takes an id from a hash of its code (`code-<hash>`, with `-2`, `-3`… for repeats). Each package ships a small client script (`./client`) that copies the block's code, without the newline markdown ends it with, shows a check with "Copied!" in a pill beside it, as GitHub does, and announces it to screen readers; the buttons render `hidden` until it runs, so a page without it shows none. The `icons` and `text` options set the button's icon and text in each state. Write `nocopy` after the fence's language to leave a block without one; a host that highlights first can keep the meta in a `data-meta` attribute on the `<pre>`. Where CSS anchor positioning with `anchor-scope` is supported, the button sits in the block's top corner and shows on hover or focus. The markdown-it, remark and Sätteri plugins emit identical HTML.
|
|
11
|
+
|
|
5
12
|
## 0.1.2
|
|
6
13
|
<sub>2026-10-28</sub>
|
|
7
14
|
|
package/dist/index.d.mts
CHANGED
|
@@ -388,5 +388,43 @@ export declare const figureProperties: (author?: Properties) => Properties;
|
|
|
388
388
|
* Wrap each captioned block of an mdast tree, with its caption, in a `figure` node (`hName: "figure"`, class `markdown-caption`) whose last child is a `figcaption` node. `source` is the document the tree was parsed from: caption lines are found, and placed, by their source lines.
|
|
389
389
|
*/
|
|
390
390
|
export declare const processCaptions: (root: Root, source: string) => void;
|
|
391
|
-
|
|
391
|
+
/** The copy button's class. */
|
|
392
|
+
export declare const COPY_CODE_CLASS = "markdown-copy-code";
|
|
393
|
+
/** The invoker command the button sends its code block. */
|
|
394
|
+
export declare const COPY_CODE_COMMAND = "--copy";
|
|
395
|
+
/** Whether a fence's meta, the info string after its language, turns its block's button off. */
|
|
396
|
+
export declare const copyCodeOptedOut: (meta: string | null | undefined) => boolean;
|
|
397
|
+
/** The text a block copies: its code with line endings normalized and without the newline that ends it. */
|
|
398
|
+
export declare const copyCodeText: (code: string) => string;
|
|
399
|
+
/**
|
|
400
|
+
* A document's code block ids, one per block in document order: `code-` and a hash of the block's text, so a block's id doesn't change when others are edited, with `-2`, `-3`… for repeats of one block. Create one per document.
|
|
401
|
+
*/
|
|
402
|
+
export declare const copyCodeIds: () => ((text: string) => string);
|
|
403
|
+
/**
|
|
404
|
+
* A hast `<pre>` holding a code block, as markdown renders one: its only element child is a `<code>`. Returns the text the block copies and its fence's meta, or nothing for another `<pre>` or an empty block. The meta is the `<code>`'s, as remark and Sätteri keep it, or else the `<pre>`'s `data-meta` attribute, where a highlighter that rebuilds the block (such as Astro's Shiki) can keep it.
|
|
405
|
+
*/
|
|
406
|
+
export declare const copyCodeBlock: (node: HastLike) => {
|
|
407
|
+
text: string;
|
|
408
|
+
meta: string | undefined;
|
|
409
|
+
} | undefined;
|
|
410
|
+
/** A copy button's states: before its block is copied, and for a moment after. */
|
|
411
|
+
type CopyCodeState = "copy" | "copied";
|
|
412
|
+
/** Options shared by the copy-code plugins for every engine. */
|
|
413
|
+
interface CopyCodeOptions {
|
|
414
|
+
/** The button's icon in each state, as SVG markup. An icon can be replaced but not removed, since it's all the button holds: an empty one keeps the default. Defaults: {@link COPY_CODE_ICONS}. */
|
|
415
|
+
icons?: Partial<Record<CopyCodeState, string>>;
|
|
416
|
+
/**
|
|
417
|
+
* Text shown beside the button in each state, and the button's accessible name; `null` or `""` shows none. Defaults: {@link COPY_CODE_TEXT}, none before copying and `Copied!` after. The copy text shows while the button is hovered or focused.
|
|
418
|
+
*/
|
|
419
|
+
text?: Partial<Record<CopyCodeState, string | null>>;
|
|
420
|
+
}
|
|
421
|
+
/** The button's default icon in each state. */
|
|
422
|
+
export declare const COPY_CODE_ICONS: Record<CopyCodeState, string>;
|
|
423
|
+
/** The button's default text in each state, as GitHub shows it: none before copying, `Copied!` after. */
|
|
424
|
+
export declare const COPY_CODE_TEXT: Record<CopyCodeState, string>;
|
|
425
|
+
/**
|
|
426
|
+
* Builds a document's copy buttons under the plugin's options. A button is for the code block whose `<pre>` has the id, and goes in the `<pre>` after its `<code>`. It starts `hidden`: the client script shows it where it can copy, so a page without the script has no button that does nothing. Each state's icon and text are spans marked `data-state`, which the stylesheet shows by the button's `data-copied`; the client script names the copied button by its copied text.
|
|
427
|
+
*/
|
|
428
|
+
export declare const createCopyCodeButton: (options?: CopyCodeOptions) => ((id: string) => string);
|
|
429
|
+
export type { AbbreviationPart, AlertOptions, AlertParagraph, AlertResolver, AlertType, CopyCodeOptions, CopyCodeState, DelimiterMarker, EditableTree, HastElementLike, HastLike, InlineSvgLimits, LineContainer, MermaidAttribute, PhrasingLike, Positioned, ReadAttributes, ScriptSyntax, SpanNodes, SpanTransform, StepsItemNode, StepsListNode, StepsTitleNode, TabsItemNode, TabsLabelNode, TabsListNode, TextLikeNode, TreeNode };
|
|
392
430
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/escapes.ts","../src/github-alerts/types.ts","../src/github-alerts/icons.ts","../src/github-alerts/index.ts","../src/spans.ts","../src/delimited.ts","../src/kbd.ts","../src/scripts.ts","../src/hast.ts","../src/abbr.ts","../src/steps.ts","../src/tabs.ts","../src/editable.ts","../src/cut-attributes.ts","../src/inline-svg.ts","../src/mermaid-pele.ts","../src/line-containers.ts","../src/caption.ts"],"mappings":";;;;;;;;qBAqBa,iBACX,eACA,gBACA,eACA,gBACC;;qBAyBU,cAA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;;;qBAuCnC,qBACX,MAAM,MACN,gCACA,MAAM;;UC/CS;;EAEf;;EAEA;;EAEA;;EAEA;;;;;qBAcW,cAAe;;;;qBAqDf,kBACX,iBACA,yBACA,sBACA,QAAQ;;KC7EE,oBAAoB,cAAc;;qBAgBjC,gBAAiB;;;;qBAMjB,oBACX,qBACG;;;;qBA0BQ,aACX,aACA,qBAAqB;;qBA2BV,iBACX,YAAY,wCACX;;;;qBAoCU,iBACX,KAAK;EACF;EAAgB,SAAS;;;;;qBAkBjB,iBACX,gBACA,6BACC;;;;KC5IS;EACN;EAAe;;EACf;EAAc;;;;;qBAKP,iBACX,cACA,qBAAqB;;;;qBAoBV,cAAe;;qBCxBf;;qBAGA,gBAAiB;;qBAIjB,gBAAiB;;qBAIjB,qBAAsB;;qBAyBtB,mBAAoB,SAAS,eAAa;;;;qBAoF1C,kBAAmB,MAAM,MAAM"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/escapes.ts","../src/github-alerts/types.ts","../src/github-alerts/icons.ts","../src/github-alerts/index.ts","../src/spans.ts","../src/delimited.ts","../src/kbd.ts","../src/scripts.ts","../src/hast.ts","../src/abbr.ts","../src/steps.ts","../src/tabs.ts","../src/editable.ts","../src/cut-attributes.ts","../src/inline-svg.ts","../src/mermaid-pele.ts","../src/line-containers.ts","../src/caption.ts","../src/copy-code.ts"],"mappings":";;;;;;;;qBAqBa,iBACX,eACA,gBACA,eACA,gBACC;;qBAyBU,cAAe,eAAe,SAAS;;qBAYvC,gBAAiB;;UAMb;EACf;EACA;EACA;IAEM;MAAS;;IACT;MAAO;;;EAGb,WAAW;;;;;;;qBAQA,kBACX,MAAM,cACN;;KCvFU;;qBAoBC,eAAe,eAAe;;qBAiC9B,eAAe,OAAO;;UAmBlB;;;;;;EAMf,QAAQ;;EAER,SAAS,QAAQ,OAAO;;EAExB;;EAEA;;EAEA;;;qBC9EW,OAAO,OAAO;;qBCMd,oBAAqB;;UAOjB;;EAEf,UAAU;;EA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BjB,iBACX,gBACA,6BACC;;;;KC5IS;EACN;EAAe;;EACf;EAAc;;;;;qBAKP,iBACX,cACA,qBAAqB;;;;qBAoBV,cAAe;;qBCxBf;;qBAGA,gBAAiB;;qBAIjB,gBAAiB;;qBAIjB,qBAAsB;;qBAyBtB,mBAAoB,SAAS,eAAa;;;;qBAoF1C,kBAAmB,MAAM,MAAM;;qBC5H/B;;qBAGA;;qBAMA,mBAAoB;;qBAIpB,eAAgB;;;;qBAMhB,qBAAoB;;;;qBAapB,gBACX,MAAM;EACH;EAAc;;;KAcP;;UAGK;;EAEf,QAAQ,QAAQ,OAAO;;;;EAIvB,OAAO,QAAQ,OAAO;;;qBAQX,iBAAiB,OAAO;;qBAQxB,gBAAgB,OAAO;;;;qBAcvB,uBACX,UAAS,sBACN"}
|
package/dist/index.mjs
CHANGED
|
@@ -113,24 +113,24 @@ const DEFAULT_TITLE = {
|
|
|
113
113
|
quote: "Quote"
|
|
114
114
|
};
|
|
115
115
|
// src/github-alerts/icons.ts
|
|
116
|
-
const icon = (path) => `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${path}</svg>`;
|
|
116
|
+
const icon$1 = (path) => `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${path}</svg>`;
|
|
117
117
|
/** Inline SVG icon markup for each {@link AlertType}. */
|
|
118
118
|
const ICONS = {
|
|
119
|
-
note: icon("<path d=\"M12 20h9\"></path><path d=\"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z\"></path>"),
|
|
120
|
-
tip: icon("<path d=\"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5\"></path><path d=\"M9 18h6\"></path><path d=\"M10 22h4\"></path>"),
|
|
121
|
-
important: icon("<path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22z\"></path>"),
|
|
122
|
-
warning: icon("<path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"></path><path d=\"M12 9v4\"></path><path d=\"M12 17h.01\"></path>"),
|
|
123
|
-
caution: icon("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m4.9 4.9 14.2 14.2\"></path><path d=\"M12 8v4\"></path><path d=\"M12 16h.01\"></path>"),
|
|
124
|
-
abstract: icon("<rect width=\"8\" height=\"4\" x=\"8\" y=\"2\" rx=\"1\" ry=\"1\"></rect><path d=\"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2\"></path><path d=\"M12 11h4\"></path><path d=\"M12 16h4\"></path><path d=\"M8 11h.01\"></path><path d=\"M8 16h.01\"></path>"),
|
|
125
|
-
info: icon("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M12 16v-4\"></path><path d=\"M12 8h.01\"></path>"),
|
|
126
|
-
todo: icon("<path d=\"M8 6h13\"></path><path d=\"M8 12h13\"></path><path d=\"M8 18h13\"></path><path d=\"M3 6h.01\"></path><path d=\"M3 12h.01\"></path><path d=\"M3 18h.01\"></path>"),
|
|
127
|
-
success: icon("<path d=\"M22 11.08V12a10 10 0 1 1-5.93-9.14\"></path><path d=\"m9 11 3 3L22 4\"></path>"),
|
|
128
|
-
question: icon("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3\"></path><path d=\"M12 17h.01\"></path>"),
|
|
129
|
-
failure: icon("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m15 9-6 6\"></path><path d=\"m9 9 6 6\"></path>"),
|
|
130
|
-
danger: icon("<path d=\"M13 2 3 14h9l-1 8 10-12h-9l1-8z\"></path>"),
|
|
131
|
-
bug: icon("<path d=\"m8 2 1.88 1.88\"></path><path d=\"M14.12 3.88 16 2\"></path><path d=\"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1\"></path><path d=\"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6\"></path><path d=\"M12 20v-9\"></path><path d=\"M6.53 9C4.6 8.8 3 7.1 3 5\"></path><path d=\"M6 13H2\"></path><path d=\"M3 21c0-2.1 1.7-3.9 3.8-4\"></path><path d=\"M20.97 5c0 2.1-1.6 3.8-3.5 4\"></path><path d=\"M22 13h-4\"></path><path d=\"M17.2 17c2.1.1 3.8 1.9 3.8 4\"></path>"),
|
|
132
|
-
example: icon("<path d=\"M8 6h13\"></path><path d=\"M8 12h13\"></path><path d=\"M8 18h13\"></path><path d=\"M3 6 4 5l1 1-1 1z\"></path><path d=\"M3 12 4 11l1 1-1 1z\"></path><path d=\"M3 18 4 17l1 1-1 1z\"></path>"),
|
|
133
|
-
quote: icon("<path d=\"M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z\"></path><path d=\"M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z\"></path>")
|
|
119
|
+
note: icon$1("<path d=\"M12 20h9\"></path><path d=\"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z\"></path>"),
|
|
120
|
+
tip: icon$1("<path d=\"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5\"></path><path d=\"M9 18h6\"></path><path d=\"M10 22h4\"></path>"),
|
|
121
|
+
important: icon$1("<path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22z\"></path>"),
|
|
122
|
+
warning: icon$1("<path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"></path><path d=\"M12 9v4\"></path><path d=\"M12 17h.01\"></path>"),
|
|
123
|
+
caution: icon$1("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m4.9 4.9 14.2 14.2\"></path><path d=\"M12 8v4\"></path><path d=\"M12 16h.01\"></path>"),
|
|
124
|
+
abstract: icon$1("<rect width=\"8\" height=\"4\" x=\"8\" y=\"2\" rx=\"1\" ry=\"1\"></rect><path d=\"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2\"></path><path d=\"M12 11h4\"></path><path d=\"M12 16h4\"></path><path d=\"M8 11h.01\"></path><path d=\"M8 16h.01\"></path>"),
|
|
125
|
+
info: icon$1("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M12 16v-4\"></path><path d=\"M12 8h.01\"></path>"),
|
|
126
|
+
todo: icon$1("<path d=\"M8 6h13\"></path><path d=\"M8 12h13\"></path><path d=\"M8 18h13\"></path><path d=\"M3 6h.01\"></path><path d=\"M3 12h.01\"></path><path d=\"M3 18h.01\"></path>"),
|
|
127
|
+
success: icon$1("<path d=\"M22 11.08V12a10 10 0 1 1-5.93-9.14\"></path><path d=\"m9 11 3 3L22 4\"></path>"),
|
|
128
|
+
question: icon$1("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3\"></path><path d=\"M12 17h.01\"></path>"),
|
|
129
|
+
failure: icon$1("<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m15 9-6 6\"></path><path d=\"m9 9 6 6\"></path>"),
|
|
130
|
+
danger: icon$1("<path d=\"M13 2 3 14h9l-1 8 10-12h-9l1-8z\"></path>"),
|
|
131
|
+
bug: icon$1("<path d=\"m8 2 1.88 1.88\"></path><path d=\"M14.12 3.88 16 2\"></path><path d=\"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1\"></path><path d=\"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6\"></path><path d=\"M12 20v-9\"></path><path d=\"M6.53 9C4.6 8.8 3 7.1 3 5\"></path><path d=\"M6 13H2\"></path><path d=\"M3 21c0-2.1 1.7-3.9 3.8-4\"></path><path d=\"M20.97 5c0 2.1-1.6 3.8-3.5 4\"></path><path d=\"M22 13h-4\"></path><path d=\"M17.2 17c2.1.1 3.8 1.9 3.8 4\"></path>"),
|
|
132
|
+
example: icon$1("<path d=\"M8 6h13\"></path><path d=\"M8 12h13\"></path><path d=\"M8 18h13\"></path><path d=\"M3 6 4 5l1 1-1 1z\"></path><path d=\"M3 12 4 11l1 1-1 1z\"></path><path d=\"M3 18 4 17l1 1-1 1z\"></path>"),
|
|
133
|
+
quote: icon$1("<path d=\"M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z\"></path><path d=\"M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z\"></path>")
|
|
134
134
|
};
|
|
135
135
|
// src/github-alerts/index.ts
|
|
136
136
|
const MARKER_RE = /^\[!([^\]]+)\]([+-])?/;
|
|
@@ -2177,6 +2177,68 @@ const inlineSvgMarkup = (content, alts, relativePath, limits) => {
|
|
|
2177
2177
|
return index === 0 ? sprite + use : use;
|
|
2178
2178
|
});
|
|
2179
2179
|
};
|
|
2180
|
-
|
|
2180
|
+
// src/copy-code.ts
|
|
2181
|
+
/** The copy button's class. */
|
|
2182
|
+
const COPY_CODE_CLASS = "markdown-copy-code";
|
|
2183
|
+
/** The invoker command the button sends its code block. */
|
|
2184
|
+
const COPY_CODE_COMMAND = "--copy";
|
|
2185
|
+
const OPT_OUT = `nocopy`;
|
|
2186
|
+
/** Whether a fence's meta, the info string after its language, turns its block's button off. */
|
|
2187
|
+
const copyCodeOptedOut = (meta) => (meta ?? ``).split(/\s+/).includes(OPT_OUT);
|
|
2188
|
+
/** The text a block copies: its code with line endings normalized and without the newline that ends it. */
|
|
2189
|
+
const copyCodeText = (code) => code.replace(/\r\n?/g, `\n`).replace(/\n$/, ``);
|
|
2190
|
+
/**
|
|
2191
|
+
* A document's code block ids, one per block in document order: `code-` and a hash of the block's text, so a block's id doesn't change when others are edited, with `-2`, `-3`… for repeats of one block. Create one per document.
|
|
2192
|
+
*/
|
|
2193
|
+
const copyCodeIds = () => mermaidIdPrefixes(`code`);
|
|
2194
|
+
const textOf = (node) => node.type === `text` ? node.value ?? `` : (node.children ?? []).map(textOf).join(``);
|
|
2195
|
+
/**
|
|
2196
|
+
* A hast `<pre>` holding a code block, as markdown renders one: its only element child is a `<code>`. Returns the text the block copies and its fence's meta, or nothing for another `<pre>` or an empty block. The meta is the `<code>`'s, as remark and Sätteri keep it, or else the `<pre>`'s `data-meta` attribute, where a highlighter that rebuilds the block (such as Astro's Shiki) can keep it.
|
|
2197
|
+
*/
|
|
2198
|
+
const copyCodeBlock = (node) => {
|
|
2199
|
+
if (node.type !== `element` || node.tagName !== `pre`) return void 0;
|
|
2200
|
+
const elements = (node.children ?? []).filter((child) => child.type === `element`);
|
|
2201
|
+
const [code] = elements;
|
|
2202
|
+
if (elements.length !== 1 || code?.tagName !== `code`) return void 0;
|
|
2203
|
+
const text = copyCodeText(textOf(code));
|
|
2204
|
+
if (text === ``) return void 0;
|
|
2205
|
+
const meta = code.data?.meta ?? node.properties?.dataMeta;
|
|
2206
|
+
return {
|
|
2207
|
+
text,
|
|
2208
|
+
meta: typeof meta === `string` ? meta : void 0
|
|
2209
|
+
};
|
|
2210
|
+
};
|
|
2211
|
+
const icon = (paths) => `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
2212
|
+
/** The button's default icon in each state. */
|
|
2213
|
+
const COPY_CODE_ICONS = {
|
|
2214
|
+
copy: icon(`<rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path>`),
|
|
2215
|
+
copied: icon(`<path d="M20 6 9 17l-5-5"></path>`)
|
|
2216
|
+
};
|
|
2217
|
+
/** The button's default text in each state, as GitHub shows it: none before copying, `Copied!` after. */
|
|
2218
|
+
const COPY_CODE_TEXT = {
|
|
2219
|
+
copy: ``,
|
|
2220
|
+
copied: `Copied!`
|
|
2221
|
+
};
|
|
2222
|
+
const DEFAULT_LABEL = `Copy code`;
|
|
2223
|
+
const escape = (value) => value.replace(/&/g, `&`).replace(/</g, `<`).replace(/"/g, `"`);
|
|
2224
|
+
/**
|
|
2225
|
+
* Builds a document's copy buttons under the plugin's options. A button is for the code block whose `<pre>` has the id, and goes in the `<pre>` after its `<code>`. It starts `hidden`: the client script shows it where it can copy, so a page without the script has no button that does nothing. Each state's icon and text are spans marked `data-state`, which the stylesheet shows by the button's `data-copied`; the client script names the copied button by its copied text.
|
|
2226
|
+
*/
|
|
2227
|
+
const createCopyCodeButton = (options = {}) => {
|
|
2228
|
+
const icons = {
|
|
2229
|
+
...COPY_CODE_ICONS,
|
|
2230
|
+
...options.icons
|
|
2231
|
+
};
|
|
2232
|
+
const texts = {
|
|
2233
|
+
...COPY_CODE_TEXT,
|
|
2234
|
+
...options.text
|
|
2235
|
+
};
|
|
2236
|
+
const text = (state) => texts[state] ?? ``;
|
|
2237
|
+
const states = [`copy`, `copied`];
|
|
2238
|
+
const content = [...states.map((state) => `<span class="${COPY_CODE_CLASS}-icon" data-state="${state}" aria-hidden="true">${icons[state] || COPY_CODE_ICONS[state]}</span>`), ...states.map((state) => text(state) ? `<span class="${COPY_CODE_CLASS}-text" data-state="${state}" aria-hidden="true">${escape(text(state))}</span>` : ``)].join(``);
|
|
2239
|
+
const label = escape(text(`copy`) || DEFAULT_LABEL);
|
|
2240
|
+
return (id) => `<button type="button" class="${COPY_CODE_CLASS}" command="${COPY_CODE_COMMAND}" commandfor="${id}" aria-label="${label}" hidden>${content}</button>`;
|
|
2241
|
+
};
|
|
2242
|
+
export { ALERT_ALIASES, CAPTION_CLASS, COPY_CODE_CLASS, COPY_CODE_COMMAND, COPY_CODE_ICONS, COPY_CODE_TEXT, DEFAULT_TITLE, ICONS, LIGHTBOX_MARKER, containersKept, copyCodeBlock, copyCodeIds, copyCodeOptedOut, copyCodeText, createAbbreviationScan, createAlertResolver, createCopyCodeButton, createDelimitedTransform, createKbdTransform, editableTree, escapedIndices, figureProperties, hastAttributes, headingRank, inlineSvgMarkup, isAlertMarkerLine, isCaptionFigure, isCaptionLine, isEmptyParagraph, isImageParagraph, itemColumns, lightboxDialog, lightboxId, lightboxTrigger, maskEscaped, maskTreeEscapes, mermaidDiagram, mermaidFailure, mermaidIdPrefixes, mermaidSource, mermaidSvg, parseAbbreviations, placeCutAttributes, plainText, processCaptions, processSteps, processStepsInChildren, processTabs, processTabsInChildren, scriptSyntax, sectionize, splitAlertParagraph, startsCaption, stripAttrs, stripCaptionMarker, svgSpriteId, tabLabelText, tabsBlockId, unmaskEscaped };
|
|
2181
2243
|
|
|
2182
2244
|
//# sourceMappingURL=index.mjs.map
|