mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-12 17:26:17 +00:00
- use newest test
- remove useless binding - regroup function
This commit is contained in:
@@ -460,7 +460,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
storageKey={note.storage}
|
storageKey={note.storage}
|
||||||
noteKey={note.key}
|
noteKey={note.key}
|
||||||
linesHighlighted={note.linesHighlighted}
|
linesHighlighted={note.linesHighlighted}
|
||||||
onChange={this.handleUpdateContent.bind(this)}
|
onChange={this.handleUpdateContent}
|
||||||
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
||||||
getNote={this.getNote}
|
getNote={this.getNote}
|
||||||
RTL={config.editor.rtlEnabled && this.state.RTL}
|
RTL={config.editor.rtlEnabled && this.state.RTL}
|
||||||
@@ -475,7 +475,7 @@ class MarkdownNoteDetail extends React.Component {
|
|||||||
storageKey={note.storage}
|
storageKey={note.storage}
|
||||||
noteKey={note.key}
|
noteKey={note.key}
|
||||||
linesHighlighted={note.linesHighlighted}
|
linesHighlighted={note.linesHighlighted}
|
||||||
onChange={this.handleUpdateContent.bind(this)}
|
onChange={this.handleUpdateContent}
|
||||||
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
||||||
getNote={this.getNote}
|
getNote={this.getNote}
|
||||||
RTL={config.editor.rtlEnabled && this.state.RTL}
|
RTL={config.editor.rtlEnabled && this.state.RTL}
|
||||||
|
|||||||
@@ -706,14 +706,15 @@ function replaceNoteKeyWithNewNoteKey(noteContent, oldNoteKey, newNoteKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Deletes all :storage and noteKey references from the given input.
|
* @description replace all :storage references with given destination folder.
|
||||||
* @param input Input in which the references should be deleted
|
* @param input Input in which the references should be replaced
|
||||||
* @param noteKey Key of the current note
|
* @param noteKey Key of the current note
|
||||||
|
* @param destinationFolder Destination folder of the attachements
|
||||||
* @returns {String} Input without the references
|
* @returns {String} Input without the references
|
||||||
*/
|
*/
|
||||||
function removeStorageAndNoteReferences(input, noteKey) {
|
function replaceStorageReferences(input, noteKey, destinationFolder) {
|
||||||
return input.replace(
|
return input.replace(
|
||||||
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|\\))', 'g'),
|
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '[^"\\)<\\s]+', 'g'),
|
||||||
function(match) {
|
function(match) {
|
||||||
return match
|
return match
|
||||||
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.posix.sep)
|
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.posix.sep)
|
||||||
@@ -735,33 +736,12 @@ function removeStorageAndNoteReferences(input, noteKey) {
|
|||||||
')?',
|
')?',
|
||||||
'g'
|
'g'
|
||||||
),
|
),
|
||||||
DESTINATION_FOLDER
|
destinationFolder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description replace all :storage references with given destination folder.
|
|
||||||
* @param input Input in which the references should be replaced
|
|
||||||
* @param noteKey Key of the current note
|
|
||||||
* @param destinationFolder Destination folder of the attachements
|
|
||||||
* @returns {String} Input without the references
|
|
||||||
*/
|
|
||||||
function replaceStorageReferences(input, noteKey, destinationFolder) {
|
|
||||||
return input.replace(
|
|
||||||
new RegExp(
|
|
||||||
STORAGE_FOLDER_PLACEHOLDER +
|
|
||||||
'(' +
|
|
||||||
escapeStringRegexp(path.sep) +
|
|
||||||
noteKey +
|
|
||||||
')?',
|
|
||||||
'g'
|
|
||||||
),
|
|
||||||
destinationFolder || DESTINATION_FOLDER
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Deletes the attachment folder specified by the given storageKey and noteKey
|
* @description Deletes the attachment folder specified by the given storageKey and noteKey
|
||||||
* @param storageKey Key of the storage of the note to be deleted
|
* @param storageKey Key of the storage of the note to be deleted
|
||||||
@@ -1122,7 +1102,6 @@ module.exports = {
|
|||||||
getAttachmentsInMarkdownContent,
|
getAttachmentsInMarkdownContent,
|
||||||
getAbsolutePathsOfAttachmentsInContent,
|
getAbsolutePathsOfAttachmentsInContent,
|
||||||
importAttachments,
|
importAttachments,
|
||||||
removeStorageAndNoteReferences,
|
|
||||||
removeAttachmentsByPaths,
|
removeAttachmentsByPaths,
|
||||||
replaceStorageReferences,
|
replaceStorageReferences,
|
||||||
deleteAttachmentFolder,
|
deleteAttachmentFolder,
|
||||||
|
|||||||
@@ -702,14 +702,15 @@ it('should remove the all ":storage" and noteKey references', function() {
|
|||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const actual = systemUnderTest.removeStorageAndNoteReferences(
|
const actual = systemUnderTest.replaceStorageReferences(
|
||||||
testInput,
|
testInput,
|
||||||
noteKey
|
noteKey,
|
||||||
|
systemUnderTest.DESTINATION_FOLDER
|
||||||
)
|
)
|
||||||
expect(actual).toEqual(expectedOutput)
|
expect(actual).toEqual(expectedOutput)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make sure that "removeStorageAndNoteReferences" works with markdown content as well', function() {
|
it('should make sure that "replaceStorageReferences" works with markdown content as well', function() {
|
||||||
const noteKey = 'noteKey'
|
const noteKey = 'noteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
@@ -736,9 +737,10 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
|
|||||||
systemUnderTest.DESTINATION_FOLDER +
|
systemUnderTest.DESTINATION_FOLDER +
|
||||||
path.posix.sep +
|
path.posix.sep +
|
||||||
'pdf.pdf)'
|
'pdf.pdf)'
|
||||||
const actual = systemUnderTest.removeStorageAndNoteReferences(
|
const actual = systemUnderTest.replaceStorageReferences(
|
||||||
testInput,
|
testInput,
|
||||||
noteKey
|
noteKey,
|
||||||
|
systemUnderTest.DESTINATION_FOLDER
|
||||||
)
|
)
|
||||||
expect(actual).toEqual(expectedOutput)
|
expect(actual).toEqual(expectedOutput)
|
||||||
})
|
})
|
||||||
@@ -803,7 +805,11 @@ it('should replace the all ":storage" references', function() {
|
|||||||
' </p>\n' +
|
' </p>\n' +
|
||||||
' </body>\n' +
|
' </body>\n' +
|
||||||
'</html>'
|
'</html>'
|
||||||
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
|
const actual = systemUnderTest.replaceStorageReferences(
|
||||||
|
testInput,
|
||||||
|
noteKey,
|
||||||
|
systemUnderTest.DESTINATION_FOLDER
|
||||||
|
)
|
||||||
expect(actual).toEqual(expectedOutput)
|
expect(actual).toEqual(expectedOutput)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -811,30 +817,34 @@ it('should make sure that "replaceStorageReferences" works with markdown content
|
|||||||
const noteKey = 'noteKey'
|
const noteKey = 'noteKey'
|
||||||
const testInput =
|
const testInput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
'image.jpg) \n' +
|
||||||
'[' +
|
'[pdf](' +
|
||||||
systemUnderTest.STORAGE_FOLDER_PLACEHOLDER +
|
systemUnderTest.STORAGE_FOLDER_PLACEHOLDER +
|
||||||
path.sep +
|
path.posix.sep +
|
||||||
noteKey +
|
noteKey +
|
||||||
path.sep +
|
path.posix.sep +
|
||||||
'pdf.pdf](pdf})'
|
'pdf.pdf)'
|
||||||
|
|
||||||
const expectedOutput =
|
const expectedOutput =
|
||||||
'Test input' +
|
'Test input' +
|
||||||
' \n' +
|
'image.jpg) \n' +
|
||||||
'[' +
|
'[pdf](' +
|
||||||
systemUnderTest.DESTINATION_FOLDER +
|
systemUnderTest.DESTINATION_FOLDER +
|
||||||
path.sep +
|
path.posix.sep +
|
||||||
'pdf.pdf](pdf})'
|
'pdf.pdf)'
|
||||||
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
|
const actual = systemUnderTest.replaceStorageReferences(
|
||||||
|
testInput,
|
||||||
|
noteKey,
|
||||||
|
systemUnderTest.DESTINATION_FOLDER
|
||||||
|
)
|
||||||
expect(actual).toEqual(expectedOutput)
|
expect(actual).toEqual(expectedOutput)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user