public static EMElement CreateFromText(string text, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data, bool imageLink = false)
        {
            try
            {
                var path = EMPathProvider.CreatePath(text, doc, data);

                return(new EMRelativeLink(doc, origin, parent, path));
            }
            catch (EMPathVerificationException e)
            {
                return(new EMErrorElement(doc, origin, parent, e.AddToErrorList(data, origin.Text)));
            }
        }
Exemple #2
0
        public EMLink(EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data, EMPathProvider path, string title, EMSpanElements content)
            : base(doc, origin, parent)
        {
            Path = path;

            Title   = title;
            Content = content;

            if (path.ChangedLanguage)
            {
                AddMessage(
                    new EMReadingMessage(
                        MessageClass.Info, "BadLinkOrMissingMarkdownFileForLinkINTUsed", path.GetPath(data)),
                    data);
            }
        }
 private EMRelativeLink(EMDocument doc, EMElementOrigin origin, EMElement parent, EMPathProvider path)
     : base(doc, origin, parent)
 {
     this.path = path;
 }
Exemple #4
0
        private static EMElement Create(
            EMDocument doc,
            EMElementOrigin orig,
            EMElement parent,
            TransformationData data,
            EMSpanElements content,
            string path,
            string title)
        {
            try
            {
                bool   isAPILink = false;
                string APIMember = "";
                if (path.StartsWith("API:"))
                {
                    APIMember = path.Substring(4, path.Length - 4);
                    if (Markdown.APIFileLocation.ContainsKey(APIMember))
                    {
                        path = "https://docs.unrealengine.com/latest/INT/" + Markdown.APIFileLocation[APIMember].Replace("\\", "/") + "/index.html";
                    }
                    else
                    {
                        content.Parse(APIMember, data);
                        return(content);
                    }
                    isAPILink = true;
                }
                var pathProvider = EMPathProvider.CreatePath(path, doc, data);
                var errorId      = -1;

                if (pathProvider is EMLocalFilePath)
                {
                    var filePath = pathProvider as EMLocalFilePath;
                    if (!filePath.IsImage)
                    {
                        data.AttachNames.Add(
                            new AttachmentConversionDetail(filePath.GetSource(), filePath.GetAbsolutePath(data)));
                    }
                    else
                    {
                        data.ImageDetails.Add(
                            new ImageConversion(
                                filePath.GetSource(),
                                filePath.GetAbsolutePath(data),
                                0,
                                0,
                                false,
                                null,
                                Color.Transparent,
                                0));
                    }
                }

                if (content.ElementsCount == 0)
                {
                    if (pathProvider.IsBookmark)
                    {
                        errorId = data.ErrorList.Count;
                        data.ErrorList.Add(
                            Markdown.GenerateError(
                                Language.Message("LinkTextMustBeProvidedForBookmarkLinks", orig.Text),
                                MessageClass.Error,
                                Markdown.Unescape(orig.Text),
                                errorId,
                                data));
                    }
                    else if (pathProvider is EMLocalDocumentPath)
                    {
                        if (isAPILink)
                        {
                            content.Parse(APIMember, data);
                        }
                        else
                        {
                            content.Parse(
                                data.ProcessedDocumentCache.Variables.ReplaceVariables(
                                    content.Document, "%" + path + ":title%", data),
                                data);
                        }
                    }
                    else if (pathProvider is EMLocalFilePath)
                    {
                        if (isAPILink)
                        {
                            content.Parse(APIMember, data);
                        }
                        else
                        {
                            // If no link text provided use the file name.
                            content.Parse(Regex.Replace(pathProvider.GetPath(data), @".*[\\|/](.*)", "$1"), data);
                        }
                    }
                    else
                    {
                        if (isAPILink)
                        {
                            content.Parse(APIMember, data);
                        }
                        else
                        {
                            // If no link text provided use the url (remove protocol, e.g. ftp:// http://).
                            content.Parse(Regex.Replace(pathProvider.GetPath(data), @"([^:]+://)?(.*)", "$2"), data);
                        }
                    }
                }

                if (errorId != -1)
                {
                    return(new EMErrorElement(doc, orig, parent, errorId));
                }

                if (isAPILink)
                {
                    return(new EMLink(doc, orig, parent, data, pathProvider, APIMember, content));
                }
                else
                {
                    return(new EMLink(doc, orig, parent, data, pathProvider, title, content));
                }
            }
            catch (EMPathVerificationException e)
            {
                if (doc.PerformStrictConversion())
                {
                    return(new EMErrorElement(doc, orig, parent, e.AddToErrorList(data, orig.Text)));
                }
                else
                {
                    EMFormattedText Text = new EMFormattedText(doc, orig, parent);
                    Text.Parse(orig.Text, data);
                    return(Text);
                }
            }
        }