-
Notifications
You must be signed in to change notification settings - Fork 201
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
✨ IMPROVE: Styling print to pdf #438
Conversation
thanks @AakashGfude the new The link to the |
Thanks @mmcky , should be working now. |
Just some thoughts:
|
Good idea. We can also style the margin to include it in the main content instead of in the side, and stylize it in a way to make it look like a note?
Working on this. |
It seems like as long as there is a title tag on the button:
the Even trying to detach the
Here, |
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.
This is a nice improvement! I have a few thoughts in there about simplifying the codebase a little bit, but in general I think this is close.
The "print to PDF" thing is annoying, though already present in the theme (I didn't notice that before), so I don't think it should block this PR. Though @AakashGfude if you can figure out how to avoid it, that would be fantastic. Note that I believe this is using bootstrap-native tooltips, so maybe those docs will have helpful pointers: https://getbootstrap.com/docs/4.0/components/tooltips/
sphinx_book_theme/layout.html
Outdated
@@ -20,7 +20,25 @@ | |||
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main"> | |||
{% block docs_body %} | |||
{% include "topbar.html" %} | |||
<div id="main-content" class="row"> | |||
<h1 class="onlyprint">{{ pagetitle }}</h1> |
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.
Why don't we just wrap all of this in a div like <div id="jb-print-wrapper" class="onlyprint">
? I feel like that'd be the most obvious to understand and then we only need one onlyprint
in there
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.
If this were the case, could we just put the TOC code:
in a standalone html
file, and then import it there and here, so we don't repeat ourselves?
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.
@choldgraf there is a bit of difference in classes between the toc in print and non-print.
sphinx_book_theme/layout.html
Outdated
<div> | ||
<h2> {{ translate(theme_toc_title) }} </h2> | ||
</div> | ||
<nav aria-label="Page"> |
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.
we probably don't need aria labels and such because this is being printed to PDF, so screen readers won't make sense, right?
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.
@choldgraf these lectures, I reckon, can also be just downloaded as PDF and read on a computer or tablet offline instead of printing it in particular? In which case, screen readers would be important. Not sure, if this HTML tag translates to pdf output as well though.
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.
I'm not sure either - but if we think it might help folks with a11y issues, let's just leave it in!
Note that I believe this is using bootstrap-native tooltips, so maybe those docs will have helpful pointers: https://getbootstrap.com/docs/4.0/components/tooltips/ Thank you @choldgraf for the link. Though I could not find any resource to remove it in a boostrapy way. But I did get the element ids. I am detaching them from the DOM just before calling |
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.
Just a couple quick comments, this looks nice!
</div> | ||
</div> | ||
</div> | ||
<div id="main-content" class="row noprint"> |
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.
I'm confused - wouldn't this mean that the whole #main-content
div doesn't show up when printing?
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.
This #main-content won't, but this one will https://github.com/executablebooks/sphinx-book-theme/pull/438/files#diff-6cf877d43a0155d9e3706cb22f143f326d4283458bfdcac93017b197c4f02e2bR27 . Looking at this now, i should rename the id of onlyprint
one to something else, as there are two main-content
ids at one time in this page.
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.
or maybe convert main-content
to a class
name instead of id
?
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.
hmmm - it seems reasonable to use a unique ID for the print-only header. That seems like a smaller change than converting it from an ID to a class, IMO
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.
Fair enough. Changed them to individual ids.
Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
@choldgraf this looks ready to go I think, if there are no further comments. |
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.
I lost track of this one, but thanks @AakashGfude for the improvements! Let's iterate in subsequent PRs if we find other improvements to make.
The following PR aims to change the structure and styling of single page documents when printing using "Print to PDF" functionality of jb. It primarily relies on two css classes for defining structure(showing, hiding elements from the dom) -
onlyprint
andnoprint
.Output from this PR looks like this:
Store code outputs and insert into content.pdf
The above document's content is from https://jupyterbook.org/content/executable/output-insert.html
Will keep updating the output picture and document here, as we push more changes.
EDIT 1: increased the width content, and handled margin directive as shown in the pic above.
cc: @rowanc1 @damianavila @mmcky