Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport ebooks and pdf export #88
Comments
azerupi
added
Feature Request
labels
Dec 30, 2015
This comment has been minimized.
This comment has been minimized.
|
I would like to support pdf and ebook format. I think this could already be developed out of tree if you use the Renderer trait from mdBook. I am not sure I want to depend on a full blown Gui tool though. There must surely be a better alternative for that. |
This comment has been minimized.
This comment has been minimized.
|
Not familiar with many conversion tools like this. Pandoc also seems like a plausible option. Don't know of any others. |
This comment has been minimized.
This comment has been minimized.
|
Yeah pandoc seems a lot better! |
azerupi
added
Status: Wishlist
and removed
Status: Feature Request
labels
Jan 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Did some exploration on this and seems doable. Here's the default epub version of the Rust book. Note the chapters out of order and links not working. To get good output, I think we would need to:
I'm interested in working on this but will be a bit slow. Useful info here: Pandoc commands and styling options |
This comment has been minimized.
This comment has been minimized.
killercup
commented
Jan 11, 2016
@asolove, I have implemented this (among other transformations) in https://github.com/killercup/trpl-ebook, feel free to use my code. |
This comment has been minimized.
This comment has been minimized.
|
@killercup great, thanks! |
This comment has been minimized.
This comment has been minimized.
|
Great! Thanks for doing this :)
This is already done in the Rust code, the
Concatenating the markdown files is also not that hard, I do it for the print page. Replacing the links could be a little trickier, what should internal links look like for pandoc? I know that pulldown-cmark gives you the ability to transform the parsed markdown events before rendering, but it's not well documented. Maybe link replacing is in it's capabilities. Static files, like images, will probably also need some special treatment to be included correctly?
That is absolutely no problem, there is no rush. I am also planning on doing a big refactor (#90) to clean up and create a better API. For example, I am thinking about adding a way to poll the |
This comment has been minimized.
This comment has been minimized.
killercup
commented
Jan 11, 2016
FIY, I'm doing some regex work to transform links relative to the doc.rust-lang.org domain and make reference link names unique for the combined markdown file. |
This comment has been minimized.
This comment has been minimized.
Thanks! Does pandoc auto-generate the anchors from the markdown files in those formats? like |
This comment has been minimized.
This comment has been minimized.
killercup
commented
Jan 11, 2016
|
@azerupi I'm pretty sure pandoc generates those. I've had problems before because pandoc generates slugs in a different way than rustdoc. It should be possible to add a specific id to each header, though. The syntax is You might also want to look at adjust_header_level.rs and adjust_reference_names.rs. |
This comment has been minimized.
This comment has been minimized.
|
Ok thanks for all the information, this will probably help @asolove a lot! :) |
This comment has been minimized.
This comment has been minimized.
|
Not sure if this will help you guys, but I've created a simple rust tool which will collate multiple markdown files into one, resolving internal links and turning them into anchor links We can use this in a pipeline on the way to converting to PDF:
Code can be found here: Happy to accept any PRs |
azerupi
added
Status: Claimed
and removed
Status: Wishlist
labels
Jan 12, 2016
This comment has been minimized.
This comment has been minimized.
|
@cetra3 That is really cool! I am not sure I would add a dependency just for that functionality, because there is always the possibility that it will not be maintained actively. But it could be considered if it offers enough useful methods that we wouldn't have to reinvent here. |
This comment has been minimized.
This comment has been minimized.
mkpankov
commented
Jan 12, 2016
|
I'm also sceptical about Calibre. We use it in Russian translation of TRPL and we've come along several problems with EPUB (links are to descriptions in Russian, for reference):
|
This comment has been minimized.
This comment has been minimized.
|
Thanks for sharing your experience :)
I am not sure how this is handled with Pandoc, but having a custom theme could be a good thing. |
This comment has been minimized.
This comment has been minimized.
|
It's probably possible to wrap up those command line tools into a combined tool or expose it as a rust library. The last component (html to pdf) would need to use FFI as The complication arises in that markdown is a superset of HTML which means that you need something that can present HTML in a printable fashion. In my experience with this problem, Pandoc and Calibre will do a subset, but you won't get full parity. |
This comment has been minimized.
This comment has been minimized.
killercup
commented
Jan 13, 2016
|
There are a few things to be aware of, but in general pandoc is really amazing at converting Markdown to LaTeX. Which is what you want, I think—it has some very nice features that you currently can't get with HTML-to-PDF converters. For example, my PDF versions of the Rust Book include cross-references like "This is a mutable variable binding (section 5, page 163)". If you're no LaTeX wizard (I'm not), you might want to look at this template I threw together. If you have any issues with this, just mention me. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for all your help Pascal! |
This comment has been minimized.
This comment has been minimized.
|
+1 for the effort, I am looking forward to using It seems to have stalled a bit, is anyone currently working on this? |
This comment has been minimized.
This comment has been minimized.
Indeed, it has stalled a bit. In the last 6 months I have been overwhelmed with work at school I am (very) slowly working on the refactoring / clean-up that I wanted to do. And that work is probably going to change the way this specific feature is going to be implemented. Hopefully I will have some time in September to make significant progress on the internal rewrite so that I can work on new features again. |
This comment has been minimized.
This comment has been minimized.
|
@azerupi How much space is there for discussing this feature? There are some specific things I would be looking for in a CLI ebook helper, but maybe you are already determined in which way to go. Some time ago I wrote prophecy, a ruby gem to automate the tasks I needed when producing ebooks. This is and example of the output. It has been very useful for me, but I believe I am the only user :) I have been wanting to rewrite it with some of the hindsight since its early days, but when I saw this I thought maybe There is an asciinema recording to see to sort of things it does. |
This comment has been minimized.
This comment has been minimized.
|
I'm open to all ideas :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Luthaf
commented
Jan 17, 2017
That was basically my idea. pandoc looks nice (I've never used it), but why add another dependency if we can easily go without it? I'll try to get a poc working, and will open an issue here about this. |
This comment has been minimized.
This comment has been minimized.
Tables with headings and rules, smart quoting, tex ligatures, ampersands and other specials, list within quotes... there are so many things to think about. |
This comment has been minimized.
This comment has been minimized.
Luthaf
commented
Jan 17, 2017
Yep, that true =/. I'll give it a try to grasp the internal of the code, and I'll check how hard this is. If I can not make it work, I'll check how I can make this work on Windows/Linux/OS X with calling user-provided pandoc. Do you know any test suite for markdown files? Maybe the pandoc's one would be a good listing of all the weird cases. |
This comment has been minimized.
This comment has been minimized.
|
I'd say just adopt pandoc. Even if you did without it, the PDF feature is still not stand-alone, because there is always the assumption that the user has gone through the trouble of installing a LaTeX distribution. There exists a spec for CommonMark and there is Multimarkdown's test suite. 'Simple' is not the right word for it... |
This comment has been minimized.
This comment has been minimized.
This was referenced Mar 27, 2017
azerupi
added
A-Rendering
S-On-hold
S-Wishlist
T-Enhancement
T-New-format
and removed
Status: Claimed
labels
May 16, 2017
This was referenced Sep 14, 2017
This comment has been minimized.
This comment has been minimized.
vandenoever
commented
Sep 22, 2017
|
A very naive conversion that works pretty nice for the rust book second edition: cd second-edition/src
pandoc -o rust.epub [Sc]*.md a*.md |
This comment has been minimized.
This comment has been minimized.
dkotrada
commented
Sep 22, 2017
This comment has been minimized.
This comment has been minimized.
|
@vandenoever thanks, this seams similar to what @killercup had provided in https://github.com/killercup/trpl-ebook @dkotrada tectonic looks interesting! I understand that it does require 3'rd party tools to convert TeX/LaTeX to pdf. Am I right? |
This comment has been minimized.
This comment has been minimized.
dkotrada
commented
Sep 23, 2017
|
@budziq yes you are right. |
This comment has been minimized.
This comment has been minimized.
|
As a bit of an update on this front, I've started working on adding the ability to use alternative backends (#507). It's still very much in the experimental phase and nothing has been merged yet, but I've already got an Under the hood we use @lise-henry's epub-builder crate (awesome crate by the way) to generate an This means backends aren't limited to just Rust, for example you could use a python script that passes all Rust snippets to |
This comment has been minimized.
This comment has been minimized.
dustinmatlock
commented
Dec 16, 2017
•
This comment has been minimized.
This comment has been minimized.
d8aninja
commented
Feb 26, 2019
•
|
One of the things that doesn't seem to be mentioned anywhere on this ticket is the ability to highlight the important bits. I have used a chrome extension called Hypothesis to do this until recently but a) chrome extension, ew b) its pretty sloppy about whether the highlights are saved under your personal view or public view (ie, in some cases you can see others' highlights) and c) I say recently because I'm pretty sure when the book gets updated, all my highlights and attached notes get deleted, too. Anyway, just wanted to add my two cents and support for a PDF version to be released in parallel to the online book's update. I realize that must be a lot harder than many of us make it out to be, and you all are doing a wonderful job regardless of the format in which we are all consuming your work. Thanks! |

mdinger commentedDec 30, 2015
Gitbook supports export to ebooks and pdfs via calibre. This might be easy to hook into.
See also rust-lang/rust-by-example#684 for problems this implementation creates for rustbyexample.