コード例 #1
0
        protected override bool ReplaceLink(ref IProcessLinkParameter parameters, LinkType linkType)
        {
            FoundLink link = ((ConceptualItemParameter)parameters).Link;
            string    href = ((ConceptualItemParameter)parameters).Href;

            string baseUrl = null;

            switch (linkType)
            {
            case LinkType.GeneralLink:
                baseUrl = BaseUrl;
                break;

            case LinkType.EnUsLink:
                baseUrl = BaseEnUsUrl;
                break;

            case LinkType.RelativeWoExt:
                baseUrl = BaseWoExtUrl;
                break;
            }

            if (baseUrl == null)
            {
                return(false);
            }

            if (Uri.TryCreate(new Uri(baseUrl), href.TrimStart('\\').TrimEnd(".md"), out Uri uri))
            {
                string query = GetQueryFromLink(link.Link);
                if (linkType == LinkType.EnUsLink)
                {
                    ReplacedEnUsLinks.AppendLine($"{SourceFilePath},{link.Link},\"{link.Title}\",{uri.AbsoluteUri},\"{link.Title + ExternalText}\"");
                }
                else
                {
                    ReplacedLinks.AppendLine($"{SourceFilePath},{link.Link},\"{link.Title}\",{uri.AbsoluteUri},\"{link.Title + ExternalText}\"");
                    string fileToRemove = href.TrimStart('\\');
                    if (!String.IsNullOrEmpty(query))
                    {
                        fileToRemove = fileToRemove.Replace(query, "");
                    }
                    if (Path.GetExtension(fileToRemove).Equals(".md", StringComparison.InvariantCultureIgnoreCase) && !FilesToRemove.Contains(fileToRemove))
                    {
                        FilesToRemove.Add(fileToRemove);
                    }
                }

                _newContent.Replace(link.FullMatch, link.FullMatch.Replace(link.Title, link.Title + ExternalText).Replace(link.Link, uri.AbsoluteUri));
                return(true);
            }
            Logger.LogWarning($"URI could not be created: {BaseUrl} {href}");
            return(false);
        }
コード例 #2
0
 public ConceptualItemParameter(ref string content, FoundLink link, string href)
 {
     Content = content;
     Link    = link;
     Href    = href;
 }