mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-11 00:36:26 +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}
|
||||
noteKey={note.key}
|
||||
linesHighlighted={note.linesHighlighted}
|
||||
onChange={this.handleUpdateContent.bind(this)}
|
||||
onChange={this.handleUpdateContent}
|
||||
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
||||
getNote={this.getNote}
|
||||
RTL={config.editor.rtlEnabled && this.state.RTL}
|
||||
@@ -475,7 +475,7 @@ class MarkdownNoteDetail extends React.Component {
|
||||
storageKey={note.storage}
|
||||
noteKey={note.key}
|
||||
linesHighlighted={note.linesHighlighted}
|
||||
onChange={this.handleUpdateContent.bind(this)}
|
||||
onChange={this.handleUpdateContent}
|
||||
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
|
||||
getNote={this.getNote}
|
||||
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.
|
||||
* @param input Input in which the references should be deleted
|
||||
* @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 removeStorageAndNoteReferences(input, noteKey) {
|
||||
function replaceStorageReferences(input, noteKey, destinationFolder) {
|
||||
return input.replace(
|
||||
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|\\))', 'g'),
|
||||
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '[^"\\)<\\s]+', 'g'),
|
||||
function(match) {
|
||||
return match
|
||||
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.posix.sep)
|
||||
@@ -735,33 +736,12 @@ function removeStorageAndNoteReferences(input, noteKey) {
|
||||
')?',
|
||||
'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
|
||||
* @param storageKey Key of the storage of the note to be deleted
|
||||
@@ -1122,7 +1102,6 @@ module.exports = {
|
||||
getAttachmentsInMarkdownContent,
|
||||
getAbsolutePathsOfAttachmentsInContent,
|
||||
importAttachments,
|
||||
removeStorageAndNoteReferences,
|
||||
removeAttachmentsByPaths,
|
||||
replaceStorageReferences,
|
||||
deleteAttachmentFolder,
|
||||
|
||||
@@ -702,14 +702,15 @@ it('should remove the all ":storage" and noteKey references', function() {
|
||||
' </p>\n' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
const actual = systemUnderTest.removeStorageAndNoteReferences(
|
||||
const actual = systemUnderTest.replaceStorageReferences(
|
||||
testInput,
|
||||
noteKey
|
||||
noteKey,
|
||||
systemUnderTest.DESTINATION_FOLDER
|
||||
)
|
||||
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 testInput =
|
||||
'Test input' +
|
||||
@@ -736,9 +737,10 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
|
||||
systemUnderTest.DESTINATION_FOLDER +
|
||||
path.posix.sep +
|
||||
'pdf.pdf)'
|
||||
const actual = systemUnderTest.removeStorageAndNoteReferences(
|
||||
const actual = systemUnderTest.replaceStorageReferences(
|
||||
testInput,
|
||||
noteKey
|
||||
noteKey,
|
||||
systemUnderTest.DESTINATION_FOLDER
|
||||
)
|
||||
expect(actual).toEqual(expectedOutput)
|
||||
})
|
||||
@@ -803,7 +805,11 @@ it('should replace the all ":storage" references', function() {
|
||||
' </p>\n' +
|
||||
' </body>\n' +
|
||||
'</html>'
|
||||
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
|
||||
const actual = systemUnderTest.replaceStorageReferences(
|
||||
testInput,
|
||||
noteKey,
|
||||
systemUnderTest.DESTINATION_FOLDER
|
||||
)
|
||||
expect(actual).toEqual(expectedOutput)
|
||||
})
|
||||
|
||||
@@ -811,30 +817,34 @@ it('should make sure that "replaceStorageReferences" works with markdown content
|
||||
const noteKey = 'noteKey'
|
||||
const testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' +
|
||||
path.win32.sep +
|
||||
'image.jpg) \n' +
|
||||
'[pdf](' +
|
||||
systemUnderTest.STORAGE_FOLDER_PLACEHOLDER +
|
||||
path.sep +
|
||||
path.posix.sep +
|
||||
noteKey +
|
||||
path.sep +
|
||||
'pdf.pdf](pdf})'
|
||||
path.posix.sep +
|
||||
'pdf.pdf)'
|
||||
|
||||
const expectedOutput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
'[' +
|
||||
path.posix.sep +
|
||||
'image.jpg) \n' +
|
||||
'[pdf](' +
|
||||
systemUnderTest.DESTINATION_FOLDER +
|
||||
path.sep +
|
||||
'pdf.pdf](pdf})'
|
||||
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
|
||||
path.posix.sep +
|
||||
'pdf.pdf)'
|
||||
const actual = systemUnderTest.replaceStorageReferences(
|
||||
testInput,
|
||||
noteKey,
|
||||
systemUnderTest.DESTINATION_FOLDER
|
||||
)
|
||||
expect(actual).toEqual(expectedOutput)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user