Couscous icon indicating copy to clipboard operation
Couscous copied to clipboard

How to ignore .md in a link?

Open LordBrain opened this issue 9 years ago • 9 comments

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?

LordBrain avatar Aug 10 '16 14:08 LordBrain

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

wysow avatar Aug 10 '16 15:08 wysow

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

cyberbit avatar Aug 10 '16 15:08 cyberbit

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.

LordBrain avatar Aug 10 '16 15:08 LordBrain

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…

mnapoli avatar Aug 13 '16 11:08 mnapoli

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.

stephenharris avatar Dec 20 '16 11:12 stephenharris

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

mnapoli avatar Dec 25 '16 21:12 mnapoli

@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.

stephenharris avatar Jan 05 '17 12:01 stephenharris

@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?

mnapoli avatar Jan 07 '17 22:01 mnapoli

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.

spkane avatar Feb 01 '17 23:02 spkane