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

Link to HTML/Image not rendering properly #506

Open
erykml opened this issue Mar 19, 2022 · 5 comments
Open

Link to HTML/Image not rendering properly #506

erykml opened this issue Mar 19, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@erykml
Copy link

erykml commented Mar 19, 2022

What happened?

Hi, first of all, great job with the library!
Coming back to the issue at hand, the links to HTML outputs (DataFrames) and Images do not work.
I have tried the default MacOS terminal, iterm2, and the terminal integrated into VS Code.
All of them look like the sample provided in the output field.
It happens with all the Notebooks I have (also saved using Jupyter Notebook and not VS Code).

nbpreview version

nbpreview 0.8.1

Output

8;id=410413;file:///var/folders/jg/42cx8xxn6_s1kcdc594gmf_w0000gn/T/tmprg7rbhah.html🌐 Click to view HTML8;;

Notebook

No response

OS

macos

Terminal

terminal/vs code terminal

Python version

Python 3.8.10

@erykml erykml added the bug Something isn't working label Mar 19, 2022
@paw-lu
Copy link
Owner

paw-lu commented Mar 20, 2022

Hey @erykml, thanks for the report!

To be clear I expect hyperlinks to only work on supported terminals. To my knowledge, the default macOS terminal and integrated VSCode temrinal do not support hyperlinks. But iTerm2 >3.1 absolutely should (it's what I use).

Regardless of what terminal you use, I am surprised that you are getting that output though. It looks like nbpreview is actually doing what I want it to do, you can see that type of pattern as the expected output in the unit tests. But, I expected your terminal to format it nicely for you. For example, this is what it looks like on my machine when I try to render a link using macOS's default terminal. There is no clickable hyperlink, but I don't get the long path text you do.

Screen Shot 2022-03-19 at 10 14 47 PM

So right now:

  1. It's unexpected that hyperlinks are not rendering on iTerm2 for you
  2. It's unexpected that you are getting these ugly long paths instead of your terminal hiding it from you

Debugging

  • Are you using an up-to-date iTerm2, I think 3.1 is the version that added hyperlink support

  • What happens if you try to render any hyperlink to both of your terminals?
    One quick way to check this.

    % python -m venv .venv
    % source .venv/bin/activate
    % python -m pip install rich
    % python -m rich.markdown --hyperlinks <(echo '[Click me](https://github.com/paw-lu/nbpreview/issues/506)')

Temporary fix

This won't fix the hyperlink problem at all, but to make it less of an eyesore for now you can pass --no-hyperlinks to have nbpreview print out the entire path name, which you can click on in some terminals like VSCode, or --no-files to keep nbpreview to disable the feature all together. Both of these can be configured more permenantly by setting their respective enrivonmental variables NBPREVIEW_HYPERLINKS=0 or NBPREVIEW_NO_FILES=1.

@erykml
Copy link
Author

erykml commented Mar 20, 2022

Hi @paw-lu!

Thanks for the very fast answer! To answer your questions in order:

  • I am using iterm2 3.4.15 and rich-10.16.2
  • I have the built-in powerglyphs enabled (tried disabling, but the issue is still there)
  • when I execute the code you provided, I do have a nicely formatted and clickable link

Hopefully, this will help with narrowing down the issue! And thanks for the temporary fix :)

@paw-lu
Copy link
Owner

paw-lu commented Mar 21, 2022

Thanks @erykml for helping me out with debugging!

New theory is that it's your pager. Are you using a custom pager (ie not less) or special commands?

Verify

To veriy that this is a pager issue. We can prevent nbpreview by writing to your pager with --no-paging.

% nbpreview --no-paging notebook.ipynb

If the issue has to do with your pager, then you should get working hyperlinks (on iTerm2 at least).

Debug

What do you have set for PAGER or other environmental variables that affect paging (like LESS).

% echo $PAGER

% echo $LESS

New fixes

Disabling paging

Like we mentioned above, you can use the --no-paging to diable nbpreview from outputting to your pager. Or set NBPREVIEW_PAGING=0 for a more permanent config.

Set a new pager

Set a pager that can interpret the escape codes given. Does less -r work for you?

% PAGER='less -r' nbpreview --paging notebook.ipynb

@erykml
Copy link
Author

erykml commented Mar 21, 2022

Hi @paw-lu,

No worries, happy to help!

Let me answer in order.

  1. Using the --no-paging flag works -> the links are clickable and nicely formatted + there is no looping behavior.
  2. after running the two commands, I get less and -R respectively.
  3. Running PAGER='less -r' nbpreview --paging notebook.ipynb works as well.

So based on those, seems like the pager is indeed at fault. Thanks for helping me out with this issue!

@paw-lu
Copy link
Owner

paw-lu commented Mar 22, 2022

So based on those, seems like the pager is indeed at fault.

Eh, the issue is the pager, but I didn't expect you to have such a standard setup. I suspeceted you might be using some exotic pager, but your setup is what 98% of users will have. It's identical to what I have actually. I was hoping nbpreview would just work on setups like this.

Regardless, to be explict—for you and future users—you can fix this problem permentantly by setting PAGER in your startupfiles (.bashrc, .zshrc, .zshenv, .bash_profile, etc).

export PAGER='less -r'

This will also help with other clis as well.

But this is a pretty frustrating first-impression for a standard setup. Let's keep this open for now to see if we can measure how common this is.

Wonder if you have an older version of less? Kinda grasping at straws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants