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

New plugin: Ipynb preview as Markdown entry #8881

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

valentinbarral
Copy link
Contributor

  • I'm the package's author and/or maintainer.
  • I have have read the docs.
  • I have tagged a release with a semver version number.
  • My package repo has a description and a README describing what it's for and how to use it.
  • My package doesn't add context menu entries. *
  • My package doesn't add key bindings. **
  • Any commands are available via the command palette.
  • Preferences and keybindings (if any) are listed in the menu and the command palette, and open in split view.
  • If my package is a syntax it doesn't also add a color scheme. ***
  • If my package is a syntax it is named after the language it supports (without suffixes like "syntax" or "highlighting").
  • I use .gitattributes to exclude files from the package: images, test files, sublime-project/workspace.

My package is Ipynb preview as Markdown. There is almost no package that handles Jupyter notebooks in ST. This one generates a human-readable (non editable) preview of the notebook, in case you want to read it inside ST or copy the text or source code without having to launch the Jupyter environment.

There are no packages like it in Package Control.

Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Repo link: Ipynb Preview as Markdown

Packages added:
  - Ipynb Preview as Markdown

Processing package "Ipynb Preview as Markdown"
  - All checks passed

@braver
Copy link
Collaborator

braver commented Feb 28, 2024

Nice, looks good 👍🏻

You say it opens in split view, which in Sublime Text usually means one pane on the left, one on the right. But from your code it looks like it will actually open an output panel. Which would also be better IMO, as it won't affect the user's current layout :) Although your readme does imply left/right layout. Maybe I'm just reading it incorrectly (I don't have any ipynb files)?

repository/i.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@packagecontrol-bot packagecontrol-bot left a comment

Choose a reason for hiding this comment

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

Automated testing result: SUCCESS

Repo link: Ipynb Preview as Markdown

Packages added:
  - Ipynb Preview as Markdown

Processing package "Ipynb Preview as Markdown"
  - All checks passed

@braver braver added the mergeable The PR is in a mergeable state but awaiting some final comments/acknowledgement from either side label Feb 29, 2024
@jwortmann
Copy link
Contributor

jwortmann commented Feb 29, 2024

Hello, just a few suggestions (not required for accepting the package to Package Control, but maybe they would be possible improvements for the package):

  • This part of the code

          else:
              sublime.error_message("The current file is not an .ipynb file.")

    could be replaced for example by using a sublime_plugin.TextCommand and adding

    def is_enabled(self, **kwargs):
        file_name = self.view.file_name()
        return file_name and file_name.endswith('.ipynb')

    Then the command would only be active for relevant files.

  • The .ipynb file format (Jupyter Notebook) is not exclusively for Python code. For more flexibility you could for example add an optional command argument which would allow to set the language, like

    class PreviewIpynbAsMarkdownCommand(sublime_plugin.TextCommand):
        def run(self, edit, language='python'):
            # ...
            markdown_content += '```{}\n'.format(language) + ''.join(cell['source']) + '\n```\n\n'
  • If you would be okay with dropping support for Sublime Text 2/3 ("sublime_text": ">=4000"), you could experiment to use the mdpopups dependency in order to render the notebook content as a HtmlSheet, instead of a normal Markdown file. This may look a bit nicer for displaying the Markdown cells as Html and mdpopups also has direct support for the fenced code blocks, including syntax highlighting.
    https://facelessuser.github.io/sublime-markdown-popups/api/#new-html-sheet

@valentinbarral
Copy link
Contributor Author

Hi,
I have adapted part of your comments @jwortmann . Now the plugin uses TextCommands that are only activated if the file format is correct. Now it also checks the language used in the source code cells, to use the same in the preview.

I have also added some extra functionality, such as the possibility to hide the source code cells or the cells containing the output after a run. Regarding the cells with results, when these have images they are saved in the notebook in Base64 format, which messed up the preview if they were added that way directly. So I have made those images to be saved to files in the temp directory and referenced in the markdown as any image.

@braver
Copy link
Collaborator

braver commented Mar 8, 2024

Nice work 👍🏻

@braver braver merged commit 5d3209b into wbond:master Mar 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback provided mergeable The PR is in a mergeable state but awaiting some final comments/acknowledgement from either side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants