-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix heading links in nested pages #419
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
Conversation
Thanks for the PR! |
Uh, on windows the |
d7ac12d
to
a4533cf
Compare
Travis is completely broken right now. I filed this: https://github.com/azerupi/mdBook/issues/421 |
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.
Looks pretty good 👍
Breaking out the dummy book creation and helpers into two separate modules is a good idea, seeing as they're separate and the helpers module will probably expand as we add more tests.
Note to self: update #422 when this merges
@@ -457,7 +458,7 @@ fn id_from_content(content: &str) -> String { | |||
let mut content = content.to_string(); | |||
|
|||
// Skip any tags or html-encoded stuff | |||
let repl_sub = vec![ | |||
static REPL_SUB: &[&str] = &[ |
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.
I'm assuming you meant const REPL_SUB ...
here. Using static
means it actually gets embedded in the binary and is typically only done for global mutable objects or if your hardware requires it (like the exception vector when writing a kernel).
I'd also pull it up to the top of the file and name it to something like HTML_ENCODE_BLACKLIST
(feel free to give it a better name) so it's easy to update later on.
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.
Ooop! Right.
"first/nested.html", | ||
"second.html", | ||
"conclusion.html", | ||
r#"href="intro.html""#, |
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.
Nice fix! Without the href="
this test wouldn't have actually been checking for links, just that the filenames are present, which means it's not actually testing what we want it to.
src/lib.rs
Outdated
@@ -100,6 +100,8 @@ pub use book::BookItem; | |||
pub use renderer::Renderer; | |||
|
|||
/// The error types used through out this crate. | |||
// TODO: Drop after error_chain is fixed | |||
#[allow(unused_doc_comment)] |
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 should probably be pulled out into its own PR. error-chain
has actually fixed this, so bumping the dependency version to 0.11.0-rc.2
would be sufficient.
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.
yeah; I did this on one of my recent projects
let rendered = self.post_process(rendered, | ||
filename.file_name().unwrap().to_str().unwrap_or(""), | ||
&normalize_path(filepath.to_str() | ||
.expect(&format!("Bad file name: {}", filepath.display()))), |
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.
Is it a good idea to panic here? Another option may be to assume a safe default or return an error.
If we were to return an error, I imagine it'd look something like this:
filepath.to_str()
.ok_or_else(Error::from("Bad file name: {}", filepath.display()))?`
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.
Good point! I would expect non-Unicode file names would be caught somewhere earlier in the lib, but in case they are not, makes sense to return a nice error here.
I just had another look through this PR... Are there any tests to make sure It might also be useful to add an integration test in |
Move non-test test module files into their own directories to prevent cargo from running them as tests. Then suppress the left-over warnings. Move *dummy book* code and data into a shared folder, and leave the rest of helper utilities (one function) in the original module.
Plus fixing the whitespace chars not being replaced by hyphen. Also expand tests for link creations, and add test for nested pages. Fixes <https://github.com/azerupi/mdBook/issues/416> Fixes <https://github.com/azerupi/mdBook/issues/417>
On the web, the normalized path separator is forward-slash (`/`), so we use the built-in `is_separator()` method to replace any path separator with the forward-slash, to ensure consistent output on unix and windows machines.
Yes, the newly added "## Some Section" to the nested I'm submitting a fix for the inline comments, and I think it would be good to land. |
Addressing the review comments.
Thank you for fixing the issues raised by @Michael-F-Bryan ! |
Awesome, and then we should cut a release. |
Thanks a lot for this PR @behnam! |
Fix heading links in nested pages
Plus fixing the whitespace chars not being replaced by hyphen.
Also expand tests for link creations, and add test for nested pages.
Fixes https://github.com/azerupi/mdBook/issues/416
Fixes https://github.com/azerupi/mdBook/issues/417
And, also fix some test warnings by moving non-test module files into their own directories.