Skip to content

Commit d3091a5

Browse files
authored
Merge branch 'master' into Moving_Note_With_Attachment
2 parents f10fa63 + 2a6d950 commit d3091a5

File tree

15 files changed

+95
-7
lines changed

15 files changed

+95
-7
lines changed

browser/components/MarkdownEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class MarkdownEditor extends React.Component {
283283
indentSize={editorIndentSize}
284284
scrollPastEnd={config.preview.scrollPastEnd}
285285
smartQuotes={config.preview.smartQuotes}
286+
breaks={config.preview.breaks}
286287
sanitize={config.preview.sanitize}
287288
ref='preview'
288289
onContextMenu={(e) => this.handleContextMenu(e)}

browser/components/MarkdownPreview.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ export default class MarkdownPreview extends React.Component {
145145
}
146146

147147
initMarkdown () {
148-
const { smartQuotes, sanitize } = this.props
148+
const { smartQuotes, sanitize, breaks } = this.props
149149
this.markdown = new Markdown({
150150
typographer: smartQuotes,
151-
sanitize
151+
sanitize,
152+
breaks
152153
})
153154
}
154155

@@ -340,7 +341,9 @@ export default class MarkdownPreview extends React.Component {
340341

341342
componentDidUpdate (prevProps) {
342343
if (prevProps.value !== this.props.value) this.rewriteIframe()
343-
if (prevProps.smartQuotes !== this.props.smartQuotes || prevProps.sanitize !== this.props.sanitize) {
344+
if (prevProps.smartQuotes !== this.props.smartQuotes ||
345+
prevProps.sanitize !== this.props.sanitize ||
346+
prevProps.breaks !== this.props.breaks) {
344347
this.initMarkdown()
345348
this.rewriteIframe()
346349
}
@@ -599,5 +602,6 @@ MarkdownPreview.propTypes = {
599602
value: PropTypes.string,
600603
showCopyNotification: PropTypes.bool,
601604
storagePath: PropTypes.string,
602-
smartQuotes: PropTypes.bool
605+
smartQuotes: PropTypes.bool,
606+
breaks: PropTypes.bool
603607
}

browser/components/MarkdownSplitEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class MarkdownSplitEditor extends React.Component {
131131
lineNumber={config.preview.lineNumber}
132132
scrollPastEnd={config.preview.scrollPastEnd}
133133
smartQuotes={config.preview.smartQuotes}
134+
breaks={config.preview.breaks}
134135
sanitize={config.preview.sanitize}
135136
ref='preview'
136137
tabInde='0'

browser/lib/markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Markdown {
2525
linkify: true,
2626
html: true,
2727
xhtmlOut: true,
28-
breaks: true,
28+
breaks: config.preview.breaks,
2929
highlight: function (str, lang) {
3030
const delimiter = ':'
3131
const langInfo = lang.split(delimiter)

browser/main/lib/ConfigManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const DEFAULT_CONFIG = {
5656
plantUMLServerAddress: 'http://www.plantuml.com/plantuml',
5757
scrollPastEnd: false,
5858
smartQuotes: true,
59+
breaks: true,
5960
sanitize: 'STRICT' // 'STRICT', 'ALLOW_STYLES', 'NONE'
6061
},
6162
blog: {

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const findStorage = require('browser/lib/findStorage')
55
const mdurl = require('mdurl')
66
const fse = require('fs-extra')
77
const escapeStringRegexp = require('escape-string-regexp')
8+
const sander = require('sander')
89

910
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
1011
const DESTINATION_FOLDER = 'attachments'
@@ -213,6 +214,17 @@ function removeStorageAndNoteReferences (input, noteKey) {
213214
return input.replace(new RegExp(mdurl.encode(path.sep), 'g'), path.sep).replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey, 'g'), DESTINATION_FOLDER)
214215
}
215216

217+
/**
218+
* @description Deletes the attachment folder specified by the given storageKey and noteKey
219+
* @param storageKey Key of the storage of the note to be deleted
220+
* @param noteKey Key of the note to be deleted
221+
*/
222+
function deleteAttachmentFolder (storageKey, noteKey) {
223+
const storagePath = findStorage.findStorage(storageKey)
224+
const noteAttachmentPath = path.join(storagePath.path, DESTINATION_FOLDER, noteKey)
225+
sander.rimrafSync(noteAttachmentPath)
226+
}
227+
216228
/**
217229
* @description Deletes all attachments stored in the attachment folder of the give not that are not referenced in the markdownContent
218230
* @param markdownContent Content of the note. All unreferenced notes will be deleted
@@ -265,6 +277,7 @@ module.exports = {
265277
getAttachmentsInContent,
266278
getAbsolutePathsOfAttachmentsInContent,
267279
removeStorageAndNoteReferences,
280+
deleteAttachmentFolder,
268281
deleteAttachmentsNotPresentInNote,
269282
moveAttachments,
270283
STORAGE_FOLDER_PLACEHOLDER,

browser/main/lib/dataApi/deleteNote.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const resolveStorageData = require('./resolveStorageData')
22
const path = require('path')
33
const sander = require('sander')
4+
const attachmentManagement = require('./attachmentManagement')
45
const { findStorage } = require('browser/lib/findStorage')
56

67
function deleteNote (storageKey, noteKey) {
@@ -25,6 +26,10 @@ function deleteNote (storageKey, noteKey) {
2526
storageKey
2627
}
2728
})
29+
.then(function deleteAttachments (storageInfo) {
30+
attachmentManagement.deleteAttachmentFolder(storageInfo.storageKey, storageInfo.noteKey)
31+
return storageInfo
32+
})
2833
}
2934

3035
module.exports = deleteNote

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class UiTab extends React.Component {
9797
plantUMLServerAddress: this.refs.previewPlantUMLServerAddress.value,
9898
scrollPastEnd: this.refs.previewScrollPastEnd.checked,
9999
smartQuotes: this.refs.previewSmartQuotes.checked,
100+
breaks: this.refs.previewBreaks.checked,
100101
sanitize: this.refs.previewSanitize.value
101102
}
102103
}
@@ -476,6 +477,16 @@ class UiTab extends React.Component {
476477
Enable smart quotes
477478
</label>
478479
</div>
480+
<div styleName='group-checkBoxSection'>
481+
<label>
482+
<input onChange={(e) => this.handleUIChange(e)}
483+
checked={this.state.config.preview.breaks}
484+
ref='previewBreaks'
485+
type='checkbox'
486+
/>&nbsp;
487+
Render newlines in Markdown paragraphs as &lt;br&gt;
488+
</label>
489+
</div>
479490

480491
<div styleName='group-section'>
481492
<div styleName='group-section-label'>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@rokt33r/season": "^5.3.0",
5454
"aws-sdk": "^2.48.0",
5555
"aws-sdk-mobile-analytics": "^0.9.2",
56-
"codemirror": "^5.19.0",
56+
"codemirror": "^5.37.0",
5757
"codemirror-mode-elixir": "^1.1.1",
5858
"electron-config": "^0.2.1",
5959
"electron-gh-releases": "^2.0.2",

tests/dataApi/attachmentManagement.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jest.mock('unique-slug')
88
const uniqueSlug = require('unique-slug')
99
const mdurl = require('mdurl')
1010
const fse = require('fs-extra')
11+
const sander = require('sander')
1112

1213
const systemUnderTest = require('browser/main/lib/dataApi/attachmentManagement')
1314

@@ -262,6 +263,19 @@ it('should remove the all ":storage" and noteKey references', function () {
262263
expect(actual).toEqual(expectedOutput)
263264
})
264265

266+
it('should delete the correct attachment folder if a note is deleted', function () {
267+
const dummyStorage = {path: 'dummyStoragePath'}
268+
const storageKey = 'storageKey'
269+
const noteKey = 'noteKey'
270+
findStorage.findStorage = jest.fn(() => dummyStorage)
271+
sander.rimrafSync = jest.fn()
272+
273+
const expectedPathToBeDeleted = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, noteKey)
274+
systemUnderTest.deleteAttachmentFolder(storageKey, noteKey)
275+
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
276+
expect(sander.rimrafSync).toHaveBeenCalledWith(expectedPathToBeDeleted)
277+
})
278+
265279
it('should test that deleteAttachmentsNotPresentInNote deletes all unreferenced attachments ', function () {
266280
const dummyStorage = {path: 'dummyStoragePath'}
267281
const noteKey = 'noteKey'

0 commit comments

Comments
 (0)