Sublime Forum

Convert Inline MarkDown Links to Reference Links

#1

I really like StackExchange (StackOverflow) MarkDown editor.
Specifically the way it handles links entered by Ctrl+L. It uses Reference Style links to keep the text simple and clean.

I was looking for a way to do so on VS Code / Sublime Text.
I encountered this - Convert Markdown Links from Inline to Reference.

While it is not perfect it might be useful for others here.
Maybe even someone will create something better.

My wish is to have the same functionality as in StackExchange.

0 Likes

Extracting the Captures from `find_all()` in the `View()` Class
#2

If I use ctrl + k in the SO editor, all it does is enter a inline code block. Maybe a GIF would help understand ?

0 Likes

#3

I was wrong, the shortcut is Ctrl + L.

0 Likes

#4

thanks for sharing. Reference links have a cleaner look. can you highlight the differences between not perfect/perfect? It’s not immediatel obvious.

0 Likes

#5

Perfect, in my opinion, would do the following:

  1. It will convert inline links to reference.
  2. Arrange the links by the order they appear.
  3. Keep the : in reference aligned. Such that if there are more than 9 links it will use [01]:, [02]:, …, [10]:. For more than 99 it will have the pattern of [001]:, etc…
  4. It will remove duplicates links to have the same reference.

StackExchange does (2) and (4) perfectly. I think someone who knows Python can do all 4 pretty easily.

0 Likes

#6

With plugins, it is possible. Tried to kind of replicate the functionality of ctrl + l in SO. Is this something close to what you had in mind ?

Note: This may already be possible by an existing Markdown package.

2 Likes

#7

This is cool. Certainly in the right direction. Could you share the code? Can it support the case of marked text and then Ctrl + L?

0 Likes

#8

Here you are https://gist.github.com/Ultra-Instinct-05/53acd9f84bb06e5a0d0ff37dead10c58
As a fair warning, there might be a fair number of corner cases not handled. Anyways, I had some good fun with this one. Thanks !

0 Likes

#9

Never worked with an extension and doing my first steps in Python. Is there a way to debug it or any other way to go through it to understand what’s going on?

0 Likes

#10

Are you confused with how to use it or how it works ? If the latter, then of course it assumes some familiarity with the Plugin API (& of course Python). If you have never written plugins before, then this might be a good primer on it

0 Likes

#11

I just auto-hide urls.

0 Likes

#12

What about recycling the same links?
Hiding them doesn’t help here.

0 Likes

#13

recycling?

0 Likes

#14

I can use the same link over and over.
In your method it will appear (The whole address) again and again while using references it will appear only once (And the reference which is much shorter).

0 Likes

#15

Hiding links is not meant to replace references at all, but only make text more readable in case those inline urls are used.

0 Likes

#16

I think you’re missing the context when I say reference.

Anyhow, it is great you found your method to be effective.

0 Likes

#17

I got your point already with your first post. Just wanted to note hiding to be an alternative in use cases of reading existing files without refactoring them.

1 Like