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

convert inline links to references? #420

Open
anarcat opened this issue Dec 21, 2023 · 6 comments
Open

convert inline links to references? #420

anarcat opened this issue Dec 21, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@anarcat
Copy link

anarcat commented Dec 21, 2023

Context

I'm an apologetic reference link fan. For me, they make the source document easier to read, and I often send markdown documents by email (for various reasons) where it is particularly important to get those pesky links out of the way.

Proposal

It would be nice if mdformat could (optionally? in a plugin?) completely convert all inline links to references in a document. It's not a simple task, as references might clash with each other, so there needs to be some tracking for that...

I understand if that can't be part of mdformat per se, but I figured i would use this space to open up discussion about this, perhaps someone else has already found and fixed that problem themselves?

Thanks!

Tasks and updates

No response

@anarcat anarcat added the enhancement New feature or request label Dec 21, 2023
Copy link

welcome bot commented Dec 21, 2023

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@pawamoy
Copy link

pawamoy commented Apr 14, 2024

Super interested by this as well. Would be happy to try and send a PR if a maintainer can provide some initial guidance 😄

@nuke-web3
Copy link

Would love to see this - but it does mean this tooling needs to make very opinionated decisions about how to make the translation from inline -> reference links work

  • what is the ID system enforced? ( [text used][ID])
  • what is the location of reference links in a page? (always at the end?)
    • how are references sorted? (ID alphanumeric decending?)
  • is the inverse possible? (replace ID with URL)

@pawamoy
Copy link

pawamoy commented Jun 20, 2024

Good questions.

  • ID system: I'd say, use the text as-is, i.e. [some text] or [some text][], and [some text]: url. The user can then change the ID and mdformat would respect it next times it formats.
  • location: I think it currently always puts all references at the end of the page
  • sorting: I'd say sort on IDs yes, lower case, 0 -> 9 then a -> z
  • seems doable. Might be done in later PRs?

We just need updates from maintainers 🙂

@hukkin
Copy link
Collaborator

hukkin commented Oct 23, 2024

Fun fact: mdformat was inline links only originally #32


This shouldn't be hard to do at all. Mdformat already places references at the end of the document, orders alphabetically, canonicalizes labels to lower case, removes duplicate refs, removes unused refs etc. so much of what has been discussed here is already implemented.

It's just that we have to come up with the link label completely on our own.

I'd say, use the text as-is

This isn't a good enough spec. The link text can be empty string, link label cannot. Link text is unlimited in size, link label is limited to 999 characters. There's probably more pitfalls.

An alternative is to number the labels, 1, 2, 3, 4, ... . There are certainly documents that have more than 1000 links though.

So I think in extreme cases we probably have to resort to some kind of hash values.

So I'm not sure about this at all. If anyone wants this to happen, please come up with the perfect spec and we can consider. 😄


Maybe even more importantly, I have a feeling there's more users that don't want this feature than those who do. I may be wrong. If there's anyone who has a use case where this feature would really suck, please write in this thread! 😄

In any case, the plugin API remains to be there for people who want to extend mdformat.

@pawamoy
Copy link

pawamoy commented Oct 23, 2024

Thanks for the update @hukkin, and for pointing out the shortcomings of the proposal 🙂 I might try to write a plugin for that! That would be a good first exercise to get to know mdformat's internals 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants