-
-
Notifications
You must be signed in to change notification settings - Fork 170
New Node Type for Broken Reference Links #98
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
…render the text when the BrokenReference node is not replaced.
|
@kivikakk I seem to have broken some spec tests. I really don't know the code well enough to fix the issue. Could you help me out? |
|
@sunjay This is looking amazing! Thank you so much for your time and effort here. Let's see: This should produce a link to
Here's what local testing shows different between $ cat >test
[hi](/uri)
[hi [](/uri)
[hi []](/uri)
$ ~/github/cmark-gfm/build/src/cmark-gfm test
<p><a href="/uri">hi</a></p>
<p>[hi <a href="/uri"></a></p>
<p><a href="/uri">hi []</a></p>
$ cargo run -- test
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `target/debug/comrak test`
<p><a href="/uri">hi</a></p>
<p>[hi <a href="/uri"></a></p>
<p>[hi []](/uri)</p>
$I've pushed a commit to this branch which adds a comrak test for this, and a commit to fix the issue, which was to remove the following: if !is_image {
let mut i = brackets_len as i32 - 1;
while i >= 0 {
if !self.brackets[i as usize].image {
if !self.brackets[i as usize].active {
break;
} else {
self.brackets[i as usize].active = false;
}
}
i -= 1;
}
}The function of this code is to disable brackets surrounding the current processed bracket pair; i.e. so that only the innermost link in the following Markdown is parsed: Note we do this only when actually constructing a link from brackets, and not in case of failure. See $ ~/github/cmark-gfm/build/src/cmark-gfm
Here [I think I want [xyz][xyz] this](maybe)
[xyz]: hi
<p>Here [I think I want <a href="hi">xyz</a> this](maybe)</p>
$ ~/github/cmark-gfm/build/src/cmark-gfm
Here [I think I want [xyz][xyz] this](maybe)
<p>Here <a href="maybe">I think I want [xyz][xyz] this</a></p>
$The solution for broken references is just to do no such disabling. I've pushed a commit for this fix; there are a few other compliance issues that speak to deeper issues. For example: The non-matching brackets are intended to treated as plain text, such that this example has an emphasis placed. Because we create a node that encompasses all of I've pushed a comrak test for this, but haven't the time to devise a solution; I hope this guidance might be enough to see you through! |
|
Thank you for your help! Your explanation is very helpful. 😄 I am not sure if the If we can't think of something to address this, maybe a broken link callback would be better after all? It seems like that would simplify a lot of the code and avoid the issues we're running into. Maybe this is why |
Fixes #95.
Hi @kivikakk! I highly recommend reviewing this one commit at a time from my first commit to the latest one. The changes will make much more sense that way. My commit messages detail exactly what I'm trying to do in each step.
My code works and the tests all pass (at least locally), but because of the complexity of the code, I still don't really fully understand some of what I did. I started by copying and pasting the entire
close_bracket_matchfunction and then modifying it to work for the newBrokenReferencenode that I added. I didn't really understand what was going on in that function, so I didn't attempt to fix the duplication this created.I tried to add comments throughout the codebase to clarify things I did end up understanding, but most of it is still very unclear for me.
To show you it works, here's the AST for the following markdown: (from the
reference_linkstest intests.rs)Full AST
You'll notice that there are now
BrokenReferencenodes that contain the references that could not be resolved. For more details, see the documentation in the code forNodeValue::BrokenReferenceand the documentation forNodeBrokenRef.These new nodes are transparently rendered as text if they are not replaced by the time they get to the common mark or HTML renderer.
I also took the liberty to bump the minor (
0.x) version of the crate since this is a breaking change. Feel free to revert that or do whatever you want with any of this code. I also have a follow up PR to make debugging a lot easier if you are interested. I'll send that once this is merged. 😄