Skip to content

#27 - allow linking to a section with hash syntax #34

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 2 commits into from
May 18, 2017

Conversation

mickmcgrath13
Copy link
Contributor

resolves #27

Copy link
Contributor

@chasenlehara chasenlehara left a comment

Choose a reason for hiding this comment

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

😍 thank you for including tests for this change too

hashParts = name.split("#");

if(hashParts.length > 1){
name = hashParts[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

It’d be nice if there were comments so people reading this code could more easily understand what’s going on here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


docObject = docMap[name]
if (docObject) {
linkText = parts && parts[2] ? parts[2] : docObject.title || name;
description = docObject.description || name;

return '<a href="' + urlTo(name) + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
return '<a href="' + urlTo(name) + (hashParts.length > 1 ? ("#" + hashParts.slice(1).join("#")) : "") + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be easier to read if this logic happened before the string concatenation.

Also, you could use shift to get the name and then you wouldn't have to slice the array here. 😝

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do that

@mickmcgrath13 mickmcgrath13 merged commit 50e5909 into master May 18, 2017
@mickmcgrath13 mickmcgrath13 deleted the 27-section-linking branch May 18, 2017 18:02
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.

Allow linking to section of page
2 participants