Attempt to fix #119 replace \ with / in paths, so that Windows also uses / as separator (ugly hack)

This commit is contained in:
Mathieu David 2016-04-25 17:02:47 +02:00
parent 1b8af2bf57
commit 15d6227a11
2 changed files with 8 additions and 3 deletions

View file

@ -60,12 +60,13 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
match previous.get("path") {
Some(p) => {
// Hack for windows who tends to use `\` as separator instead of `/`
let path = Path::new(p).with_extension("html");
debug!("[*]: Inserting link: {:?}", path);
match path.to_str() {
Some(p) => {
previous_chapter.insert("link".to_owned(), p.to_json());
previous_chapter.insert("link".to_owned(), p.replace("\\", "/").to_json());
},
None => {
return Err(RenderError {
@ -170,7 +171,8 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
match link.to_str() {
Some(l) => {
next_chapter.insert("link".to_owned(), l.to_json());
// Hack for windows who tends to use `\` as separator instead of `/`
next_chapter.insert("link".to_owned(), l.replace("\\", "/").to_json());
},
None => return Err(RenderError { desc: "Link could not converted to str".to_owned() }),
}

View file

@ -68,6 +68,8 @@ impl HelperDef for RenderToc {
.with_extension("html")
.to_str()
.unwrap()
// Hack for windows who tends to use `\` as separator instead of `/`
.replace("\\", "/")
.as_bytes()));
try!(rc.writer.write("\"".as_bytes()));
@ -98,7 +100,8 @@ impl HelperDef for RenderToc {
// filter all events that are not inline code blocks
let parser = Parser::new(&name).filter(|event| {
match event {
&Event::Start(Tag::Code) | &Event::End(Tag::Code) => true,
&Event::Start(Tag::Code) |
&Event::End(Tag::Code) => true,
&Event::InlineHtml(_) => true,
&Event::Text(_) => true,
_ => false,