Пример #1
0
        private string StartLinkHandler(string[] startTagComponents)
        {
            string url    = startTagComponents[0];
            string extras = "";

            try
            {
                if (Path.GetExtension(url).Equals(Constants.TopicExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    int colonPos = url.IndexOf("::");

                    if (colonPos >= 0)  // a link to another help document
                    {
                        string document = url.Substring(0, colonPos);
                        string topic    = url.Substring(colonPos + 2);

                        _helpComponents.preprocessor.CheckExternalTopic(document, topic);
                        url = _topicCompilerSettings.ConstructLink(LinkType.ExternalTopic, new string[] { document, topic }, ref extras);
                    }

                    else
                    {
                        Preprocessor.TopicPreprocessor topic = _helpComponents.preprocessor.GetTopic(startTagComponents[0]);
                        url = _topicCompilerSettings.ConstructLink(LinkType.Topic, topic, ref extras);
                    }
                }

                else if ((url.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) == 0) ||
                         (url.IndexOf("mailto", StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    url = _topicCompilerSettings.ConstructLink(LinkType.Other, url, ref extras);
                }

                else
                {
                    throw new Exception("Link could not be processsed");
                }
            }

            catch (Exception exception)  // the topic wasn't found
            {
                throw new Exception(String.Format("The topic {0} is invalid ({1})", url, exception.Message));
            }

            return(String.Format("<a href=\"{0}\" {1}>", url, extras));
        }