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

Support for links like [this]? #597

Closed
rudymatela opened this issue Sep 5, 2024 · 4 comments · Fixed by #598
Closed

Support for links like [this]? #597

rudymatela opened this issue Sep 5, 2024 · 4 comments · Fixed by #598
Labels
Feature Feature request

Comments

@rudymatela
Copy link

Consider the following markdown file links.md:

### Reference-style links

This is a link to the [Python](https://python.org) website.

This is a link to the [Python] website.

This is a link to the [Python][] website.

[Python]: https://python.org

I can compile it with markdown2 as follows:

markdown2 links.md > links.html

When I open the HTML, this is what I get:

links

  1. The first link to python.org renders as "Python";
  2. The second link to python.org literally renders as [Python];
  3. The third link renders as "Python"

Is writing links as just [Python] supported? Or are only links with [Python][] supported?

Some other markdown engines (e.g.: GFM) support [Python]. Could this be added to markdown2 as an extra to be activated with -x?

I actually initially thought that [Python] was standard markdown. Upon looking at the syntax specification it seems only [Python][] would be standard. It nevertheless seems to be that the former is quite common, so I suggest adding it as an extension. (If you think this is a good idea of course.)

Debug info

$ python --version
Python 3.12.4

$ markdown2 --version
markdown2 2.5.0

I also tried with:

markdown2 -x footnotes links.md > links.html
@nicholasserra
Copy link
Collaborator

Interesting, I wouldn't be opposed to it. Assuming there's a good name for the extra lol.

@nicholasserra nicholasserra added the Feature Feature request label Sep 5, 2024
@rudymatela
Copy link
Author

@nicholasserra GFM calls [this] a shortcut reference link. I know that some other engines support this, but I don't know what they call it. "Shortcut reference link" seems appropriate enough.

[this]: https://example.com

In terms of the "extra" name on --help, you could have it called:

  1. shortcut-reference-link
  2. short-links
  3. link-shortcuts
  4. link-short
  5. link-shortref

Of the above, I personally would prefer 4 (link-short) as it would appear beside the related link-patterns in markdown2 --help. It is also brief. One suggestion for the help message would be "link-short: allow shortcut reference links, not followed by [] or a link label"

$ markdown2 --help
usage: markdown2 [PATHS...]

...
...
...
* html-classes: ...
* link-patterns: Auto-link given regex patterns in text (e.g. bug number
  references, revision number references).
* link-short: allow shortcut reference links, not followed by [] or a link label.
* markdown-in-html: ...
...
...
...

@nicholasserra
Copy link
Collaborator

It seems like we support the full reference links right now, without an extra. Wondering if we should just support the short without an extra too. This is just from a quick glance at the _do_links method. I'll have to do some testing.

@Crozzers
Copy link
Contributor

Crozzers commented Sep 9, 2024

I would agree with that approach.

I took a look at implementing this as a new style extra class and it's tricky to nail down. I settled on detecting snippets like [Python] and just adding the [] after them so that _do_links can process it normally. However, this didn't work particularly well and there were loads of edge cases.
Unless we spun the link processing out into a seperate link processing class (like the ItalicAndBoldProcessor) I don't think this approach is feasible.

I think making this part of _do_links is probably the most straightforward approach, and I don't mind if we gate it behind an extra or if we make it the default behaviour

Crozzers added a commit to Crozzers/python-markdown2 that referenced this issue Sep 21, 2024
nicholasserra added a commit that referenced this issue Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants