-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WIP on ePub #94
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
WIP on ePub #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub use self::renderer::Renderer; | ||
pub use self::html_handlebars::HtmlHandlebars; | ||
pub use self::pandoc::Pandoc; | ||
|
||
pub mod renderer; | ||
mod html_handlebars; | ||
mod pandoc; | ||
mod html_handlebars; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use renderer::Renderer; | ||
use book::MDBook; | ||
use book::bookitem::BookItem; | ||
|
||
use std::error::Error; | ||
use std::process::Command; | ||
|
||
pub struct Pandoc; | ||
|
||
impl Pandoc { | ||
pub fn new() -> Pandoc { | ||
Pandoc | ||
} | ||
} | ||
|
||
impl Renderer for Pandoc { | ||
fn render(&self, book: &MDBook) -> Result<(), Box<Error>> { | ||
let mut paths = vec!(); | ||
|
||
for item in book.iter() { | ||
match *item { | ||
BookItem::Chapter(_, ref ch) => { | ||
paths.push(book.get_src().join(&ch.path).into_os_string()); | ||
}, | ||
_ => println!("FIXME: don't understand this kind of BookItem") | ||
} | ||
} | ||
|
||
let output = Command::new("pandoc") | ||
.arg("-S") | ||
.arg("-osample.epub") | ||
.args(&paths) | ||
.output(); | ||
|
||
match output { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(Box::new(e)) | ||
} | ||
// FIXME: why doesn't this work | ||
// output.map(|_| ()).map_err(|e| Box::new(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why the output of In the
But it seems to me like both the types and the lifetimes should be the same in both? (Update: ok, I bet it's because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to be afraid to use the if let Err(e) = output {
return Err(Box::new(e))
}
Ok(()) Maybe there are other solutions, but it is generally a matter of personal preference :) |
||
} | ||
} |
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 just temporary to make local testing easier, but curious how we see this playing out long term. Should the mdbook command line support a new argument? Default to using all the available renderers?
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.
In the long term I guess it would be nice if the user could choose a couple of formats in his
book.json
and on build all formats would be exported. This needs a little bit of thinking to come up with a good design:book
dir but where would pdf, epub, ... go?