Skip to content

Commit 15d6227

Browse files
committed
Attempt to fix #119 replace \ with / in paths, so that Windows also uses / as separator (ugly hack)
1 parent 1b8af2b commit 15d6227

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/renderer/html_handlebars/helpers/navigation.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
6060

6161
match previous.get("path") {
6262
Some(p) => {
63+
// Hack for windows who tends to use `\` as separator instead of `/`
6364
let path = Path::new(p).with_extension("html");
6465
debug!("[*]: Inserting link: {:?}", path);
6566

6667
match path.to_str() {
6768
Some(p) => {
68-
previous_chapter.insert("link".to_owned(), p.to_json());
69+
previous_chapter.insert("link".to_owned(), p.replace("\\", "/").to_json());
6970
},
7071
None => {
7172
return Err(RenderError {
@@ -170,7 +171,8 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
170171

171172
match link.to_str() {
172173
Some(l) => {
173-
next_chapter.insert("link".to_owned(), l.to_json());
174+
// Hack for windows who tends to use `\` as separator instead of `/`
175+
next_chapter.insert("link".to_owned(), l.replace("\\", "/").to_json());
174176
},
175177
None => return Err(RenderError { desc: "Link could not converted to str".to_owned() }),
176178
}

src/renderer/html_handlebars/helpers/toc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ impl HelperDef for RenderToc {
6868
.with_extension("html")
6969
.to_str()
7070
.unwrap()
71+
// Hack for windows who tends to use `\` as separator instead of `/`
72+
.replace("\\", "/")
7173
.as_bytes()));
7274

7375
try!(rc.writer.write("\"".as_bytes()));
@@ -98,7 +100,8 @@ impl HelperDef for RenderToc {
98100
// filter all events that are not inline code blocks
99101
let parser = Parser::new(&name).filter(|event| {
100102
match event {
101-
&Event::Start(Tag::Code) | &Event::End(Tag::Code) => true,
103+
&Event::Start(Tag::Code) |
104+
&Event::End(Tag::Code) => true,
102105
&Event::InlineHtml(_) => true,
103106
&Event::Text(_) => true,
104107
_ => false,

0 commit comments

Comments
 (0)