Beispiel #1
0
        public static EMElement CreateIncludeFilesFromText(string text, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var specs = Preprocessor.UnescapeChars(IncludeFilesPattern.Match(text).Groups["specs"].Value, true);

            var paths = GetIncludesFromPathSpecs(specs, data);

            var inclusions = new EMElements(doc, origin, parent);

            var i = 0;

            foreach (var path in paths)
            {
                var pathOrigin = new EMElementOrigin(i, "");

                try
                {
                    bool languageChanged;

                    var excerpt =
                        ExcerptsManager.Get(data.ProcessedDocumentCache,
                                            Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, path),
                                            data.CurrentFolderDetails.Language,
                                            "",
                                            out languageChanged);

                    inclusions.Add(new EMInclude(doc, pathOrigin, inclusions, excerpt, 0, languageChanged, false));
                }
                catch (ExcerptsManagerException e)
                {
                    inclusions.Add(EMErrorElement.Create(doc, pathOrigin, inclusions, data, e.MessageId, e.MessageArgs));
                }

                ++i;
            }

            return(inclusions);
        }
Beispiel #2
0
        private static EMElement Create(
            Match match,
            EMDocument doc,
            EMElementOrigin origin,
            EMElement parent,
            TransformationData data)
        {
            var includeFileFolderName = "";
            var includeRegion         = "";

            var thisOffset = 0;

            if (match.Groups["includeFileRegion"].Value.Contains('#'))
            {
                includeFileFolderName = match.Groups["includeFileRegion"].Value.Split('#')[0];
                includeRegion         = match.Groups["includeFileRegion"].Value.Split('#')[1];

                if (!includeRegion.StartsWith("doxygen"))
                {
                    includeRegion = includeRegion.ToLower();
                }
            }
            else
            {
                includeFileFolderName = match.Groups["includeFileRegion"].Value;
            }

            if (includeFileFolderName.ToUpper().Contains("%ROOT%"))
            {
                includeFileFolderName = ".";
            }

            if (String.IsNullOrWhiteSpace(includeFileFolderName))
            {
                if (String.IsNullOrWhiteSpace(includeRegion))
                {
                    // Error cannot have no region and no file specified.
                    return(EMErrorElement.Create(
                               data.Document,
                               origin,
                               parent,
                               data,
                               "ExcerptRegionToIncludeWhenNoFileGiven"));
                }

                // Assume that this is a reference to a location in this file.
                includeFileFolderName = doc.GetAbsoluteMarkdownPath();
            }

            if (!String.IsNullOrWhiteSpace(match.Groups["offsetValue"].Value) &&
                !int.TryParse(match.Groups["offsetValue"].Value, out thisOffset))
            {
                return(EMErrorElement.Create(
                           data.Document,
                           origin,
                           parent,
                           data,
                           "ValueMustBeNumber"));
            }

            try
            {
                bool languageChanged;

                var excerpt =
                    ExcerptsManager.Get(data.ProcessedDocumentCache,
                                        Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, includeFileFolderName),
                                        data.CurrentFolderDetails.Language,
                                        includeRegion,
                                        out languageChanged);

                return(new EMInclude(doc, origin, parent, excerpt, thisOffset, languageChanged));
            }
            catch (ExcerptsManagerException e)
            {
                return(EMErrorElement.Create(doc, origin, parent, data, e.MessageId, e.MessageArgs));
            }
        }