Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remark plugin does not prefix reference links #8588

Closed
i-like-robots opened this issue Sep 27, 2018 · 1 comment
Closed

Remark plugin does not prefix reference links #8588

i-like-robots opened this issue Sep 27, 2018 · 1 comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby

Comments

@i-like-robots
Copy link
Contributor

i-like-robots commented Sep 27, 2018

Description

Links in Markdown files using the reference format are not currently rendered with the specified path prefix.

Steps to reproduce

For a project using markdown files as a data source and the gatsby-transformer-remark plugin, author a link in a markdown file using the reference style, e.g.:

This is [a link](/path/to/page).

This is [a reference]

[a reference]: /path/to/page

Build the project using the --prefix-paths option.

Expected result

The second link should be rendered with the path prefix, e.g.:

<p>This is <a href="/prefix/path/to/page">a link</a></p>

<p>This is <a href="/prefix/path/to/page">a reference</a></p>

Actual result

The first link will be rendered with the prefix and the second will not:

<p>This is <a href="/prefix/path/to/page">a link</a></p>

<p>This is <a href="/path/to/page">a reference</a></p>

Environment

  npmPackages:
    gatsby: next => 2.0.0-rc.25
    gatsby-remark-autolink-headers: ^1.4.19 => 1.4.19
    gatsby-remark-external-links: 0.0.4 => 0.0.4
    gatsby-remark-prismjs: ^2.0.5 => 2.0.5
    gatsby-source-filesystem: next => 2.0.1-rc.6
    gatsby-transformer-remark: next => 2.1.1-rc.5
    gatsby-transformer-yaml: ^1.5.18 => 1.5.18
@i-like-robots
Copy link
Contributor Author

i-like-robots commented Sep 27, 2018

I've looked into this and I think this is because plugin is currently only expecting link nodes and not definition nodes:

visit(markdownAST, `link`, node => {

The solution may be to listen for both (unist supports providing an array of tests), I hacked this into my local install:

visit(markdownAST, ['link', 'definition'], node => {
	if (node.url && node.url.startsWith(`/`) && !node.url.startsWith(`//`)) {
		node.url = withPathPrefix(node.url, pathPrefix);
	}
});

Shall I create PR for this or is the above enough information for somebody better positioned or currently working in this area?

@DSchau DSchau added the good first issue Issue that doesn't require previous experience with Gatsby label Sep 27, 2018
@pieh pieh closed this as completed in fb43fda Oct 2, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants