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

Add preview for .ipynb files in pl-file-preview #9840

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

kurmasz
Copy link
Contributor

@kurmasz kurmasz commented May 10, 2024

Added a workspace preview for .ipynb files in the pl-file-preview using notebookjs.
Notebookjs uses DOMpurify to sanitize the rendered markdown.
Future work could include:

Better styling of the markdown
Adding syntax highlighting
Adding a button to hide the Markdown blocks (assuming most instructors primarily care about the code blocks).
https://github.com/jsvine/notebookjs

Comment on lines +6 to +7
"marked/marked.min.js",
"notebookjs/notebook.min.js"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not be loading these unconditionally if there is no notebook to preview; that's a waste of CPU/bandwidth. I'd recommend using dynamicDependencies as documented here: https://prairielearn.readthedocs.io/en/latest/devElements/. Then you can import() them only when there is actually a .ipynb file to preview.

Comment on lines +3 to +9
// Note about notebookjs: I'm not thrilled with how notebook and marked are styling the
// Markdown. Unfortunately, I don't have the design skills to make it any better than
// it is right now. Perhaps somebody else can pick up where I left off and make improvements.
// Similarly, it might be nice to have syntax highlighting for the code blocks; but, that is
// also a task for another day.
// One last idea: Do we want a "hide markdown" button (assuming that it is usually the code
// blocks that are of interest to most instructors)?
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking comments that way "I" or "should we" shouldn't be committed. You can rephrase the first paragraph to read something like "The notebook styling is less than ideal, etc. etc.". You can add a // TODO comment for syntax highlighting if you think it's important. I don't think a "hide markdown" button is necessary now.

yarn.lock Outdated
@@ -11413,6 +11444,40 @@ __metadata:
languageName: node
linkType: hard

"jsdom@npm:^23.2.0":
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unfortunate that this pulls in a version of jsdom that's effectively unused; this leaves us with an extra 4MB of dependencies to ship around. I'm wondering if we could resolve this with Yarn resolutions: https://yarnpkg.com/configuration/manifest#resolutions

I'm happy to try out this change and push it to your branch if that's OK with you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm good with that.
I'll fix the first two issues Tuesday or Wednesday.

@nwalters512 nwalters512 changed the title Add workspace preview for .ipynb files in pl-file-preview using notebookjs (take 2) Add preview for .ipynb files in pl-file-preview May 17, 2024
Copy link

codecov bot commented May 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.43%. Comparing base (fffa876) to head (f798969).

Current head f798969 differs from pull request most recent head 410e5c3

Please upload reports for the commit 410e5c3 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9840      +/-   ##
==========================================
+ Coverage   66.41%   66.43%   +0.01%     
==========================================
  Files         453      453              
  Lines       70289    70289              
  Branches     5645     5644       -1     
==========================================
+ Hits        46681    46694      +13     
+ Misses      23184    23171      -13     
  Partials      424      424              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

None yet

2 participants