Sublime Forum

Hiding URLs in Markdown

#1

I’m trying out Sublime Text, and there’s a feature I miss from Emacs very much. When I write an line Markdown link in Emacs, the URL is hidden. Even if the link is something long and ugly (which it often is in my case), you see

 [Here's a link](∞)

Is there a way I can get Sublime Text to do something like this for inline links?

I’m also looking for a way to get headers to appear larger at higher levels, so the single pound sign headers using a bigger font than two pound sign headers, etc., and would appreciate pointers although the links thing is the bigger concern.

1 Like

#2

Sublime won’t do this by default, but it’s possible via a plugin. An example of that which does this whenever you open a file is below (see this video if you’re not sure how to install a plugin) and there may also be something on Package Control as well.

This creates a new markdown_fold_links command and then triggers it whenever a file loads and whenever a file is saved. You could also bind the command to a key if you want to trigger it manually (and then remove one or both of the event handlers as well if desired):

import sublime
import sublime_plugin


class MarkdownFoldLinksCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.fold(self.view.find_by_selector("meta.link.inline markup.underline.link"))

    def is_enabled(self):
        return self.view.match_selector(0, "text.html.markdown")


class MarkdownLinkFolder(sublime_plugin.ViewEventListener):
    @classmethod
    def is_applicable(cls, settings):
        return settings.get("syntax").endswith("Markdown.sublime-syntax")

    def on_load(self):
        self.view.run_command("markdown_fold_links")

    on_post_save = on_load

That will fold up inline links but leave <https://somewhere.com> style links alone (although with a slight tweak you can fold those too). In practice that looks something like this; the color you see for the fold icon depends on your color scheme:

You can use the items in Edit > Code Folding to unfold links if you want to see them; for example by selecting one and using the menu item or key binding visible there.

Although you can adjust the font_face and font_size on a file by file basis (or file type by file type or project by project), a file is locked to one specific font face and font size. The color scheme can apply bold and italic to text, but it can’t adjust the font face or font size of text away from the currently configured size.

3 Likes