summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/filters.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/filters.rs b/src/filters.rs
index 8dbe578..9e37371 100644
--- a/src/filters.rs
+++ b/src/filters.rs
@@ -1,6 +1,6 @@
1use std::{collections::HashMap, path::Path}; 1use std::{collections::HashMap, path::Path};
2 2
3use log::trace; 3use log::{trace, warn};
4use pandoc_ast::MutVisitor; 4use pandoc_ast::MutVisitor;
5 5
6// If a link points to `./a/b/c.ext`, and a file in the output directory `pdbook/./a/b/c.html` 6// If a link points to `./a/b/c.ext`, and a file in the output directory `pdbook/./a/b/c.html`
@@ -13,10 +13,13 @@ pub struct RelativizeUrls<'a> {
13} 13}
14 14
15impl<'a> pandoc_ast::MutVisitor for RelativizeUrls<'a> { 15impl<'a> pandoc_ast::MutVisitor for RelativizeUrls<'a> {
16 fn walk_inline(&mut self, inline: &mut pandoc_ast::Inline) { 16 fn visit_inline(&mut self, inline: &mut pandoc_ast::Inline) {
17 let link = match inline { 17 let link = match inline {
18 pandoc_ast::Inline::Link(_, _, target) => &mut target.0, 18 pandoc_ast::Inline::Link(_, _, target) => &mut target.0,
19 _ => return, 19 _ => {
20 self.walk_inline(inline);
21 return;
22 }
20 }; 23 };
21 24
22 if link.starts_with('#') || link.contains("://") { 25 if link.starts_with('#') || link.contains("://") {
@@ -26,6 +29,7 @@ impl<'a> pandoc_ast::MutVisitor for RelativizeUrls<'a> {
26 let link_path = self.source_dir.join(&link); 29 let link_path = self.source_dir.join(&link);
27 30
28 if link_path.is_absolute() { 31 if link_path.is_absolute() {
32 warn!("Link is absolute: '{}'", link_path.display());
29 return; 33 return;
30 } 34 }
31 35
@@ -46,7 +50,13 @@ impl<'a> pandoc_ast::MutVisitor for RelativizeUrls<'a> {
46 .expect("Path constructed from UTF-8 valid strings in not UTF-8 valid") 50 .expect("Path constructed from UTF-8 valid strings in not UTF-8 valid")
47 .to_string(); 51 .to_string();
48 52
49 trace!("Relativizing link '{}' -> into '{}'", link_path.display(), link); 53 trace!(
54 "Relativizing link '{}' -> into '{}'",
55 link_path.display(),
56 link
57 );
58 } else {
59 warn!("Could not relativize link '{}'", link_path.display());
50 } 60 }
51 } 61 }
52} 62}