Skip to content

Update comrak to 0.2.3, use ext_header_ids #1129

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

Merged
merged 7 commits into from
Oct 23, 2017
Merged

Update comrak to 0.2.3, use ext_header_ids #1129

merged 7 commits into from
Oct 23, 2017

Conversation

kivikakk
Copy link
Contributor

Fixes #1037. Use latest comrak, and use the header IDs extension to generate GitHub-compatible anchors.

/cc @kejadlen @treiff

@kivikakk
Copy link
Contributor Author

It occurs to me this won't quite fix #1023; the anchors still won't work because we prefix "user-content-" to IDs to prevent nasty name collisions and subsequent security issues, but we need to still support hrefs without this prefix (because users don't expect to see #user-content-… in their address bar).

I'll come up with an appropriate solution shortly; on GitHub we use JavaScript which fires on hash change to search for and scroll to the item with the "user-content-" prefix.

@kivikakk
Copy link
Contributor Author

kivikakk commented Oct 16, 2017

So, to prevent ID collisions, we'll also need to sanitize the IDs not coming from comrak-outputted header tags; I've proposed https://github.com/notriddle/ammonia/pull/66 (now merged!) to give us the machinery to do that.

Finally, we'll need either the JavaScript portion to scroll the appropriate tag into view (I could throw this together easily based on what we're using here), or we'd need to change all relative hrefs. The former is a bit prettier since it means we don't end up with "user-content-" or similar in the address bar.

@kivikakk
Copy link
Contributor Author

The JavaScript side of the solution is now in this PR; ready for your thoughts/comments!

Copy link
Member

@carols10cents carols10cents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good, going to try it out now :)

@@ -53,8 +53,7 @@ impl<'a> MarkdownRenderer<'a> {
.cloned()
.collect();
let tag_attributes = [
("a", ["href", "target"].iter().cloned().collect()),
("code", ["class"].iter().cloned().collect()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, does allowed_classes make this line unnecessary...? I guess so since the tests pass!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it even became required in the newer ammonia: https://github.com/notriddle/ammonia/blob/2581eec04ef98419fd202e0dd4d8997c9dfdb06e/src/lib.rs#L1030-L1037 (you're allowed to use allowed_classes or set class as an allowed tag, but not both)

@carols10cents
Copy link
Member

Looks great, thank you!!! I'm going to review your other readme-related PRs then deploy and regenerate the readmes all at once, that'll probably take me a few days :) Thank you so much for taking care of all these things!!!

bors: r+

bors-voyager bot added a commit that referenced this pull request Oct 23, 2017
1129: Update comrak to 0.2.3, use ext_header_ids r=carols10cents

Fixes #1037. Use latest comrak, and use the header IDs extension to generate GitHub-compatible anchors.

/cc @kejadlen @treiff
@bors-voyager
Copy link
Contributor

bors-voyager bot commented Oct 23, 2017

Build succeeded

@bors-voyager bors-voyager bot merged commit 0301237 into rust-lang:master Oct 23, 2017
@kivikakk
Copy link
Contributor Author

Thanks so much!

@kivikakk kivikakk deleted the comrak-0-2-3 branch October 25, 2017 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants