public override void Parse(List<TextFragment> fragments, TransformationData data)
        {
            ParseElements(data, fragments, new EMMarkdownAndHTMLTagsParser(GetLocation, true));
            ParseElements(data, fragments, new EMSpanParser(GetLocation));

            foreach (var fragment in fragments)
            {
                var formattedText = new EMFormattedText(Document, new EMElementOrigin(fragment.Start, fragment.Text), this);

                formattedText.Parse(fragment.Text, data);

                Add(formattedText);
            }
        }
Esempio n. 2
0
        public override void Parse(List <TextFragment> fragments, TransformationData data)
        {
            ParseElements(data, fragments, new EMMarkdownAndHTMLTagsParser(GetLocation, true));
            ParseElements(data, fragments, new EMSpanParser(GetLocation));

            foreach (var fragment in fragments)
            {
                var formattedText = new EMFormattedText(Document, new EMElementOrigin(fragment.Start, fragment.Text), this);

                formattedText.Parse(fragment.Text, data);

                Add(formattedText);
            }
        }
Esempio n. 3
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);
                }
            }
        }