Modifying the .cson file of a core package (hyperlink)


#1

I have a problem that I imagine is quite simple to solve, but I am having a hard time trying to find a solution.

The hyperlink.cson file of the language-hyperlink package (https://github.com/atom/language-hyperlink/blob/master/grammars/hyperlink.cson) defines some patterns to highlight hyperlinks. I would like to modify those patterns, adding one new pattern to recognize the prefix “thunderlink”. So, basically I need to replace:

‘patterns’: [
{
‘match’: ‘(?x)\b(https?|s?ftp|ftps|file|smb|afp|nfs|(?:x-)?man(?:-page)?|gopher|txmt|issue)://((?!(\#[[:word:]]\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])’
‘name’: ‘markup.underline.link.$1.hyperlink’
}
{
‘match’: '(?x)\b(mailto):((?!(\#[[:word:]]
\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])’
‘name’: ‘markup.underline.link.$1.hyperlink’
}
{
‘match’: ‘(?i)\bRFC(?: |(?<= RFC))(\d+)\b’
‘name’: ‘markup.underline.link.rfc.$1.hyperlink’
}
]

by (just a “thunderlink” option is added in the first match):

patterns: [
{
match: "(?x)\b(https?|thunderlink|s?ftp|ftps|file|smb|afp|nfs|(?:x-)?man(?:-page)?|gopher|txmt|issue)://((?!(\#[[:word:]]\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])"
name: “markup.underline.link.$1.hyperlink”
}
{
match: "(?x)\b(mailto):((?!(\#[[:word:]]
\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])"
name: “markup.underline.link.$1.hyperlink”
}
{
match: "(?i)\bRFC(?: |(?<= RFC))(\d+)\b"
name: “markup.underline.link.rfc.$1.hyperlink”
}
]

But I do not know how to do that. Inspired by https://flight-manual.atom.io/using-atom/sections/basic-customization/, I tried by modifying the global Atom’s config.cson file and adding at the end the following code:

text:
hyperlink:
patterns: [
{
match: "(?x)\b(https?|thunderlink|s?ftp|ftps|file|smb|afp|nfs|(?:x-)?man(?:-page)?|gopher|txmt|issue)://((?!(\#[[:word:]]\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])"
name: “markup.underline.link.$1.hyperlink”
}
{
match: "(?x)\b(mailto):((?!(\#[[:word:]]
\#))(?:[-:@[:word:].,~%+_/?=&#;|!]))+(?<![-.,?:#;])"
name: “markup.underline.link.$1.hyperlink”
}
{
match: "(?i)\bRFC(?: |(?<= RFC))(\d+)\b"
name: “markup.underline.link.rfc.$1.hyperlink”
}
]

(as the scope for language-hyperlink is text.hyperlink)

However, this does not work. Any ideas about what is wrong? It seems that I am injecting the code in the wrong place. I tried other alternatives but with no success. Any help would be really useful.

Thank you in advance.


Styling a specific tag - i.e. "table" tag in AtomEditor?
#2

When posting code on here, you should fence it with backticks to mark it as code, like so:

```
Formatting and
               indentations will be preserved.
This also lets you use ` and <tags> without the forum trying to parse them.
```

For more information, you can look up GitHub-flavored markdown.


#3

[non-expert opinion]
Consider cloning the language package and customizing it to your needs.
I doubt it will be possible to customize in any other way.


#4
  1. Ideal: Submit a pull-request with your changes (and hope the developers merge them)

  2. Last resort: Create your own version (e.g “Hyperlink Expanded”), import the settings from the original package and overwrite some of its rules

name: "Hyperlink Expanded" # for lack of a better name
scopeName: "text.hyperlink.expanded" # for lack of a better name
fileTypes: []
injectionSelector: 'text - string.regexp, string - string.regexp, comment, source.gfm'
patterns: [
  {
    # Include the rules from the Hyperlink package 
    include: "text.hyperlink"
  }
  {
    # Override some of the original's rules
    'match': '(?x)\\b(
    https?|s?ftp|ftps|file|smb|afp|nfs|(?:x-)?man(?:-page)?|itmss|gopher|spotify|slack|txmt|thunderlink|issue
    )://((?!(\\#[[:word:]]*\\#))(?:[-:@[:word:].,~%+_\/?=&#;|!]))+(?<![-.,?:#;])'
    'name': 'markup.underline.link.$1.hyperlink'
  }
]

#5

Thank you for your reply.
Your reply has a positive approach aiming to better the original source too.




Please allow me to add some idea.

My research has uncovered an article (https://www.apeth.com/nonblog/stories/textmatebundle.html) where it states:

A patterns array is an array of match rules. The fact that it’s an array is important, because order matters. Matches are performed in the order listed. TextMate considers lines of a document one at a time, looking within each one for matches. When we make a match, that’s the end for everything in that line up to that point. Thus, you can effectively make conditional rules by judicious ordering of a patterns array.

Doing quick test revealed the following results:

Please correct me if I am wrong. If a new custom rule needs to take priority over the original, the new rule should be listed first in the pattern list.