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

How to ignore .md in a link? #178

Open
LordBrain opened this issue Aug 10, 2016 · 9 comments
Open

How to ignore .md in a link? #178

LordBrain opened this issue Aug 10, 2016 · 9 comments

Comments

@LordBrain
Copy link

Couscous is changing a external URL that ends in .md to .html (like is should) but in this case its to a repo outside of where couscous is running, so we need the .md. Can we flag the url string somehow so couscous will ignore it and set the link to the correct .md path?

@wysow
Copy link
Member

wysow commented Aug 10, 2016

Hum... for me it sounds like an optimization we must do... Let me check that ASAP and come back to you.

@cyberbit
Copy link
Contributor

This is the first time I've seen a valid reason for the labels "bug" and "enhancement" to be applied to the same issue. 👍

@LordBrain
Copy link
Author

So we came up with a hack to get around it. Your regex is looking for the whole '.md'. We can use ascii to swap out the . and then use % encoded value: '%2Emd'. This gets it around the current problem, but there should be a better way to do it.

@mnapoli
Copy link
Member

mnapoli commented Aug 13, 2016

That's unfortunate, I don't see a lot of options. We could check that the file exists in the repository? Hopefully it won't be tricky with relative paths and absolute…

@stephenharris
Copy link

Couscous is changing a external URL that ends in .md to .html (like is should)

Why couldn't Couscous ignore's external URLs by checking the domain against the baseUrl? You could always enter a HTML URL if that's what you wanted in the published site.

@mnapoli
Copy link
Member

mnapoli commented Dec 25, 2016

@stephenharris that's a good idea, maybe we could also check whether the URL is relative or absolute to another domain?

@stephenharris
Copy link

@mnapoli Yes, so if the url (relative or an absolute) evaluates to something under the baseUrl it is parsed. Absolute urls to other (sub-?)domains is ignored. The regex for that would need some thought.

I'm not familiar with Couscous' internals, but happy to attempt a PR if the above seems reasonable.

@mnapoli
Copy link
Member

mnapoli commented Jan 7, 2017

@stephenharris if you want to give it a go, here is the test: https://github.com/CouscousPHP/Couscous/blob/master/tests/UnitTest/Module/Markdown/Step/RewriteMarkdownLinksTest.php and the class containing the regex: https://github.com/CouscousPHP/Couscous/blob/master/src/Module/Markdown/Step/RewriteMarkdownLinks.php (that regex looks fun :) )

I'm not sure I understand fully what you suggest, here is what I have in mind:

  • URL is absolute -> leave it
  • URL is relative -> do the same thing as what is done now

So it should be a matter of rewriting the regex so that it doesn't match anything that starts with http:// or https:// or whatever other protocol?

@spkane
Copy link

spkane commented Feb 1, 2017

Leaving absolute URLs alone, is probably the correct solution here.

I do however, have a clean workaround for the time being. HTML tags are acceptable in markdown and get left alone by couscous.

Changing a link like this:

[Contributors](https://github.com/CouscousPHP/Couscous/blob/master/CONTRIBUTING.md)

to this:

<a href="https://github.com/CouscousPHP/Couscous/blob/master/CONTRIBUTING.md">Contributors</a>

seems to workaround the issue well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants