living-documentation 7.16.0 → 7.17.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.
@@ -8,6 +8,31 @@ let _imgPasteExt = "png";
8
8
  let _imgPasteCursorStart = 0;
9
9
  let _imgPasteCursorEnd = 0;
10
10
 
11
+ // Strip diacritics (é → e, à → a, ç → c), lowercase, then replace anything
12
+ // that isn't [a-z0-9] by "_". Length is preserved so the input caret stays put.
13
+ const _LD_DIACRITICS_RE = new RegExp("[\\u0300-\\u036f]", "g");
14
+ function _sanitizeImageName(s) {
15
+ return (s || "")
16
+ .normalize("NFD")
17
+ .replace(_LD_DIACRITICS_RE, "")
18
+ .toLowerCase()
19
+ .replace(/[^a-z0-9]/g, "_");
20
+ }
21
+
22
+ function _wireImageNameSanitizer() {
23
+ const input = document.getElementById("img-paste-name");
24
+ if (!input || input.dataset.ldSanitizerWired === "1") return;
25
+ input.dataset.ldSanitizerWired = "1";
26
+ input.addEventListener("input", () => {
27
+ const pos = input.selectionStart;
28
+ const cleaned = _sanitizeImageName(input.value);
29
+ if (cleaned !== input.value) {
30
+ input.value = cleaned;
31
+ input.setSelectionRange(pos, pos);
32
+ }
33
+ });
34
+ }
35
+
11
36
  async function handleEditorPaste(e) {
12
37
  const items = Array.from(e.clipboardData?.items ?? []);
13
38
  const imageItem = items.find((item) => item.type.startsWith("image/"));
@@ -23,8 +48,8 @@ async function handleEditorPaste(e) {
23
48
  _imgPasteBlob = imageItem.getAsFile();
24
49
  if (!_imgPasteBlob) return;
25
50
 
26
- // Propose a default name: timestamp in ms
27
- const defaultName = Date.now().toString();
51
+ // Propose a default name: timestamp in ms (already [0-9]+, so sanitization-safe)
52
+ const defaultName = _sanitizeImageName(Date.now().toString());
28
53
  document.getElementById("img-paste-name").value = defaultName;
29
54
  document.getElementById("img-paste-ext").textContent =
30
55
  "." + _imgPasteExt;
@@ -32,6 +57,7 @@ async function handleEditorPaste(e) {
32
57
 
33
58
  // Focus the name input and select all for quick renaming
34
59
  const nameInput = document.getElementById("img-paste-name");
60
+ _wireImageNameSanitizer();
35
61
  nameInput.focus();
36
62
  nameInput.select();
37
63
  }
@@ -42,9 +68,8 @@ function imgPasteCancel() {
42
68
  }
43
69
 
44
70
  async function imgPasteConfirm() {
45
- const name =
46
- document.getElementById("img-paste-name").value.trim() ||
47
- Date.now().toString();
71
+ const raw = document.getElementById("img-paste-name").value.trim();
72
+ const name = _sanitizeImageName(raw) || Date.now().toString();
48
73
  document.getElementById("img-paste-modal").classList.add("hidden");
49
74
 
50
75
  const editor = document.getElementById("doc-editor");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "living-documentation",
3
- "version": "7.16.0",
3
+ "version": "7.17.0",
4
4
  "description": "A CLI tool that serves a local Markdown documentation viewer",
5
5
  "main": "dist/src/server.js",
6
6
  "bin": {