Skip to content
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

Improved attachments +fix supporting non-unique names #980

Merged
merged 9 commits into from
Apr 5, 2019

Conversation

maartenbreddels
Copy link
Collaborator

Via voila-dashboards/voila#16 we found out that nbconvert does not handle attachments correctly when they have the same name.
With the new attachment notebook, the old result gave:
image
While this fix gives:
image

The fix works as following:

  • for every attachment, give them a globally unique name, by prefixing with globally_unique_{cell_index}
  • replace markdown source by replacing e.g. ](attachment:image.png) by ](attachment:globally_unique_2_image.png)

The last point might lead to unexpected results if somehow the markdown source include that 'magic' string. However, that would currently already break, because

output = output.replace(
would do an even less restricted replacement.

@@ -87,7 +89,29 @@ def process_attachments(self, nb, output):
'data:' + att_type + ';base64, ' + attachment[att_type])
return output

def _make_attachments_globally_unique(self, nb):
nb = copy.deepcopy(nb)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do a copy, or can we modify in place?

@maartenbreddels maartenbreddels changed the title FIX: support attachments with non-unique names WIP: FIX: support attachments with non-unique names Apr 5, 2019
@maartenbreddels
Copy link
Collaborator Author

I think this can be done more elegantly, for backtracking, the initial start was in #780

@maartenbreddels maartenbreddels changed the title WIP: FIX: support attachments with non-unique names Improved attachments supporting non-unique names Apr 5, 2019
@maartenbreddels maartenbreddels changed the title Improved attachments supporting non-unique names Improved attachments +fix supporting non-unique names Apr 5, 2019
@maartenbreddels
Copy link
Collaborator Author

I think this implementation for attachments is much cleaner, since it know about it's context (the cell), so the attachments refer to the cell's attachment, avoiding name collisions (bug exposed by one of the untitests).

This also will be less error prone, since no string replacement or regex-fu is used. This approach also makes embedding images much more easy compared to this approach which is something we need for voila.

@MSeal would love to see this in the next release, so we can push voila forward, happy to iterate on this quickly.

Copy link
Contributor

@MSeal MSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MSeal MSeal merged commit 8b28bfc into jupyter:master Apr 5, 2019
@maartenbreddels maartenbreddels deleted the fix_non_unique_attachments branch April 5, 2019 17:59
@SylvainCorlay
Copy link
Member

Looking forward with a release including that fix!

@MSeal
Copy link
Contributor

MSeal commented Apr 10, 2019

Got a few hanging PRs, then we should be set to release. Some reviews of the PRs I have open would help speed it up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants