How to disable automatic links in code

edited April 2012 in Vanilla 2.0 - 2.8

#Text in posts automatically links to the search results page for the word 'Text'
@Text in posts automatically links to the profile page of the user with username 'Text'

This is very useful, but not inside code blocks. When I use '@import' in CSS, that text is automatically linked to a user profile, and #ID... you know the drill.

How can I disable this in 'code' and 'pre' blocks? has anyone given a thought to it? If not possible, I would like to disable them completely.

Best Answers

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    should remove both #hashtags and mentions @badlearner at least in 2.0.18.4

    $Configuration['Garden']['Format']['Mentions'] = FALSE;
    $Configuration['Garden']['Format']['Hashtags'] = FALSE;
    

    If you want to test for a code and pre blocks you probably need to reprogram
    /library/core/class.format.php - search for mentions and hashtags and do a preg match conditional on string and test for code and pre matches to skip the routine.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    in 2.18.0.4 assuming you don't add

    $Configuration['Garden']['Format']['Mentions'] = FALSE;

    and you want to selectively filter out @ only if code or pre statements exist

    original /library/core/class.format.php

       // Handle @mentions.
                     if(C('Garden.Format.Mentions')) {
                        $Mixed = preg_replace(
                           '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                           '\1'.Anchor('@\2', '/profile/\\2'),
                           $Mixed
                        );
                     }
    

    modified - if the word <code or <pre or exists in the body of message than @ is disabled

    the i means match any case Code code CODE, etc

            // Handle @mentions.
             if(C('Garden.Format.Mentions')) {
               if((!preg_match("/<code/i",$Mixed)) && (!preg_match("/<pre/i",$Mixed)) ){
                $Mixed = preg_replace(
                   '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                   '\1'.Anchor('@\2', '/profile/\\2'),
                   $Mixed
                );
                  }
             }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Answers

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    should remove both #hashtags and mentions @badlearner at least in 2.0.18.4

    $Configuration['Garden']['Format']['Mentions'] = FALSE;
    $Configuration['Garden']['Format']['Hashtags'] = FALSE;
    

    If you want to test for a code and pre blocks you probably need to reprogram
    /library/core/class.format.php - search for mentions and hashtags and do a preg match conditional on string and test for code and pre matches to skip the routine.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    in 2.18.0.4 assuming you don't add

    $Configuration['Garden']['Format']['Mentions'] = FALSE;

    and you want to selectively filter out @ only if code or pre statements exist

    original /library/core/class.format.php

       // Handle @mentions.
                     if(C('Garden.Format.Mentions')) {
                        $Mixed = preg_replace(
                           '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                           '\1'.Anchor('@\2', '/profile/\\2'),
                           $Mixed
                        );
                     }
    

    modified - if the word <code or <pre or exists in the body of message than @ is disabled

    the i means match any case Code code CODE, etc

            // Handle @mentions.
             if(C('Garden.Format.Mentions')) {
               if((!preg_match("/<code/i",$Mixed)) && (!preg_match("/<pre/i",$Mixed)) ){
                $Mixed = preg_replace(
                   '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
                   '\1'.Anchor('@\2', '/profile/\\2'),
                   $Mixed
                );
                  }
             }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine : You're awesome. Thanks a lot!

  • glad you liked it :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.