@aspan-corporation/ac-shared 1.2.33 → 1.2.35
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/lib/utils/diary.js +15 -2
- package/package.json +1 -1
package/lib/utils/diary.js
CHANGED
|
@@ -99,6 +99,10 @@ export const tokenizeText = (markdown) => {
|
|
|
99
99
|
// fenced + inline code
|
|
100
100
|
.replace(/```[\s\S]*?```/g, " ")
|
|
101
101
|
.replace(/`[^`]*`/g, " ")
|
|
102
|
+
// angle-bracket image targets `` first — the destination may
|
|
103
|
+
// contain ")" (e.g. a filename like "image (2).jpg"), which the generic
|
|
104
|
+
// `\([^)]*\)` form below would mis-match.
|
|
105
|
+
.replace(/!\[([^\]]*)\]\(<[^>]*>\)/g, " $1 ")
|
|
102
106
|
// image / link targets: keep the visible text, drop the URL/key
|
|
103
107
|
.replace(/!\[([^\]]*)\]\([^)]*\)/g, " $1 ")
|
|
104
108
|
.replace(/\[([^\]]*)\]\([^)]*\)/g, " $1 ")
|
|
@@ -124,6 +128,10 @@ export const diaryPreview = (markdown) => {
|
|
|
124
128
|
const text = markdown
|
|
125
129
|
.replace(/```[\s\S]*?```/g, " ")
|
|
126
130
|
.replace(/`[^`]*`/g, " ")
|
|
131
|
+
// angle-bracket image targets first — the destination may contain ")"
|
|
132
|
+
// (e.g. "image (2).jpg"), which the generic form below would mis-match,
|
|
133
|
+
// leaking ".jpg )" into the preview.
|
|
134
|
+
.replace(/!\[[^\]]*\]\(<[^>]*>\)/g, " ")
|
|
127
135
|
.replace(/!\[([^\]]*)\]\([^)]*\)/g, " ")
|
|
128
136
|
.replace(/\[([^\]]*)\]\([^)]*\)/g, " $1 ")
|
|
129
137
|
.replace(/[#>*_~]+/g, " ")
|
|
@@ -136,10 +144,15 @@ export const diaryPreview = (markdown) => {
|
|
|
136
144
|
/** Extract the media keys of photos embedded as `` in the body. */
|
|
137
145
|
export const extractEmbeddedPhotoKeys = (markdown) => {
|
|
138
146
|
const keys = new Set();
|
|
139
|
-
|
|
147
|
+
// Two destination forms (CommonMark): angle-bracketed `<…>` — used for keys
|
|
148
|
+
// with spaces, and which may also contain ")" (e.g. "image (2).jpg") — or a
|
|
149
|
+
// bare URL up to the first ")". The angle form is captured in group 1, the
|
|
150
|
+
// bare form in group 2; the bare form must stop at ")" so it can't swallow a
|
|
151
|
+
// parenthesised key, which is exactly why such keys use the angle form.
|
|
152
|
+
const re = /!\[[^\]]*\]\(\s*(?:<([^>]*)>|([^)\s]+))\s*\)/g;
|
|
140
153
|
let m;
|
|
141
154
|
while ((m = re.exec(markdown)) !== null) {
|
|
142
|
-
const key = m[1].trim();
|
|
155
|
+
const key = (m[1] ?? m[2] ?? "").trim();
|
|
143
156
|
// Only treat library media keys as photo links (ignore external URLs).
|
|
144
157
|
if (key && !/^https?:\/\//i.test(key))
|
|
145
158
|
keys.add(key);
|