Argentini.Halide.H3Text.AutoHyperlinks C# (CSharp) Méthode

AutoHyperlinks() public static méthode

and tags are ignored. Any linkable items within a [nolink][/nolink] or region are ignored. ]]>
public static AutoHyperlinks ( string strVar, string param ) : String
strVar string String to process.
param string /// tags, like target="_blank". /// ]]> ///
Résultat String
        public static String AutoHyperlinks(string strVar, string param)
        {
            string final = strVar;
            string section = String.Empty;
            Regex regex;
            MatchCollection theMatches;
            int checkNoLink = 0;
            int checkATAG = 0;
            int checkIMG = 0;

            // Switch out periods within a <nolink> region to prevent processing

            if(InStr(final, "/nolink>") > 0) checkNoLink = 1;
            if(InStr(final, "/nolink]") > 0) checkNoLink = 2;

            if(checkNoLink == 1)
            {
                regex = new Regex(@"<nolink>(.*?)</nolink>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(final);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace(".", "[[[pk:period]]]"));
                }
            }

            if(checkNoLink == 2)
            {
                regex = new Regex(@"\[nolink\](.*?)\[/nolink\]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(final);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace(".", "[[[pk:period]]]"));
                }
            }

            // Make email addresses mailto links

            if(InStr(final, "@") > 0)
            {
                regex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(final);

                if(theMatches.Count > 0) checkATAG = 1;

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), "<a href=\"mailto:" + theMatches[index].ToString() + "\">" + theMatches[index].ToString() + "</a>");
                }
            }

            if(checkATAG == 0)
            {
                if(InStr(final, "<a") > 0) checkATAG = 1;
            }

            // Switch out periods within a <a> region to prevent processing

            if(checkATAG == 1)
            {
                regex = new Regex(@"<a(.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(final);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace(".", "[[[pk:period]]]"));
                }
            }

            if(InStr(final, "<img ") > 0) checkIMG = 1;

            // Switch out periods within a <img> tags to prevent processing

            if(checkIMG == 1)
            {
                regex = new Regex(@"<img (.*?)>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

                theMatches = regex.Matches(final);

                for (int index = 0; index < theMatches.Count; index++)
                {
                    final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace(".", "[[[pk:period]]]"));
                }
            }

            // Switch out periods within numeric values that appear to be valid domain names

            Regex tags = new Regex(@"[^\.\da-zA-Z\-\?\&\=]{1,}[^\.\d\?\&\=]*([\d]*\.[\d]{1,}([\.][\d]{1,})*)[^\.a-zA-Z\-]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            theMatches = tags.Matches(final);

            if(theMatches.Count > 0) checkATAG = 1;

            for (int index = 0; index < theMatches.Count; index++)
            {
                final = final.Replace(theMatches[index].ToString(), theMatches[index].ToString().Replace(".", "[[[pk:period]]]"));
            }

            // H3Identify all potential URLs and domain names and make them hyperLinks

            //		tags = new Regex(@"([a-zA-Z0-9\:/\-]*[a-zA-Z0-9\-_]\.[a-zA-Z0-9\-_][a-zA-Z0-9\-_][a-zA-Z0-9\?\=&#_\-/\.\:]*[^<>,;\.\s\)\(\]\[\""])", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            //		tags = new Regex(@"(?:(http|https|ftp)://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)?)[^<>,;\.\s\)\(\]\[\""]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            //		tags = new Regex(@"(?:([a-zA-Z]{0,8}://)(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)?)[^<>,;\.\s\)\(\]\[\""]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            //		tags = new Regex(@"[a-zA-Z]{0,8}:{0,}/(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)[^<>,;\.\s\)\(\]\[\""]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            //		tags = new Regex(@"([a-zA-Z]{0,8}://){0,}(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{2}))|[;:@&=])*))?)[^<>,;\.\s\)\(\]\[\""]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            tags = new Regex(@"([a-zA-Z]{3,10}://[a-zA-Z0-9\-_\.]{1,}[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z][a-zA-Z0-9\?\=&#_\-/\.\:;]*[^<>,;\.\s\)\(\]\[\""])", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            theMatches = tags.Matches(final);

            if(theMatches.Count > 0) checkATAG = 1;

            for (int index = 0; index < theMatches.Count; index++)
            {
                section = theMatches[index].ToString();

                final = final.Replace(theMatches[index].ToString(), "<a href=\"" + section.Replace(".", "[[[pk:period]]]") + "\" " + param + ">" + theMatches[index].ToString().Replace(".", "[[[pk:period]]]") + "</a>");
            }

            tags = new Regex(@"([a-zA-Z0-9\-_]{1,}[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z][a-zA-Z0-9\?\=&#_\-/\.\:;]*[^<>,;\.\s\)\(\]\[\""])", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            theMatches = tags.Matches(final);

            if(theMatches.Count > 0) checkATAG = 1;

            for (int index = 0; index < theMatches.Count; index++)
            {
                section = theMatches[index].ToString();

                section = "http://" + section;

                final = final.Replace(theMatches[index].ToString(), "<a href=\"" + section.Replace(".", "[[[pk:period]]]") + "\" " + param + ">" + theMatches[index].ToString().Replace(".", "[[[pk:period]]]") + "</a>");
            }

            // Clear out escape sequences and [nolink][/nolink] or <nolink></nolink> tags

            final = final.Replace("[[[pk:period]]]", ".");

            final = final.Replace("<nolink>", "");
            final = final.Replace("</nolink>", "");
            final = final.Replace("[nolink]", "");
            final = final.Replace("[/nolink]", "");

            return final;
        }