-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(markdown): add ids to headers #713
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
I'd like to try my hand at getting those tests passing. @glebec are you comfortable adding me as a contributor to your fork? |
Please do – I was probably going to post that anyone who wanted to take a crack at this branch should feel free, as I don’t have a strong need for this feature currently myself. |
Hey @bennypowers and @glebec, this is very late notice (apologies), but I have a PR for this issue for this in our old repo that is mostly done. I'll bring that PR over since I've worked out most of the bugs and kinks that come along the way. If you'd like, you can keep working on this PR, but I think it makes sense for us to take a look at both PRs and see which one should be merged into the other. Sorry for letting the crossed wires happen! |
@Zhao-Andy no worries, I haven't spent any serious time or thought on this PR – nor do I know this codebase (or even language) well. So I'm going to assume a priori that your branch is probably going to be farther along. We can certainly review that, of course. |
@Zhao-Andy in that case I'll finish up with my current test and fire it off for comparisson. Thanks! |
b973c28
to
6ead028
Compare
6ead028
to
cb376bc
Compare
I got bored so I fixed the tests ;) |
spec/labor/markdown_parser_spec.rb
Outdated
@@ -54,7 +54,7 @@ def generate_and_parse_markdown(raw_markdown) | |||
it "does not generated nested link tags" do | |||
nested_links = generate_and_parse_markdown("[[](http://b)](http://a)") | |||
nested_links = Nokogiri::HTML(nested_links).at("p").inner_html | |||
expect(nested_links).to eq('[<a href="http://b" rel="noopener noreferrer"></a>](<a href="http://a" rel="noopener noreferrer">http://a</a>)') # rubocop:disable Metrics/LineLength | |||
expect(nested_links).to eq('[<a href="http://b"></a>](<a href="http://a">http://a</a>)') |
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 curious why this PR's changes invalidated the former test and mean that the rel
s had to be taken out. I personally don't have any stake in those rel
s existing, just doing some due diligence.
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.
Nevermind – I was looking at only 81d998e's changes. I failed to notice that those changes undid some earlier changes in this same PR.
spec/models/comment_spec.rb
Outdated
@@ -44,7 +44,7 @@ | |||
end | |||
|
|||
it "converts body_markdown to proper processed_html" do | |||
expect(comment.processed_html.include?('<h1 id="hello-hy-hey-hey">')).to eq(true) | |||
expect(comment.processed_html.include?('<h1 id="hello">')).to eq(true) |
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.
Out of curiosity, why do id
s behave differently now? If this test didn't make sense before, why did it previously pass? Is there any observable behavior change that might break earlier content?
Just doing due diligence, not saying how it ought to be.
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.
The original test tested against <h1>
, which would fail if the markdown text was
# hello
hy hey hey
This change just includes the anchor id in an otherwise unrelated test.
@bennypowers is this ready to have the WIP prefix removed (i.e. ready for this to be reviewed again)? |
@glebec yeah afaict it's ready to roll |
@Zhao-Andy interesting points for comparison: testing for emoji in headers. |
Hey @glebec, finally getting around to this now; sorry about that. Mind if I push up to your branch directly? Seems to be the easiest way to keep the history clean. |
I'm fine with that, will add you as a collaborator shortly. EDIT: ok, you should have received an invite to collab at https://github.com/glebec/dev.to. |
Just made a push. I made a couple of changes:
In the future, we might add an icon to the left side of the headers much like GitHub does in READMEs. I tried that in my previous PR but it was such a pain to get the styling correct for both articles and comments. Maybe in the future though :) |
i'd suggest that emoji get stripped out of the anchor name rather than converted to unicode address |
29470b2
to
6cecb4a
Compare
1f09ca1
to
5354261
Compare
</h1> | ||
|
||
<h1> | ||
<a name="%F0%9F%98%8E-emoji-heading" href="#%F0%9F%98%8E-emoji-heading" class="anchor" id="%F0%9F%98%8E-emoji-heading"> |
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.
Not sure why this looks like this file, but it works fine in development.
Haven't reviewed the code but for the third example it should probably strip the trailing |
👋 |
Hey @bennypowers, thanks for the bump. We'll get to this soon. 🙈 |
What type of PR is this? (check all applicable)
Description
Enables the
with_toc_data
option for the Redcarpet markdown renderer. This addsid
attributes to the markdown headers, allowing for hash links to specific page content. This is useful both for linking and for generating tables of content (ToCs).Input:
Rendered (before):
Rendered (after):
NB, I don't know Ruby so you should definitely sanity-check the code and make sure it makes sense w.r.t. how these classes & functions are intended to work.
Related Tickets & Documents
Might be considered to close #183. However, you might also want a feature similar to GitHub's markdown renderer, which makes it clear that headers have anchors via a link or hover icon.
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
Added to documentation?