Skip to content
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

Homepage: Markdown Links to Anchors Do Not Work #2450

Open
sanssecours opened this Issue Mar 1, 2019 · 3 comments

Comments

Projects
None yet
5 participants
@sanssecours
Copy link
Member

sanssecours commented Mar 1, 2019

Steps to Reproduce the Problem

  1. Search for the text “see also Data Types” in this webpage.
  2. Click on the link “Data Types”.

Expected Result

The browser scrolls to the header “Data Types”

Actual Result

The browser tries to open

https://github.com/ElektraInitiative/libelektra/tree/master/src/libs/high-level-api#data-types

, which does not exist.

Additional Information

The problem does not occur on GitHub. If you retry the procedure from “Steps to Reproduce the Problem” here, everything will work as expected.

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 2, 2019

Thank you for this beautiful description of the problem! Seems like the markdown parser for our webpage behaves differently than the one from GitHub.

@Namoshek Do you know if this problem might be caused by parts written by you (iirc you implemented some logic to handle external links vs. links to GitHub?) or by the markdown parser we use?

A solution to this problem would also be to find some other way to specify anchors which work for every markdown parser we use.

@Namoshek

This comment has been minimized.

Copy link
Contributor

Namoshek commented Mar 2, 2019

The problem is most likely cause by this code:

this.ensureAbsoluteLinkPaths = function (filepath, text) {
return text.replace(/\[(.+)\]\(([^\)]+)\)/gi, function (match, text, url) {
if (url.indexOf('://') > -1 || url.charAt(0) === '#') {
return match;
} else {
if (url.charAt(0) === '/') {
return '[' + text + '](' + url.substr(1) + ')';
} else {
return '[' + text + '](' + path.join(path.dirname(filepath), url) + ')';
}
}
});
};

The snippet is invoked when the website content is built (pre-processed), i.e. links are rewritten to match our needs. I'm not sure, why it doesn't work though. Might be the markdown parser received an update that broke the anchor-links. As I don't really remember everything about the code, I can only say that the snippet obviously handles anchor tags on line 157.


Ok, during writing the above, I realized I'm on the wrong path. The file fetched by the website in the background contains a link like this [Data Types](#data-types), so it must be the frontend doing something wrong:

link: function (href, title, text) {
// external link
if (href.indexOf('://') > -1) {
return '<a href="' + href + '"' + (title ? ' title="' + title + '"' : '') +
' target="_blank">' + text + ' <i class="fa fa-external-link"></i></a>';
}
// internal link
var file = findFileInWebstructure(webStructure, href);
// we don't have the file on the website, make external link
if (file === null) {
return '<a href="' + config.github.website.root + config.github.website.paths.doc_root + href +
'"' + (title ? ' title="' + title + '"' : '') + ' target="_blank">' + text +
' <i class="fa fa-external-link"></i></a>';
}
// we have this file on the website, make internal link
else {
return '<a ui-sref="main.dyn.' + file.ref + '({file:\'' + file.slug + '\'})"' +
(title ? ' title="' + title + '"' : '') + '>' + text + '</a>';
}
},

I guess a special case for anchor tags is required. Probably below line 31.


While doing some research, I saw some links in the documentation that should probably be changed to relative ones: /doc/tutorials/cascading.md (L7-L11)

@markus2330

This comment has been minimized.

Copy link
Contributor

markus2330 commented Mar 2, 2019

Thank you so much for pointing out so fast where the problem is and how to solve it!

@markus2330 markus2330 assigned hesirui and unassigned vanessaNWK Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.