Exemplo n.º 1
0
        public string FilterOut(string text, TransformationData data, PreprocessedData preprocessedData)
        {
            var map = preprocessedData.TextMap;

            try
            {
                foreach (var element in elements)
                {
                    var changes = new List<PreprocessingTextChange>();

                    text = element.Pattern.Replace(text, m => FilterEvaluator(m, element.Predicate, changes));

                    Preprocessor.AddChangesToBounds(map, changes, preprocessedData, PreprocessedTextType.FilteredOut);

                    map.ApplyChanges(changes);
                }
            }
            catch (FilterPredicateException e)
            {
                data.ErrorList.Add(Markdown.GenerateError(
                    e.Message, MessageClass.Error, "", 0, data));
            }

            return text;
        }
Exemplo n.º 2
0
 public EMDocument(string path, TransformationData data)
 {
     LocalPath = path;
     TransformationData = data;
     preprocessedData = new PreprocessedData(this, data.ProcessedDocumentCache);
     publish = false;
 }
        public int AddToErrorList(TransformationData data, string originalText)
        {
            var errorId = data.ErrorList.Count;
            data.ErrorList.Add(Markdown.GenerateError(Message, MessageClass.Error, originalText, errorId, data));

            return errorId;
        }
Exemplo n.º 4
0
 public override void AppendHTML(StringBuilder builder, Stack<EMInclude> includesStack, TransformationData data)
 {
     builder.Append(
         Templates.Region.Render(
             Hash.FromAnonymousObject(
                 new { regionParameters = RegionParam, regionContent = Elements.GetInnerHTML(includesStack, data), singleLine })));
 }
Exemplo n.º 5
0
        public string Preprocess(string text, TransformationData transData, PreprocessedData data, string relativePathToLinkedFile = null, bool full = true)
        {
            var relPath = relativePathToLinkedFile ?? transData.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf;

            text = Normalizer.Normalize(text, data.TextMap);

            text = OffensiveWordFilterHelper.CheckAndGenerateInfos(text, data.TextMap);

            text = EscapeChars(text, data.TextMap);

            text = DoCodeSpans(text, data.TextMap);

            text = data.Metadata.ParseMetadata(text, transData, data, full);

            text = filter.FilterOut(text, transData, data);

            text = data.Variables.ParseVariablesDefinition(text, relPath, transData, data.TextMap);

            data.ExcerptTextMap = new PreprocessedTextLocationMap(data.TextMap);
            text = data.Excerpts.ParseExcerpts(text, transData, data.TextMap);

            text = data.ReferenceLinks.Parse(text, data);

            text = CutoutComments(text, data);

            return text;
        }
Exemplo n.º 6
0
        private string ParseVariableDefinition(Match everyMatch, string relPath, TransformationData data)
        {
            var value = everyMatch.Groups["variableContent"].Value.Replace("<a name=\"MARKDOWNANCHORNOTUSEDELSEWHERE\"></a>", "");

            Add(everyMatch.Groups["variableName"].Value.ToLower(), value, data, relPath);

            return "";
        }
Exemplo n.º 7
0
        public static EMElement CreateRegion(EMElementOrigin origin, EMDocument doc, EMElement parent, TransformationData data, EMMarkdownTaggedElementMatch match, string regionParameters)
        {
            var content = new EMRegion(doc, origin, parent, match, regionParameters);

            content.Elements.Parse(0, Markdown.OutdentIfPossible(match.Content, content.Elements.TextMap), data);

            return content;
        }
        public EMLocalFilePath(string userPath, EMDocument doc, TransformationData data, Func<string, string> outputFileNameConversion = null)
        {
            userPath = Preprocessor.UnescapeChars(userPath, true);

            if (userPath.StartsWith("%ROOT%"))
            {
                userPath = userPath.Replace("%ROOT%", ".");
            }

            if (outputFileNameConversion == null)
            {
                outputFileNameConversion = NoConversion;
            }

            var localized = data.CurrentFolderDetails.Language != "INT";
            IsImage = ImageExtensionPattern.IsMatch(userPath);

            var sourceDocDir = GetDirectoryName(userPath, doc, data);
            var fileName = Path.GetFileName(userPath);

            absolutePath = GetAbsoluteFilePath(sourceDocDir, fileName, data, localized);
            dstRelative = localized
                              ? Path.Combine(
                                  GetFolderTypeName(),
                                  sourceDocDir,
                                  data.CurrentFolderDetails.Language,
                                  outputFileNameConversion(Path.GetFileName(userPath)))
                              : Path.Combine(
                                  GetFolderTypeName(),
                                  sourceDocDir,
                                  outputFileNameConversion(Path.GetFileName(userPath)));

            if (!File.Exists(absolutePath))
            {
                if (localized)
                {
                    absolutePath = GetAbsoluteFilePath(sourceDocDir, fileName, data, false);
                    changedLanguage = File.Exists(absolutePath);
                }

                if (!localized || !changedLanguage)
                {
                    throw new EMPathVerificationException(
                        Language.Message(
                            string.Format(
                                "{0}FileNotFoundIn{1}INTDir",
                                IsImage ? "Image" : "Attachment",
                                data.CurrentFolderDetails.Language != "INT" ? "LanguageOr" : ""),
                            absolutePath));
                }

                dstRelative = Path.Combine(
                    GetFolderTypeName(),
                    sourceDocDir,
                    outputFileNameConversion(Path.GetFileName(userPath)));
            }
        }
Exemplo n.º 9
0
        private static EMElement CreateDecoration(IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var decorationMatch = match as EMDecorationMatch;

            var element = new EMDecorationElement(doc, origin, parent, decorationMatch.Type);
            element.Content.Parse(decorationMatch.ContentStart, decorationMatch.Content, data);

            return element;
        }
Exemplo n.º 10
0
 public override void AppendHTML(StringBuilder builder, Stack<EMInclude> includesStack, TransformationData data)
 {
     builder.Append(Templates.CustomTag.Render(Hash.FromAnonymousObject(
         new
             {
                 tagName = name,
                 attributesList = attributesString,
                 content = Elements.GetInnerHTML(includesStack, data)
             })));
 }
Exemplo n.º 11
0
        private static EMHeader CreateFromSetextMatch(Match match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var headerText = match.Groups[2].Value;
            var level = match.Groups[3].Value.StartsWith("=") ? 1 : 2;
            var isOptional = string.IsNullOrWhiteSpace(match.Groups[1].Value);

            headerText = Markdown.Unescape(data.Markdown.RunSpanGamut(headerText, data));

            return new EMHeader(doc, origin, parent, level, headerText, isOptional);
        }
Exemplo n.º 12
0
 public static EMErrorElement Create(
     EMDocument doc,
     EMElementOrigin origin,
     EMElement parent,
     TransformationData data,
     string messageId,
     params string[] messageArgs)
 {
     return new EMErrorElement(doc, origin, parent, new EMReadingMessage(MessageClass.Error, messageId, messageArgs), data);
 }
        public void AddToErrorListAndAppend(StringBuilder builder, TransformationData data, string originalText)
        {
            var errorId = AddToErrorList(data, originalText);

            if (data.Markdown.ThisIsPreview)
            {
                builder.Append(
                    Templates.ErrorHighlight.Render(
                        Hash.FromAnonymousObject(new { errorText = originalText, errorId })));
            }
        }
Exemplo n.º 14
0
 public override void AppendHTML(StringBuilder builder, Stack<EMInclude> includesStack, TransformationData data)
 {
     try
     {
         builder.Append(path.GetPath(data).Replace("\\", "/"));
     }
     catch (EMPathVerificationException e)
     {
         e.AddToErrorListAndAppend(builder, data, Origin.Text);
     }
 }
Exemplo n.º 15
0
        public override void AppendHTML(StringBuilder builder, Stack<EMInclude> includesStack, TransformationData data)
        {
            var content = Elements.GetInnerHTML(includesStack, data);

            content = NewlinePattern.Replace(content, "  ");

            // These leading spaces screw with <pre> content, so we need to fix that:
            content = PreTagPattern.Replace(content, BlockQuotePreLeadingSpacesFix);

            builder.Append(Templates.Blockquote.Render(Hash.FromAnonymousObject(new { value = content })));
        }
Exemplo n.º 16
0
        public static void ParseElements(
            TransformationData data,
            EMDocument doc,
            EMElement parent,
            string text,
            IParser parser,
            Action<EMElement> elementEmitter)
        {
            var fragments = new List<TextFragment> { new TextFragment(0, text) };

            ParseElements(data, doc, parent, fragments, parser, elementEmitter);
        }
Exemplo n.º 17
0
        private static EMElement CreateItem(EMListType type, EMDocument doc, Match match, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var itemGroup = match.Groups[4];

            var item = new EMListItem(doc, origin, parent, type);

            // adding offset to text map
            item.Elements.TextMap.ApplyChanges(new List<PreprocessingTextChange>() { new PreprocessingTextChange(0, itemGroup.Index - match.Index, 0) });

            item.Elements.Parse(0, Markdown.Outdent(itemGroup.Value, item.Elements.TextMap), data);

            return item;
        }
Exemplo n.º 18
0
 public static void ParseElements(
     TransformationData data,
     EMDocument doc,
     EMElement parent,
     List<TextFragment> fragments,
     List<IParser> parsers,
     Action<EMElement> elementEmitter)
 {
     foreach (var parser in parsers)
     {
         ParseElements(data, doc, parent, fragments, parser, elementEmitter);
     }
 }
Exemplo n.º 19
0
        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));
            }
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
 public override void Parse(List<TextFragment> fragments, TransformationData data)
 {
     ParseElements(data, fragments, new EMMarkdownAndHTMLTagsParser(GetLocation));
     ParseElements(data, fragments, EMHeader.GetParser());
     ParseElements(data, fragments, EMInclude.GetParser());
     ParseElements(data, fragments, EMTOCInline.GetParser());
     ParseElements(data, fragments, EMBookmark.GetParser());
     ParseElements(data, fragments, EMHorizontalRule.GetParser());
     ParseElements(data, fragments, EMList.GetParser());
     ParseElements(data, fragments, EMTable.GetParser());
     ParseElements(data, fragments, EMCodeBlock.GetParser());
     ParseElements(data, fragments, EMBlockQuotes.GetParser());
     ParseElements(data, fragments, EMParagraph.GetParser());
 }
Exemplo n.º 22
0
        public override EMElement Create(IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            if (match is EMBracketedImagesAndLinksMatch)
            {
                return CreateBracketed(match, doc, origin, parent, data);
            }

            if (match is EMDecorationMatch)
            {
                return CreateDecoration(match, doc, origin, parent, data);
            }

            throw new InvalidOperationException("Should not happend!");
        }
Exemplo n.º 23
0
        private static EMElement Create(Match match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var bqTextGroup = match.Groups[1];
            var bqText = bqTextGroup.Value;

            bqText = Regex.Replace(bqText, @"^[ ]*>[ ]?", "", RegexOptions.Multiline);       // trim one level of quoting
            bqText = Regex.Replace(bqText, @"^[ ]+$", "", RegexOptions.Multiline);           // trim whitespace-only lines

            var bq = new EMBlockQuotes(doc, origin, parent);

            bq.Elements.Parse(origin.Start + bqTextGroup.Index, bqText, data);

            return bq;
        }
Exemplo n.º 24
0
        private static EMHeader CreateFromAtxMatch(Match match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var headerText = match.Groups[3].Value;

            if (headerText.Contains("ifndef") || headerText.Contains("endif"))
            {
                return null;
            }

            var level = match.Groups[1].Value.Length;
            var isOptional = string.IsNullOrWhiteSpace(match.Groups[2].Value);

            headerText = Markdown.Unescape(data.Markdown.RunSpanGamut(headerText, data));

            return new EMHeader(doc, origin, parent, level, headerText, isOptional);
        }
Exemplo n.º 25
0
        public static EMElements ExcerptLazyParser(EMDocument doc, EMElement parent, string content, TransformationData data)
        {
            content = Preprocessor.CutoutComments(content, null);

            var elements = new EMElements(doc, new EMElementOrigin(0, content), parent);

            var previousCurrentFolder = data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf;
            var newCurrentFolder = doc.GetAbsoluteMarkdownPath();

            data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf = newCurrentFolder;

            elements.Parse(content, data);

            data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf = previousCurrentFolder;

            return elements;
        }
Exemplo n.º 26
0
        public void Add(string name, string content, TransformationData data, string variableFileFolderName = null)
        {
            if (!string.IsNullOrWhiteSpace(variableFileFolderName))
            {
                content = Markdown.ProcessRelativePaths(content, variableFileFolderName);
            }

            if (variableMap.ContainsKey(name))
            {
                data.ErrorList.Add(
                    new ErrorDetail(Language.Message("VariableRedefinition", name),
                        MessageClass.Info, "", "", 0, 0)
                );
            }
            else
            {
                variableMap.Add(name, content);
            }
        }
Exemplo n.º 27
0
        public static EMPathProvider CreatePath(string userPath, EMDocument currentDocument, TransformationData data)
        {
            if (EMEMailPath.Verify(userPath))
            {
                return new EMEMailPath(userPath);
            }

            if (EMExternalPath.Verify(userPath))
            {
                return new EMExternalPath(userPath);
            }

            if (EMLocalFilePath.Verify(userPath))
            {
                return new EMLocalFilePath(userPath, currentDocument, data);
            }

            return new EMLocalDocumentPath(userPath, currentDocument, data);
        }
Exemplo n.º 28
0
        private static EMElement CreateBracketed(
            IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var taggedMatch = match as EMBracketedImagesAndLinksMatch;

            // Check if image.
            if (taggedMatch.Text.StartsWith("!") && !string.IsNullOrWhiteSpace(taggedMatch.Parameters))
            {
                EMElement outElement = null;

                var fragments = new List<TextFragment>() { new TextFragment(origin.Start, match.Text) };

                EMParsingHelper.ParseElements(
                    data, doc, parent, fragments, EMImage.GetParser(), element => { outElement = element; });

                if (outElement == null)
                {
                    string imageError = "Could not find image in given text: " + origin.Text;
                    throw new InvalidOperationException(imageError);
                }

                return outElement;
            }

            // Check if shortcut ref
            if (string.IsNullOrWhiteSpace(taggedMatch.Parameters))
            {
                return EMLink.CreateFromAnchorRefShortcut(
                    EMLink.AnchorRefShortcut.Match(taggedMatch.Text), doc, origin, parent, data);
            }

            // If not an image and not a shortcut link, then must have been other link.

            // Parse span content for internal elements.
            var span = new EMSpanElements(doc, origin, parent);
            span.Parse(taggedMatch.ContentStart, taggedMatch.Content, data);

            // Check if ref link
            return taggedMatch.Parameters.StartsWith("[")
                       ? EMLink.CreateFromAnchorRef(doc, origin, parent, data, span, taggedMatch.Parameters)
                       : EMLink.CreateFromInline(doc, origin, parent, data, span, taggedMatch.Parameters);
        }
        public override EMElement Create(IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            if (match is EMRawHTMLMatch)
            {
                var htmlMatch = match as EMRawHTMLMatch;
                if (htmlMatch.Name.ToLower() == "code")
                {
                    return new EMCodeBlock(doc, origin, parent, htmlMatch.Content, true);
                }

                var element = new EMRawHTML(doc, origin, parent, htmlMatch.Name, htmlMatch.AttributesString);

                element.Elements.Parse(Markdown.Outdent(htmlMatch.Content, element.Elements.TextMap), data);

                return element;
            }

            if (match is EMMarkdownTaggedElementMatch)
            {
                var markdownMatch = match as EMMarkdownTaggedElementMatch;

                switch (markdownMatch.Name.ToLower())
                {
                    case "region":
                        return EMRegion.CreateRegion(origin, doc, parent, data, markdownMatch, markdownMatch.Parameters);
                    case "include":
                        return EMInclude.CreateFromText(markdownMatch.Text, doc, origin, parent, data);
                    case "include_files":
                        return EMInclude.CreateIncludeFilesFromText(markdownMatch.Text, doc, origin, parent, data);
                    case "relative":
                        return EMRelativeLink.CreateFromText(markdownMatch.Parameters, doc, origin, parent, data);
                    case "relative_img":
                        return EMRelativeLink.CreateFromText(markdownMatch.Parameters, doc, origin, parent, data, true);
                    case "object":
                        return EMObject.CreateFromText(markdownMatch.Parameters, markdownMatch, doc, origin, parent, data);
                    default:
                        return EMErrorElement.Create(doc, origin, parent, data, "UnsupportedTaggedMarkdownElement");
                }
            }

            return EMErrorElement.Create(doc, origin, parent, data, "UnknownMatchTypeForTaggedElementsParser");
        }
Exemplo n.º 30
0
        public static EMObjectParam CreateParam(EMElementOrigin origin, EMDocument doc, EMElement parent, TransformationData data, EMMarkdownTaggedElementMatch match, string paramName, string paramIndentation)
        {
            var content = new EMObjectParam(doc, origin, parent, match, paramName);

            var text =
                Preprocessor.Replace(
                    new Regex(
                        "^" + Regex.Escape(paramIndentation), RegexOptions.Multiline),
                    content.Elements.Origin.Text,
                    "",
                    content.Elements.TextMap);

            text = Preprocessor.Trim(text, '\n', content.Elements.TextMap);

            text = Markdown.OutdentIfPossible(text, content.Elements.TextMap);

            content.Elements.Parse(0, text, data);

            return content;
        }
Exemplo n.º 31
0
    /**
     * Adds an entry to the queue with predefined transformation time. This is a re-entry method, so we don't want to check for
     * duplicate data this time around in the queue.
     */

    public bool Add(ulong time, TransformationData tData, bool inProgress = false)
    {
        this.CreateQueueIfUndefined();
        this.queue.Add(new TransformationJob(time, tData, inProgress));
        return(true);
    }
Exemplo n.º 32
0
 public abstract void Parse(List <TextFragment> fragments, TransformationData data);
Exemplo n.º 33
0
        public EMLocalDocumentPath(string userPath, EMDocument currentDocument, TransformationData data)
        {
            userPath = Preprocessor.Preprocessor.UnescapeChars(userPath, true);

            if (userPath.StartsWith("%ROOT%"))
            {
                userPath = userPath.Replace("%ROOT%", ".");
            }

            this.currentDocument = currentDocument;
            var match = DocumentPathPattern.Match(userPath);

            if (!match.Success)
            {
                throw new EMPathVerificationException(Language.Message("InvalidLocalDocumentPath", userPath));
            }

            DocumentPath = match.Groups["path"].Value;

            changedLanguage = false;

            if (string.IsNullOrWhiteSpace(DocumentPath))
            {
                DocumentPath = currentDocument.LocalPath;
            }
            else
            {
                DirectoryInfo docDir;
                try
                {
                    docDir = new DirectoryInfo(Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, DocumentPath));
                }
                catch (Exception e)
                {
                    if (e is NotSupportedException || e is ArgumentException)
                    {
                        throw new EMPathVerificationException(Language.Message("InvalidLocalDocumentPath", userPath));
                    }

                    throw;
                }

                if (!docDir.Exists)
                {
                    throw new EMPathVerificationException(Language.Message("BadLinkOrMissingMarkdownFileForLink", DocumentPath));
                }

                var docFiles = docDir.GetFiles(string.Format("*.{0}.udn", data.CurrentFolderDetails.Language));

                if (docFiles.Length == 0)
                {
                    if (data.CurrentFolderDetails.Language != "INT")
                    {
                        docFiles        = docDir.GetFiles("*.INT.udn");
                        changedLanguage = docFiles.Length != 0;
                    }

                    if (data.CurrentFolderDetails.Language == "INT" || !ChangedLanguage)
                    {
                        throw new EMPathVerificationException(Language.Message("BadLinkOrMissingMarkdownFileForLink", DocumentPath));
                    }
                }

                DocumentPath = docFiles[0].FullName;
            }

            BookmarkName = match.Groups["bookmark"].Value;

            if (string.IsNullOrWhiteSpace(BookmarkName))
            {
                BookmarkName = null;
            }
        }
Exemplo n.º 34
0
 public ProcessedDocumentCache(string path, TransformationData data)
 {
     TransformationData  = data;
     currentFileDocument = new EMDocument(path, data);
 }
Exemplo n.º 35
0
        public void FlattenInternalLinks(TransformationData data)
        {
            if (Data == null)
            {
                return;
            }

            var bookmarks = new Dictionary <string, EMBookmark>();

            Data.GetElements <EMBookmark>().ForEach((bookmark) =>
            {
                if (bookmarks.ContainsKey(bookmark.UniqueKey))
                {
                    var errorId = data.ErrorList.Count;
                    data.ErrorList.Add(
                        Markdown.GenerateError(
                            Language.Message("ConflictingBookmarkNameOrHeaderId", bookmark.UniqueKey),
                            MessageClass.Info,
                            bookmark.Origin.Text,
                            errorId,
                            data));
                    return;
                }

                bookmarks.Add(bookmark.UniqueKey, bookmark);
            });

            var inclusions = new Dictionary <string, EMInclude>();

            Data.GetElements <EMInclude>().ForEach(e =>
            {
                if (!e.Excerpt.IsDocumentExcerpt)
                {
                    return;
                }

                e.AddHashedPathBookmarkToOutput();
                var inclusionPath = e.Excerpt.Document.LocalPath.ToLower();

                if (!inclusions.ContainsKey(inclusionPath))
                {
                    inclusions.Add(inclusionPath, e);
                }
            });

            foreach (
                var link in
                Data.GetElements(
                    e =>
                    (e is EMLink) && (e as EMLink).Path is EMLocalDocumentPath).Cast <EMLink>())
            {
                var path = link.Path as EMLocalDocumentPath;
                var id   = path.BookmarkName;

                if ((path.IsBookmark && (path.DocumentPath != path.currentDocument.LocalPath || !bookmarks.ContainsKey(id))) ||
                    (!path.IsBookmark && !inclusions.ContainsKey(path.DocumentPath.ToLower())))
                {
                    if (data.NonDynamicHTMLOutput)
                    {
                        link.ConvertToJustTextOutput();
                    }
                }
                else
                {
                    link.ConvertToInternal();
                }
            }
        }
Exemplo n.º 36
0
        public static EMElements ExcerptLazyParser(EMDocument doc, EMElement parent, string content, TransformationData data)
        {
            content = Preprocessor.CutoutComments(content, null);

            var elements = new EMElements(doc, new EMElementOrigin(0, content), parent);

            var previousCurrentFolder = data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf;
            var newCurrentFolder      = doc.GetAbsoluteMarkdownPath();

            data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf = newCurrentFolder;

            elements.Parse(content, data);

            data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf = previousCurrentFolder;

            return(elements);
        }
Exemplo n.º 37
0
 public override void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
 {
     builder.Append(Content);
 }
Exemplo n.º 38
0
 public override void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
 {
     foreach (var element in elements)
     {
         element.Value.AppendHTML(builder, includesStack, data);
     }
 }
Exemplo n.º 39
0
        public static EMPathProvider CreatePath(string userPath, EMDocument currentDocument, TransformationData data)
        {
            if (EMEMailPath.Verify(userPath))
            {
                return(new EMEMailPath(userPath));
            }

            if (EMExternalPath.Verify(userPath))
            {
                return(new EMExternalPath(userPath));
            }

            if (EMLocalFilePath.Verify(userPath))
            {
                return(new EMLocalFilePath(userPath, currentDocument, data));
            }

            return(new EMLocalDocumentPath(userPath, currentDocument, data));
        }
Exemplo n.º 40
0
            public void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
            {
                var cells = new StringBuilder();

                foreach (var cell in Cells)
                {
                    cell.AppendHTML(cells, includesStack, data);
                }

                builder.Append(Templates.TableRow.Render(
                                   Hash.FromAnonymousObject(new { hasError = HasError, errorId = ErrorId, cells = cells.ToString() })));
            }
Exemplo n.º 41
0
        public override void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
        {
            var headers = new StringBuilder();

            if (tableHeaderRows != null)
            {
                foreach (var headerRow in tableHeaderRows)
                {
                    headerRow.AppendHTML(headers, includesStack, data);
                }
            }

            var rows = new StringBuilder();

            foreach (var row in tableRows)
            {
                row.AppendHTML(rows, includesStack, data);
            }

            builder.Append(Templates.Table.Render(Hash.FromAnonymousObject(
                                                      new
            {
                caption          = optionalCaption,
                columnAlignments = tableColumnAlignments,
                headers          = tableHeaderRows != null ? headers.ToString() : null,
                rows             = rows.ToString()
            })));
        }
Exemplo n.º 42
0
 public void Parse(string text, TransformationData data)
 {
     Parse(0, text, data);
 }
Exemplo n.º 43
0
        public override void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
        {
            if (includesStack.Count > 0 && !includesStack.First().IncludeTOC)
            {
                return;
            }

            var isLocalTOC = linkedDocument == Document.TransformationData.Document;

            builder.Append(RenderTOC(
                               startLevel,
                               endLevel,
                               string.IsNullOrWhiteSpace(path)
                    ? ""
                    : Path.Combine(
                                   data.CurrentFolderDetails.RelativeHTMLPath,
                                   data.CurrentFolderDetails.Language,
                                   path,
                                   "index.html"),
                               !isLocalTOC));
        }
Exemplo n.º 44
0
 public EMElement Create(IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
 {
     return(elementCreator((TMatch)match, doc, origin, parent, data));
 }
Exemplo n.º 45
0
        private static List <TableRowInformation> GetHeaders(EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data, int headerOffset, string tableHeader, out bool useRowHeader)
        {
            // Add headers
            // May be multiple lines, may have columns spanning
            // May also have no header if we are intending the 1st column to be the header

            var map = new PreprocessedTextLocationMap();

            tableHeader = RemoveTrailingWhitespaceAndNewLines(tableHeader, map);

            List <TableRowInformation> templateHeaderRows = null;

            useRowHeader = true;

            if (!String.IsNullOrWhiteSpace(tableHeader))
            {
                templateHeaderRows = new List <TableRowInformation>();

                var headerRowOffset = 0;

                var headerRows = Regex.Split(tableHeader, @"\n");
                foreach (var headerRow in headerRows)
                {
                    var count = 0;

                    var headerColumns = Regex.Matches(headerRow, @"[ ]?([^\|]+)[ ]?([\|]*)");
                    var row           = new TableRowInformation();

                    foreach (Match headerColumn in headerColumns)
                    {
                        var cellGroup        = headerColumn.Groups[1];
                        var columnSpanLength = 1;

                        if (Regex.Match(headerColumn.Groups[2].Value, @"(\|{2,})").Success)
                        {
                            columnSpanLength = Regex.Match(headerColumn.Groups[2].Value, @"(\|{2,})").Length;
                        }

                        var cell = new TableCellInformation(doc, new EMElementOrigin(headerOffset + map.GetOriginalPosition(headerRowOffset + cellGroup.Index, PositionRounding.Down), cellGroup.Value), parent, data, columnSpanLength, null, true);

                        if (count == 0)
                        {
                            useRowHeader = !Regex.Match(cell.ToString(), @"(\S)").Success;
                        }

                        count++;

                        row.Cells.Add(cell);
                    }

                    headerRowOffset += headerRow.Length + 1;
                    templateHeaderRows.Add(row);
                }
            }

            return(templateHeaderRows);
        }
Exemplo n.º 46
0
        private static string ParseExcerpt(Match match, Dictionary <string, ExcerptInfo> excerptsInfos, TransformationData data, List <PreprocessingTextChange> changes)
        {
            var name         = match.Groups["name"].Value.ToLower();
            var contentGroup = match.Groups["content"];
            var content      = contentGroup.Value;

            content = ExcerptBlock.Replace(content, m => ParseExcerpt(m, excerptsInfos, data, null));
            content = ExcerptInline.Replace(content, m => ParseExcerpt(m, excerptsInfos, data, null));

            if (excerptsInfos.ContainsKey(name))
            {
                excerptsInfos[name].Content.Append("\n" + content);
            }
            else
            {
                excerptsInfos.Add(name, new ExcerptInfo(match.Index, contentGroup.Index - match.Index, content));
            }

            if (changes != null)
            {
                changes.Add(PreprocessingTextChange.CreateRemove(match.Groups["prefix"]));
                changes.Add(PreprocessingTextChange.CreateRemove(match.Groups["postfix"]));
            }

            return(content);
        }
Exemplo n.º 47
0
 public override void AppendHTML(System.Text.StringBuilder builder, System.Collections.Generic.Stack <EMInclude> includesStack, TransformationData data)
 {
     // write nothing
 }
Exemplo n.º 48
0
 protected void ParseElements(TransformationData data, List <TextFragment> fragments, IParser parser)
 {
     EMParsingHelper.ParseElements(data, Document, this, fragments, parser, Add);
 }
Exemplo n.º 49
0
        public EMTable(EMDocument doc, EMElementOrigin origin, EMElement parent, Match match, TransformationData data)
            : base(doc, origin, parent)
        {
            var tableAlignment = RemoveTrailingWhitespaceAndNewLines(match.Groups[3].Value, null);

            bool useRowHeader;

            optionalCaption       = data.Markdown.RunSpanGamut(GetOptionalCaption(match.Groups[0].Value), data);
            tableHeaderRows       = GetHeaders(doc, origin, this, data, match.Groups[2].Index - match.Index, match.Groups[2].Value, out useRowHeader);
            tableColumnAlignments = new List <Hash>();
            tableRows             = GetRows(this, data, match.Groups[5].Index - match.Index, match.Groups[5].Value, GetAlignments(tableAlignment, tableColumnAlignments), useRowHeader, !String.IsNullOrWhiteSpace(match.Groups[2].Value));
        }
Exemplo n.º 50
0
 private static EMElement CreateTable(Match match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
 {
     return(new EMTable(doc, origin, parent, match, data));
 }
Exemplo n.º 51
0
 public EMExcerpt(EMDocument doc, int originPosition, int contentStart, string content, TransformationData data, bool isDocumentExcerpt)
     : base(doc, new EMElementOrigin(originPosition + contentStart, content), null)
 {
     this.IsDocumentExcerpt = isDocumentExcerpt;
     lazyLoadingFunction    = () => ExcerptLazyParser(doc, this, content, data);
 }
Exemplo n.º 52
0
 protected void ParseElements(TransformationData data, List <TextFragment> fragments, IEnumerable <IParser> parsers)
 {
     ParseElements(data, Document, fragments, parsers);
 }
Exemplo n.º 53
0
 public void Parse(string content, TransformationData data)
 {
     Content = Markdown.Unescape(data.Markdown.RunSpanGamut(content, data));
 }
Exemplo n.º 54
0
    /**
     * Gets the transformation time from world time
     */

    private static ulong CalculateTransformationTimeAsWorldTime(TransformationData tData)
    {
        ulong worldTime = GameManager.Instance.World.worldTime;

        return(worldTime + (ulong)tData.transformationTime);
    }
Exemplo n.º 55
0
        private static List <TableRowInformation> GetRows(
            EMElement parent,
            TransformationData data,
            int tableDataOffset,
            string tableData,
            string[] alignments,
            bool useRowHeader,
            bool hasHeader)
        {
            // Add body data
            var tableRows = new List <TableRowInformation>();

            var map = new PreprocessedTextLocationMap();

            tableData = RemoveTrailingWhitespaceAndNewLines(tableData, map);

            var dataRows = Regex.Split(tableData, @"\n");

            var rowOffset = 0;

            for (var i = 0; i < dataRows.Count(); ++i)
            {
                var dataRow = dataRows[i];

                // Parse table into List of List of CellInformation
                var count = 0;

                var dataColumns = Regex.Matches(dataRow, @"([^\|]+)([\|]*)");

                var tableRow = new TableRowInformation();

                // Check to see if someone has left an empty row incorrectly formatted, which we can fix.
                if (dataColumns.Count == 0)
                {
                    var fixedDataRow = dataRow;
                    for (var j = dataRow.Length; j < alignments.Length + 1; ++j)
                    {
                        fixedDataRow += '|';
                    }
                    fixedDataRow = fixedDataRow.Insert(1, " ");

                    dataColumns = Regex.Matches(fixedDataRow, @"([^\|]+)([\|]*)");
                }

                foreach (Match dataColumn in dataColumns)
                {
                    int addToOffset;
                    var cell = Normalizer.LeadingWhitespaceRemove(dataColumn.Groups[1].Value, out addToOffset);
                    cell = Normalizer.TrailingWhitespaceRemove(cell);

                    var columnSpanLength = 1;
                    var isRowHeader      = (count == 0 && useRowHeader && dataColumns.Count > 1) ||
                                           (dataColumns.Count == 1 && i == 0 && !hasHeader);

                    if (Regex.Match(dataColumn.Groups[2].Value, @"(\|{2,})").Success)
                    {
                        columnSpanLength = Regex.Match(dataColumn.Groups[2].Value, @"(\|{2,})").Length;
                    }

                    // @UE3 ensure that the index into alignments is not greater than the amount expected. (Users may accidentally add extra || to lines)
                    string alignment = null;
                    if (count >= alignments.Length)
                    {
                        // Report only 1 error per row per run to avoid duplicates
                        if (!tableRow.HasError)
                        {
                            var errorCount = data.ErrorList.Count;
                            tableRow.ErrorId  = errorCount;
                            tableRow.HasError = true;
                            data.ErrorList.Add(
                                Markdown.GenerateError(
                                    Language.Message(
                                        "MoreColumnsThanAllignmentsInOneOfTheTableRowsColumnsIgnored",
                                        Markdown.Unescape(dataRows[i])),
                                    MessageClass.Error,
                                    Markdown.Unescape(dataRows[i]),
                                    errorCount,
                                    data));
                        }
                    }
                    else
                    {
                        alignment = alignments[count];
                    }

                    var cellInformation = (cell.Trim() != "^")
                                              ? new TableCellInformation(
                        parent.Document,
                        new EMElementOrigin(tableDataOffset + map.GetOriginalPosition(addToOffset + rowOffset + dataColumn.Groups[1].Index, PositionRounding.Down), cell),
                        parent, data, columnSpanLength, alignment, isRowHeader)
                                              : new TableCellInformation(columnSpanLength, alignment, isRowHeader, false, 1, true);

                    tableRow.Cells.Add(cellInformation);

                    // Make parsing table easier later, if ColumnSpan > 1 create a blank column for each over one
                    for (var dummyColumnCount = 1; dummyColumnCount < columnSpanLength; ++dummyColumnCount)
                    {
                        tableRow.Cells.Add(new TableCellInformation(0));
                    }

                    // @UE3 this was not in original specification, handles correct alignment of a subsequent column after a long column.
                    count += columnSpanLength;
                }
                // If count is zero check that someone has just not placed a space in the first column indicating it should be empty.

                if (count < alignments.Length)
                {
                    var errorCount = data.ErrorList.Count;
                    tableRow.ErrorId  = errorCount;
                    tableRow.HasError = true;
                    data.ErrorList.Add(
                        Markdown.GenerateError(
                            Language.Message(
                                "LessColumnsThanExpectedInOneOfTheTableRowsEmptyCellsInserted", Markdown.Unescape(dataRows[i])),
                            MessageClass.Error,
                            Markdown.Unescape(dataRows[i]),
                            errorCount,
                            data));
                }

                // If count is less than total expected for a rows data add dummy column and raise error
                for (var dummyColumnCount = count; dummyColumnCount < alignments.Length; ++dummyColumnCount)
                {
                    tableRow.Cells.Add(new TableCellInformation(1, null, false, true));
                }

                tableRows.Add(tableRow);

                rowOffset += dataRow.Length + 1;
            }

            // Now work out rowspans based on Content and character ^
            // Work down rows in columns

            for (var columnNumber = 0; columnNumber < alignments.Length; ++columnNumber)
            {
                var firstNonSpanRow = -1;
                for (var rowNumber = 0; rowNumber < tableRows.Count; ++rowNumber)
                {
                    if (tableRows[rowNumber].Cells[columnNumber].IsRowSpanColumn) //Found a rowspan column
                    {
                        if (rowNumber == 0)
                        {
                            var errorCount = data.ErrorList.Count;
                            tableRows[rowNumber].ErrorId  = errorCount;
                            tableRows[rowNumber].HasError = true;
                            data.ErrorList.Add(
                                Markdown.GenerateError(
                                    Language.Message(
                                        "ColumnCannotBeSetToSpanWithSpecialSymbolInTheFirstRowOfATable", dataRows[0]),
                                    MessageClass.Error,
                                    dataRows[0],
                                    errorCount,
                                    data));
                        }
                        else
                        {
                            if (firstNonSpanRow < 0)
                            {
                                //is this the first detected row for this span?
                                firstNonSpanRow = rowNumber - 1;

                                //Row span above this 1 now should include itself
                                tableRows[firstNonSpanRow].Cells[columnNumber].RowSpanCount = 1;
                            }

                            //Increment the Row above first_row detected by 1
                            tableRows[firstNonSpanRow].Cells[columnNumber].RowSpanCount += 1;
                        }
                    }
                    else if (firstNonSpanRow >= 0)
                    {
                        //This row is not a rowspan but we had one previously so clear for any other rowspans in the column
                        firstNonSpanRow = -1;
                    }
                }
            }

            return(tableRows);
        }
Exemplo n.º 56
0
        public static EMObjectParam CreateParam(EMElementOrigin origin, EMDocument doc, EMElement parent, TransformationData data, EMMarkdownTaggedElementMatch match, string paramName, string paramIndentation)
        {
            var content = new EMObjectParam(doc, origin, parent, match, paramName);

            var text =
                Preprocessor.Replace(
                    new Regex(
                        "^" + Regex.Escape(paramIndentation), RegexOptions.Multiline),
                    content.Elements.Origin.Text,
                    "",
                    content.Elements.TextMap);

            text = Preprocessor.Trim(text, '\n', content.Elements.TextMap);

            text = Markdown.OutdentIfPossible(text, content.Elements.TextMap);

            content.Elements.Parse(0, text, data);

            return(content);
        }
Exemplo n.º 57
0
        public static string GetSymbolDescriptionAndCatchExceptionIntoMarkdownErrors(string path, string originalUserEntry, DescriptionType descriptionType,
                                                                                     TransformationData transformationDataForThisRun, Markdown parser, HashSet <string> foundSymbolPaths = null)
        {
            var outputText = "";
            var isError    = false;
            var isInfo     = false;
            var errorId    = 0;

            try
            {
                var match = SymbolPathPattern.Match(path);

                if (!match.Success)
                {
                    throw new InvalidDoxygenPath(path);
                }

                var symbolPath   = match.Groups["symbolPath"].Value;
                var overloadSpec = match.Groups["overloadSpecification"].Value;

                var symbol = DoxygenDbCache.GetSymbolFromPath(symbolPath);

                if (foundSymbolPaths != null)
                {
                    foundSymbolPaths.Add(symbolPath);
                }

                if (symbol.IsOverloadedMember)
                {
                    if (string.IsNullOrWhiteSpace(overloadSpec))
                    {
                        throw new DoxygenAmbiguousSymbolException(path, symbol.GetOverloadSpecificationOptions());
                    }

                    outputText = symbol.GetSymbolDescription(descriptionType, overloadSpec);
                }
                else
                {
                    outputText = symbol.GetSymbolDescription(descriptionType);
                }
            }
            catch (Exception e)
            {
                errorId = transformationDataForThisRun.ErrorList.Count;
                transformationDataForThisRun.ErrorList.Add(
                    Markdown.GenerateError(
                        Language.Message("DoxygenQueryError", e.Message),
                        MessageClass.Error, originalUserEntry, errorId, transformationDataForThisRun));

                isError = true;

                // rethrowing if not known exception
                if (!(e is InvalidDoxygenPath) && !(e is SymbolNotFoundInDoxygenXmlFile) && !(e is DoxygenAmbiguousSymbolException))
                {
                    throw;
                }
            }

            if (parser.ThisIsPreview && (isInfo || isError))
            {
                return(Templates.ErrorHighlight.Render(Hash.FromAnonymousObject(
                                                           new
                {
                    errorId = errorId,
                    errorText = outputText
                })));
            }

            return(outputText);
        }
Exemplo n.º 58
0
 public abstract string GetPath(TransformationData data);
Exemplo n.º 59
0
 public override void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
 {
     builder.Append(Elements.GetInnerHTML(includesStack, data));
 }
Exemplo n.º 60
0
 public void AppendHTML(StringBuilder builder, Stack <EMInclude> includesStack, TransformationData data)
 {
     builder.Append(
         Templates.TableCell.Render(
             Hash.FromAnonymousObject(
                 new
     {
         hasContent   = (Content != null),
         isRowHeader  = IsRowHeader,
         rowSpanCount = RowSpanCount,
         colSpanCount = ColSpanCount,
         alignment    = Alignment,
         content      = (Content != null) ? Content.GetInnerHTML(includesStack, data) : null
     })));
 }