mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #2002 from ehhc/paste_storage_link_should_clone_attachment
Copying the link to an attachment should make sure that it is located…
This commit is contained in:
@@ -16,7 +16,7 @@ CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||
|
||||
const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
|
||||
const buildCMRulers = (rulers, enableRulers) =>
|
||||
enableRulers ? rulers.map(ruler => ({ column: ruler })) : []
|
||||
enableRulers ? rulers.map(ruler => ({column: ruler})) : []
|
||||
|
||||
export default class CodeEditor extends React.Component {
|
||||
constructor (props) {
|
||||
@@ -268,7 +268,7 @@ export default class CodeEditor extends React.Component {
|
||||
|
||||
componentDidUpdate (prevProps, prevState) {
|
||||
let needRefresh = false
|
||||
const { rulers, enableRulers } = this.props
|
||||
const {rulers, enableRulers} = this.props
|
||||
if (prevProps.mode !== this.props.mode) {
|
||||
this.setMode(this.props.mode)
|
||||
}
|
||||
@@ -368,6 +368,7 @@ export default class CodeEditor extends React.Component {
|
||||
|
||||
handlePaste (editor, e) {
|
||||
const clipboardData = e.clipboardData
|
||||
const {storageKey, noteKey} = this.props
|
||||
const dataTransferItem = clipboardData.items[0]
|
||||
const pastedTxt = clipboardData.getData('text')
|
||||
const isURL = (str) => {
|
||||
@@ -377,22 +378,28 @@ export default class CodeEditor extends React.Component {
|
||||
const isInLinkTag = (editor) => {
|
||||
const startCursor = editor.getCursor('start')
|
||||
const prevChar = editor.getRange(
|
||||
{ line: startCursor.line, ch: startCursor.ch - 2 },
|
||||
{ line: startCursor.line, ch: startCursor.ch }
|
||||
{line: startCursor.line, ch: startCursor.ch - 2},
|
||||
{line: startCursor.line, ch: startCursor.ch}
|
||||
)
|
||||
const endCursor = editor.getCursor('end')
|
||||
const nextChar = editor.getRange(
|
||||
{ line: endCursor.line, ch: endCursor.ch },
|
||||
{ line: endCursor.line, ch: endCursor.ch + 1 }
|
||||
{line: endCursor.line, ch: endCursor.ch},
|
||||
{line: endCursor.line, ch: endCursor.ch + 1}
|
||||
)
|
||||
return prevChar === '](' && nextChar === ')'
|
||||
}
|
||||
if (dataTransferItem.type.match('image')) {
|
||||
const {storageKey, noteKey} = this.props
|
||||
attachmentManagement.handlePastImageEvent(this, storageKey, noteKey, dataTransferItem)
|
||||
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
|
||||
this.handlePasteUrl(e, editor, pastedTxt)
|
||||
}
|
||||
if (attachmentManagement.isAttachmentLink(pastedTxt)) {
|
||||
attachmentManagement.handleAttachmentLinkPaste(storageKey, noteKey, pastedTxt)
|
||||
.then((modifiedText) => {
|
||||
this.editor.replaceSelection(modifiedText)
|
||||
})
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
handleScroll (e) {
|
||||
@@ -487,7 +494,7 @@ export default class CodeEditor extends React.Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
const { className, fontSize } = this.props
|
||||
const {className, fontSize} = this.props
|
||||
let fontFamily = this.props.fontFamily
|
||||
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
|
||||
? [fontFamily].concat(defaultEditorFontFamily)
|
||||
|
||||
@@ -6,6 +6,7 @@ const mdurl = require('mdurl')
|
||||
const fse = require('fs-extra')
|
||||
const escapeStringRegexp = require('escape-string-regexp')
|
||||
const sander = require('sander')
|
||||
import i18n from 'browser/lib/i18n'
|
||||
|
||||
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
|
||||
const DESTINATION_FOLDER = 'attachments'
|
||||
@@ -286,7 +287,7 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
|
||||
if (fs.existsSync(attachmentFolder)) {
|
||||
fs.readdir(attachmentFolder, (err, files) => {
|
||||
if (err) {
|
||||
console.error('Error reading directory \'' + attachmentFolder + '\'. Error:')
|
||||
console.error('Error reading directory "' + attachmentFolder + '". Error:')
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
@@ -295,17 +296,17 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
|
||||
const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file)
|
||||
fs.unlink(absolutePathOfFile, (err) => {
|
||||
if (err) {
|
||||
console.error('Could not delete \'%s\'', absolutePathOfFile)
|
||||
console.error('Could not delete "%s"', absolutePathOfFile)
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
console.info('File \'' + absolutePathOfFile + '\' deleted because it was not included in the content of the note')
|
||||
console.info('File "' + absolutePathOfFile + '" deleted because it was not included in the content of the note')
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
console.debug('Attachment folder (\'' + attachmentFolder + '\') did not exist..')
|
||||
console.info('Attachment folder ("' + attachmentFolder + '") did not exist..')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +337,71 @@ function cloneAttachments (oldNote, newNote) {
|
||||
}
|
||||
}
|
||||
|
||||
function generateFileNotFoundMarkdown () {
|
||||
return '**' + i18n.__('⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠') + '**'
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a given text is a link to an boostnote attachment
|
||||
* @param text Text that might contain a attachment link
|
||||
* @return {Boolean} Result of the test
|
||||
*/
|
||||
function isAttachmentLink (text) {
|
||||
if (text) {
|
||||
return text.match(new RegExp('.*\\[.*\\]\\( *' + escapeStringRegexp(STORAGE_FOLDER_PLACEHOLDER) + escapeStringRegexp(path.sep) + '.*\\).*', 'gi')) != null
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Handles the paste of an attachment link. Copies the referenced attachment to the location belonging to the new note.
|
||||
* Returns a modified version of the pasted text so that it matches the copied attachment (resp. the new location)
|
||||
* @param storageKey StorageKey of the current note
|
||||
* @param noteKey NoteKey of the currentNote
|
||||
* @param linkText Text that was pasted
|
||||
* @return {Promise<String>} Promise returning the modified text
|
||||
*/
|
||||
function handleAttachmentLinkPaste (storageKey, noteKey, linkText) {
|
||||
if (storageKey != null && noteKey != null && linkText != null) {
|
||||
const storagePath = findStorage.findStorage(storageKey).path
|
||||
const attachments = getAttachmentsInContent(linkText) || []
|
||||
const replaceInstructions = []
|
||||
const copies = []
|
||||
for (const attachment of attachments) {
|
||||
const absPathOfAttachment = attachment.replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER, 'g'), path.join(storagePath, DESTINATION_FOLDER))
|
||||
copies.push(
|
||||
sander.exists(absPathOfAttachment)
|
||||
.then((fileExists) => {
|
||||
if (!fileExists) {
|
||||
const fileNotFoundRegexp = new RegExp('!?' + escapeStringRegexp('[') + '[\\w|\\d|\\s|\\.]*\\]\\(\\s*' + STORAGE_FOLDER_PLACEHOLDER + '[\\w|\\d|\\-|' + escapeStringRegexp(path.sep) + ']*' + escapeStringRegexp(path.basename(absPathOfAttachment)) + escapeStringRegexp(')'))
|
||||
replaceInstructions.push({regexp: fileNotFoundRegexp, replacement: this.generateFileNotFoundMarkdown()})
|
||||
return Promise.resolve()
|
||||
}
|
||||
return this.copyAttachment(absPathOfAttachment, storageKey, noteKey)
|
||||
.then((fileName) => {
|
||||
const replaceLinkRegExp = new RegExp(escapeStringRegexp('(') + ' *' + STORAGE_FOLDER_PLACEHOLDER + '[\\w|\\d|\\-|' + escapeStringRegexp(path.sep) + ']*' + escapeStringRegexp(path.basename(absPathOfAttachment)) + ' *' + escapeStringRegexp(')'))
|
||||
replaceInstructions.push({
|
||||
regexp: replaceLinkRegExp,
|
||||
replacement: '(' + path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName) + ')'
|
||||
})
|
||||
return Promise.resolve()
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
return Promise.all(copies).then(() => {
|
||||
let modifiedLinkText = linkText
|
||||
for (const replaceInstruction of replaceInstructions) {
|
||||
modifiedLinkText = modifiedLinkText.replace(replaceInstruction.regexp, replaceInstruction.replacement)
|
||||
}
|
||||
return modifiedLinkText
|
||||
})
|
||||
} else {
|
||||
console.log('One if the parameters was null -> Do nothing..')
|
||||
return Promise.resolve(linkText)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
copyAttachment,
|
||||
fixLocalURLS,
|
||||
@@ -349,6 +415,9 @@ module.exports = {
|
||||
deleteAttachmentsNotPresentInNote,
|
||||
moveAttachments,
|
||||
cloneAttachments,
|
||||
isAttachmentLink,
|
||||
handleAttachmentLinkPaste,
|
||||
generateFileNotFoundMarkdown,
|
||||
migrateAttachments,
|
||||
STORAGE_FOLDER_PLACEHOLDER,
|
||||
DESTINATION_FOLDER
|
||||
|
||||
@@ -151,5 +151,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -206,5 +206,6 @@
|
||||
"Rename": "Umbenennen",
|
||||
"Folder Name": "Ordnername",
|
||||
"No tags": "Keine Tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -175,5 +175,6 @@
|
||||
"Render newlines in Markdown paragraphs as <br>": "Render newlines in Markdown paragraphs as <br>",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -151,5 +151,6 @@
|
||||
"Only allow secure html tags (recommended)": "Solo permitir etiquetas html seguras (recomendado)",
|
||||
"Allow styles": "Permitir estilos",
|
||||
"Allow dangerous html tags": "Permitir etiquetas html peligrosas",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
}
|
||||
|
||||
@@ -154,5 +154,6 @@
|
||||
"Only allow secure html tags (recommended)": "(فقط تگ های امن اچ تی ام ال مجاز اند.(پیشنهاد میشود",
|
||||
"Allow styles": "حالت های مجاز",
|
||||
"Allow dangerous html tags": "تگ های خطرناک اچ تی ام ال مجاز اند",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
@@ -151,5 +151,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -175,5 +175,6 @@
|
||||
"Render newlines in Markdown paragraphs as <br>": "Az újsor karaktert <br> soremelésként jelenítse meg a Markdown jegyzetekben",
|
||||
"Allow styles": "Stílusok engedélyezése",
|
||||
"Allow dangerous html tags": "Veszélyes html tag-ek engedélyezése",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -154,5 +154,6 @@
|
||||
"Only allow secure html tags (recommended)": "Consenti solo tag HTML sicuri (raccomandato)",
|
||||
"Allow styles": "Consenti stili",
|
||||
"Allow dangerous html tags": "Consenti tag HTML pericolosi",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
}"
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -151,5 +151,6 @@
|
||||
"Only allow secure html tags (recommended)": "安全なHTMLタグのみ利用を許可する(推奨)",
|
||||
"Allow styles": "スタイルを許可する",
|
||||
"Allow dangerous html tags": "安全でないHTMLタグの利用を許可する",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -157,5 +157,6 @@
|
||||
"Only allow secure html tags (recommended)": "안전한 HTML 태그만 허용 (추천)",
|
||||
"Allow styles": "style 태그, 속성까지 허용",
|
||||
"Allow dangerous html tags": "모든 위험한 태그 허용",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -150,5 +150,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -150,5 +150,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -150,5 +150,6 @@
|
||||
"Only allow secure html tags (recommended)": "Permitir apenas tags html seguras (recomendado)",
|
||||
"Allow styles": "Permitir estilos",
|
||||
"Allow dangerous html tags": "Permitir tags html perigosas",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -150,5 +150,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -147,5 +147,6 @@
|
||||
"Editor Rulers": "Editor Rulers",
|
||||
"Enable": "Enable",
|
||||
"Disable": "Disable",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -149,5 +149,6 @@
|
||||
"Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)",
|
||||
"Allow styles": "Allow styles",
|
||||
"Allow dangerous html tags": "Allow dangerous html tags",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -206,5 +206,6 @@
|
||||
"Folder Name": "文件夹名称",
|
||||
"No tags":"无标签",
|
||||
"Render newlines in Markdown paragraphs as <br>":"在 Markdown 段落中使用 <br> 换行",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -149,5 +149,6 @@
|
||||
"Only allow secure html tags (recommended)": "只允許安全的 HTML 標籤 (建議)",
|
||||
"Allow styles": "允許樣式",
|
||||
"Allow dangerous html tags": "允許危險的 HTML 標籤",
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown."
|
||||
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
|
||||
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠"
|
||||
}
|
||||
|
||||
@@ -501,3 +501,239 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
||||
expect(findStorage.findStorage).not.toHaveBeenCalled()
|
||||
expect(sander.copyFileSync).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should test that isAttachmentLink works correctly', function () {
|
||||
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
||||
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf)')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + 'noteKey' + path.sep + 'pdf.pdf) test')).toBe(true)
|
||||
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then(() => {
|
||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePath, storageKey, newNoteKey)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(false))
|
||||
systemUnderTest.copyAttachment = jest.fn()
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then(() => {
|
||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
||||
expect(systemUnderTest.copyAttachment).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste copies multiple attachments if multiple were pasted', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then(() => {
|
||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathOne)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathTwo)
|
||||
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathOne, storageKey, newNoteKey)
|
||||
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathTwo, storageKey, newNoteKey)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyNewFileName = 'dummyNewFileName'
|
||||
const pasteText = 'text '
|
||||
const expectedText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyNewFileName))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedText)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if multiple links are posted', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyNewFileNameOne = 'dummyNewFileName'
|
||||
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const expectedText = 'text  ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn()
|
||||
systemUnderTest.copyAttachment.mockReturnValueOnce(Promise.resolve(dummyNewFileNameOne))
|
||||
systemUnderTest.copyAttachment.mockReturnValue(Promise.resolve(dummyNewFileNameTwo))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedText)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste calls the copy method correct if multiple links are posted where one file was found and one was not', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ..' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
||||
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
||||
|
||||
sander.exists = jest.fn()
|
||||
sander.exists.mockReturnValueOnce(Promise.resolve(false))
|
||||
sander.exists.mockReturnValue(Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then(() => {
|
||||
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathOne)
|
||||
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathTwo)
|
||||
expect(systemUnderTest.copyAttachment).toHaveBeenCalledTimes(1)
|
||||
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathTwo, storageKey, newNoteKey)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if the file was not found', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text '
|
||||
const storageKey = 'storageKey'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD
|
||||
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
||||
sander.exists = jest.fn(() => Promise.resolve(false))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedPastText)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if multiple files were not found', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const pasteText = 'text  ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
||||
|
||||
sander.exists = jest.fn(() => Promise.resolve(false))
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedPastText)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if one file was found and one was not found', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyFoundFileName = 'dummyFileName'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
||||
|
||||
sander.exists = jest.fn()
|
||||
sander.exists.mockReturnValueOnce(Promise.resolve(false))
|
||||
sander.exists.mockReturnValue(Promise.resolve(true))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyFoundFileName))
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedPastText)
|
||||
})
|
||||
})
|
||||
|
||||
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if one file was found and one was not found', function () {
|
||||
const dummyStorage = {path: 'dummyStoragePath'}
|
||||
findStorage.findStorage = jest.fn(() => dummyStorage)
|
||||
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
||||
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
||||
const dummyFoundFileName = 'dummyFileName'
|
||||
const fileNotFoundMD = 'file not found'
|
||||
const pasteText = 'text  .. ' +
|
||||
''
|
||||
const storageKey = 'storageKey'
|
||||
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
||||
|
||||
sander.exists = jest.fn()
|
||||
sander.exists.mockReturnValueOnce(Promise.resolve(true))
|
||||
sander.exists.mockReturnValue(Promise.resolve(false))
|
||||
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyFoundFileName))
|
||||
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
||||
|
||||
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
||||
.then((returnedPastedText) => {
|
||||
expect(returnedPastedText).toBe(expectedPastText)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user