@riebeckite/plugin-code-enhance 0.0.15 → 0.0.16

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/dist/client.js CHANGED
@@ -26,7 +26,7 @@ function initCodeEnhance(options = {}) {
26
26
  });
27
27
  }
28
28
  async function copyCode(button, copyLabel, copiedLabel) {
29
- const code = button.dataset.code ?? "";
29
+ const code = getCodeText(button);
30
30
  if (!code) return;
31
31
  await navigator.clipboard.writeText(code);
32
32
  button.textContent = copiedLabel;
@@ -34,6 +34,11 @@ async function copyCode(button, copyLabel, copiedLabel) {
34
34
  button.textContent = copyLabel;
35
35
  }, 1500);
36
36
  }
37
+ function getCodeText(button) {
38
+ const figure = button.closest(".rr-code");
39
+ const code = figure?.querySelector(".rr-code__code");
40
+ return code?.textContent ?? "";
41
+ }
37
42
  function toggleWrap(button) {
38
43
  const figure = button.closest(".rr-code");
39
44
  const pre = figure?.querySelector(".rr-code__pre");
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ function initCodeEnhance(options = {}) {
33
33
  });
34
34
  }
35
35
  async function copyCode(button, copyLabel, copiedLabel) {
36
- const code = button.dataset.code ?? "";
36
+ const code = getCodeText(button);
37
37
  if (!code) return;
38
38
  await navigator.clipboard.writeText(code);
39
39
  button.textContent = copiedLabel;
@@ -41,6 +41,11 @@ async function copyCode(button, copyLabel, copiedLabel) {
41
41
  button.textContent = copyLabel;
42
42
  }, 1500);
43
43
  }
44
+ function getCodeText(button) {
45
+ const figure = button.closest(".rr-code");
46
+ const code = figure?.querySelector(".rr-code__code");
47
+ return code?.textContent ?? "";
48
+ }
44
49
  function toggleWrap(button) {
45
50
  const figure = button.closest(".rr-code");
46
51
  const pre = figure?.querySelector(".rr-code__pre");
@@ -225,7 +230,6 @@ function enhancePrettyCodeFigures(tree, options) {
225
230
  const titleNode = findTitleNode(node);
226
231
  const title = titleNode ? getTextContent(titleNode) : null;
227
232
  const language = getLanguage(pre, code);
228
- const rawCode = code ? getTextContent(code) : getTextContent(pre);
229
233
  const isTerminal = options.terminal !== false && isTerminalLanguage(language);
230
234
  node.properties = {
231
235
  ...node.properties,
@@ -257,7 +261,6 @@ function enhancePrettyCodeFigures(tree, options) {
257
261
  buildHeader({
258
262
  title: options.filename === false ? null : title,
259
263
  language,
260
- rawCode,
261
264
  copyButton: options.copyButton !== false,
262
265
  wrapToggle: options.wrapToggle !== false,
263
266
  collapsible: options.collapsible === true
@@ -297,7 +300,6 @@ function buildHeader(input) {
297
300
  type: "button",
298
301
  className: "rr-code__action",
299
302
  dataCodeCopy: "true",
300
- dataCode: input.rawCode,
301
303
  ariaLabel: "Copy code"
302
304
  },
303
305
  [text("Copy")]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-code-enhance",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "rehype-pretty-code": "^0.14.1",
25
25
  "shiki": "^3.13.0",
26
- "@riebeckite/core": "0.0.15"
26
+ "@riebeckite/core": "0.0.16"
27
27
  },
28
28
  "devDependencies": {
29
29
  "tsx": "^4.22.4"