@@ -227,7 +227,15 @@ function migrateAttachments (markdownContent, storagePath, noteKey) {
227
227
* @returns {String } postprocessed HTML in which all :storage references are mapped to the actual paths.
228
228
*/
229
229
function fixLocalURLS ( renderedHTML , storagePath ) {
230
- return renderedHTML . replace ( new RegExp ( '/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?"' , 'g' ) , function ( match ) {
230
+ /*
231
+ A :storage reference is like `:storage/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`.
232
+
233
+ - `STORAGE_FOLDER_PLACEHOLDER` will match `:storage`
234
+ - `(?:(?:\\\/|%5C)[-.\\w]+)+` will match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564/f939b2c3.jpg`
235
+ - `(?:\\\/|%5C)[-.\\w]+` will either match `/3b6f8bd6-4edd-4b15-96e0-eadc4475b564` or `/f939b2c3.jpg`
236
+ - `(?:\\\/|%5C)` match the path seperator. `\\\/` for posix systems and `%5C` for windows.
237
+ */
238
+ return renderedHTML . replace ( new RegExp ( '/?' + STORAGE_FOLDER_PLACEHOLDER + '(?:(?:\\\/|%5C)[-.\\w]+)+' , 'g' ) , function ( match ) {
231
239
var encodedPathSeparators = new RegExp ( mdurl . encode ( path . win32 . sep ) + '|' + mdurl . encode ( path . posix . sep ) , 'g' )
232
240
return match . replace ( encodedPathSeparators , path . sep ) . replace ( new RegExp ( '/?' + STORAGE_FOLDER_PLACEHOLDER , 'g' ) , 'file:///' + path . join ( storagePath , DESTINATION_FOLDER ) )
233
241
} )
@@ -279,7 +287,7 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
279
287
* @param {String } noteKey Key of the current note
280
288
* @param {DataTransferItem } dataTransferItem Part of the past-event
281
289
*/
282
- function handlePastImageEvent ( codeEditor , storageKey , noteKey , dataTransferItem ) {
290
+ function handlePasteImageEvent ( codeEditor , storageKey , noteKey , dataTransferItem ) {
283
291
if ( ! codeEditor ) {
284
292
throw new Error ( 'codeEditor has to be given' )
285
293
}
@@ -323,7 +331,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
323
331
* @param {String } noteKey Key of the current note
324
332
* @param {NativeImage } image The native image
325
333
*/
326
- function handlePastNativeImage ( codeEditor , storageKey , noteKey , image ) {
334
+ function handlePasteNativeImage ( codeEditor , storageKey , noteKey , image ) {
327
335
if ( ! codeEditor ) {
328
336
throw new Error ( 'codeEditor has to be given' )
329
337
}
@@ -583,8 +591,8 @@ module.exports = {
583
591
fixLocalURLS,
584
592
generateAttachmentMarkdown,
585
593
handleAttachmentDrop,
586
- handlePastImageEvent ,
587
- handlePastNativeImage ,
594
+ handlePasteImageEvent ,
595
+ handlePasteNativeImage ,
588
596
getAttachmentsInMarkdownContent,
589
597
getAbsolutePathsOfAttachmentsInContent,
590
598
removeStorageAndNoteReferences,
0 commit comments