Link definitions in syntaxes

Hey @agiletortoise (or anyone else who can confirm): would I be correct in thinking that you can only specify one link definition per syntax?

hey @jsamlarose, I took a look at the docs and it seems like the “linkDefinitions” uses an array so you could specify multiple objects in a given syntax. I don’t understand why that would be the case but I do see it there. I also see that in my own custom syntax, I created an array as well (I guess as a backup to not screw up the original) and it seems to be working fine.

I’m curious to know what you’re trying to do exactly. I was wondering why it was an array object in the docs.

1 Like

Interesting. Thanks. I did take a look at the docs, and tried to add a second link definition in my own syntax, but it didn’t work, so maybe I just went about it in the wrong way. I’ll take another look.

I was experimenting with enabling inline hash-tags AND wiki-links in the same syntax… :wink:

Should support multiple linkDefinition entries. You need to make sure they don’t conflict/overlap, but that should not be a problem. Here’s a quick, rough version of an entry for hash tags (currently just looks up by title, not sure what you want it to do:

[
  {
    "match": "(#)()([^ ]+)",
    "templates": {
      "": "drafts://open?title=[[value]]&allowCreate=true"
    },
    "enabled": true,
    "captures": {
      "value": "3",
      "key": "2",
      "prefix": "1",
      "link": "3"
    },
    "scopes": {
      "value": "text.italic",
      "key": "text.bold",
      "prefix": "markup",
      "suffix": "markup"
    }
  }
]
1 Like

So are you looking to implement something that would pick up and link to [[#some_awesome_hashtag]]? I’m guessing it means you want to create links that would open up a list of all drafts tagged with what’s specified? Happy to help out on this. Could be really interesting!

1 Like

Love it. Many thanks. Experimenting now. Ultimately, I’ll wire this into my own search action, but my first step is just understanding how to appropriately write this into the existing array. If I already have a link definition, would I simply be tacking this onto the end of the existing the array, something like:

  "linkDefinitions": [
    {
      "match": "(\\[\\[)(((d|u|s|w|gt|map|node|google|wikipedia|bear|url|sc|ax|sx|@):)?([^\\[]+?))(\\]\\])",
      "templates": {
        "": "drafts://open?title=[[value]]&allowCreate=true",
        "google": "https://www.google.com/search?q=[[value]]",
        "wikipedia": "https://en.wikipedia.org/wiki/[[value]]",
        "u": "drafts://open?uuid=[[value]]",
        "d": "drafts://open?title=[[value]]&allowCreate=true",
        "bear": "bear://x-callback-url/open-note?title=[[value]]",
        "w": "drafts://workspace?name=[[value]]",
        "s": "drafts://quickSearch?query=[[value]]",
        "sc": "drafts://x-callback-url/runAction?text=[[value]]&action=run%20shortcuts%20from%20wikilink",
        "sx": "drafts://x-callback-url/runAction?text=fromWikiLink:[[value]]&action=Block%20level%20filter%20%28MGCL%2Fsearch%29",
        "ax": "drafts://runAction?text=&action=[[value]]",
		"map": "ithoughts://open?path=/iCloud/[[value]].itmz",
		"node": "ithoughts://x-callback-url/amendMap?path=/iCloud/OVERVIEW&target=[[value]]&text=x&edit=NO",
		"gt": "goodtask3://search?keyword=[[value]]",
		"@": "drafts://x-callback-url/runAction?text=[[value]]&action=People",
        "url": "[[value_unencoded]]"
      },
      "enabled": true,
      "captures": {
        "value": "5",
        "key": "4",
        "prefix": "1",
        "suffix": "6",
        "link": "2"
      },
      "scopes": {
        "value": "text.italic",
        "key": "text.bold",
        "prefix": "markup",
        "suffix": "markup"
      },
    "match": "(#)()([^ ]+)",
    "templates": {
      "": "drafts://open?title=[[value]]&allowCreate=true"
	    },
	    "enabled": true,
	    "captures": {
	      "value": "3",
	      "key": "2",
	      "prefix": "1",
	      "link": "3"
	    },
	    "scopes": {
	      "value": "text.italic",
	      "key": "text.bold",
	      "prefix": "markup",
	      "suffix": "markup"
	    }
    }
  ],

Love that spirit, @motopascyyy! Thanks for pitching in. Not wiki-linked hashtags, just a syntax definition with wiki-links and hash-tags. So I could have both [[link to draft]] and #awesome_hashtag picked up without having to switch syntaxes.

Plan is to point it towards the block level filter action I’ve been rambling about recently; that’ll call up not just the drafts, but individual paragraphs that contain that tag. For example, I could have a #follow_up tag, and click on it to pull up a list of all items I want to follow up on. Or anything else that might benefit from that kind of surfacing…

That syntax does not look quite valid, are you using a JSON editing tool? It helps a lot. I use JSON Editor on the Mac.

Here’s the full entry in my test syntax:

{
  "linkDefinitions": [
    {
      "match": "(\\[\\[)(((d|u|s|w|google|wikipedia|bear|url):)?([^\\[]+?))(\\]\\])",
      "templates": {
        "": "drafts://open?title=[[value]]&allowCreate=true",
        "google": "https://www.google.com/search?q=[[value]]",
        "wikipedia": "https://en.wikipedia.org/wiki/[[value]]",
        "u": "drafts://open?uuid=[[value]]",
        "d": "drafts://open?title=[[value]]&allowCreate=true",
        "bear": "bear://x-callback-url/open-note?title=[[value]]",
        "w": "drafts://workspace?name=[[value]]",
        "s": "drafts://quickSearch?query=[[value]]",
        "url": "[[value_unencoded]]"
      },
      "enabled": true,
      "captures": {
        "value": "5",
        "key": "4",
        "prefix": "1",
        "suffix": "6",
        "link": "2"
      },
      "scopes": {
        "value": "text.italic",
        "key": "text.bold",
        "prefix": "markup",
        "suffix": "markup"
      }
    },
    {
      "match": "(#)()([^ ]+)",
      "templates": {
        "": "drafts://open?title=[[value]]&allowCreate=true"
      },
      "enabled": true,
      "captures": {
        "value": "3",
        "key": "2",
        "prefix": "1",
        "link": "3"
      },
      "scopes": {
        "value": "text.italic",
        "key": "text.bold",
        "prefix": "markup",
        "suffix": "markup"
      }
    }
  ]
}
1 Like

You’re right (of course)— my edit didn’t work, although it didn’t throw up any error indicators in Textastic at first glance. Will plug your edit in now…

Okay. Pretty much there. Really appreciate the support.

One more thing: if I want to target the styling (specifically the colour) of these tags, without impacting any other links, what would I need to look at? And/or: what default scope is a link definition styled by— is it text.activeLink? I see I can’t set the scope for a link in the link definition itself…

Links cannot be different colors. This is a platform limitation on the way text views render links. There’s just one link color, which is controller by the colors.editor.link key in the theme.

1 Like

Ahhh. Got it. This is got me as far as I could ask for, then. Appreciate it.