-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement markdown cell attachments. Allow drag’n’drop of images into… #621
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3462b34
Implement markdown cell attachments. Allow drag’n’drop of images into…
julienr 398c90b
Use the cell ‘attachments’ property instead of ‘metadata.attachments’.
julienr 3414b83
Insert markdown markup for attachments images instead of HTML
julienr 1c6f589
Add attachments cell toolbar option which opens a metadata-like JSON …
julienr 13bcdc9
Keep the attachments even if the cell type changes
julienr 480c90e
Refactor the inline image drop logic. Preliminary copy/paste support.
julienr 22fccff
Add a new insert-image action and corresponding dialog to insert inli…
julienr c4bd66e
Nicer attachments editing dialog
julienr b21348f
Attachments dialog only apply deletion on ‘Apply’.
julienr e66ff8f
Fix drag/drop event handler to be compatible with codemirror 5.8, which
julienr 646619d
Check that we have items in markdown cell paste handler
865de47
Add Cut/Copy/Paste Cell attachments menu items
6cc468d
Add tests for attachments insert menuitem
aa460ff
Fix speed issues when attaching large images
c012835
Fix 'insert-image' menu item toggling. Instead of disabling the menui…
84f38c2
Make attachments textcell-specific
ac9a345
Bump nbformat minor to 4.1 to support attachments
c8266aa
Fix cell attachments copy/paste
a0920c4
Simplify attachments handling code by having an attachment attribute …
julienr c7186d5
Remove unused attachments on manual save
julienr ea57ff7
Explain why we disable caja uri checks on img::src
cc58b28
Remove jquery from dependencies since it’s a global
julienr 51cab51
Add Copy/Paste cell attachments test
julienr f50474d
Add test for attachments garbage collection
julienr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
notebook/static/notebook/js/celltoolbarpresets/attachments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
define([ | ||
'notebook/js/celltoolbar', | ||
'base/js/dialog', | ||
], function(celltoolbar, dialog) { | ||
"use strict"; | ||
|
||
var CellToolbar = celltoolbar.CellToolbar; | ||
|
||
var edit_attachments_dialog = function(cell) { | ||
dialog.edit_attachments({ | ||
attachments: cell.attachments, | ||
callback: function(attachments) { | ||
cell.attachments = attachments; | ||
// Force cell refresh | ||
cell.unrender(); | ||
cell.render(); | ||
}, | ||
name: 'cell', | ||
notebook: cell.notebook, | ||
keyboard_manager: cell.keyboard_manager | ||
}); | ||
}; | ||
|
||
var add_dialog_button = function(div, cell) { | ||
var button_container = $(div); | ||
var button = $('<button />') | ||
.addClass('btn btn-default btn-xs') | ||
.text('Edit Attachments') | ||
.click( function() { | ||
edit_attachments_dialog(cell); | ||
return false; | ||
}); | ||
button_container.append(button); | ||
}; | ||
|
||
var register = function(notebook) { | ||
CellToolbar.register_callback('attachments.edit', add_dialog_button); | ||
|
||
var attachments_preset = []; | ||
attachments_preset.push('attachments.edit'); | ||
|
||
CellToolbar.register_preset('Attachments', attachments_preset, notebook); | ||
console.log('Attachments editing toolbar loaded.'); | ||
|
||
}; | ||
return {'register' : register} | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this removes a security check, we need to make sure that there are no possible
img.src
attributes that can execute javascript on any supported browser before we can allow this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The good solution would be to only allow
data
uris (and disallowjavascript:
uri). Unfortunately, it seems that caja has hardcoded allowed uri schemes (anddata
is not included):https://github.com/minrk/google-caja-bower/blob/master/html-sanitizer.js#L813
Should I just monkey patch
caja.html.ALLOWED_URI_SCHEMES
to allow data uris ?There is an open issue on caja on this subject, but it doesn't seem very alive :
googlearchive/caja#1558
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a bit of reading, I believe this is not an issue on any supported browser. Can you make a note here that img:src is safe on browsers post ie6?