Esempio n. 1
0
        public PreprocessedTextLocationMap(PreprocessedTextLocationMap other)
        {
            var subsets = other.textSubsets;

            textSubsets = new PreprocessedTextSubset[subsets.Length];
            subsets.CopyTo(textSubsets, 0);
        }
Esempio n. 2
0
        public static void AddChangesToBounds(
            PreprocessedTextLocationMap map,
            List <PreprocessingTextChange> changes,
            PreprocessedData data,
            PreprocessedTextType type)
        {
            if (data == null)
            {
                return;
            }

            foreach (var change in changes)
            {
                if (change.RemoveCharsCount == 0)
                {
                    continue;
                }

                var start = change.Index;
                var end   = change.Index + change.RemoveCharsCount - 1;

                if (map != null)
                {
                    start = map.GetOriginalPosition(start, PositionRounding.Up);
                    end   = map.GetOriginalPosition(end, PositionRounding.Down);
                }

                data.PreprocessedTextBounds.Add(
                    new PreprocessedTextBound(
                        type, start, end));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Turn Markdown `code spans` into HTML code tags
        /// </summary>
        private static string DoCodeSpans(string text, PreprocessedTextLocationMap locationMap)
        {
            //    * You can use multiple backticks as the delimiters if you want to
            //        include literal backticks in the code span. So, this input:
            //
            //        Just type ``foo `bar` baz`` at the prompt.
            //
            //        Will translate to:
            //
            //          <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
            //
            //        There's no arbitrary limit to the number of backticks you
            //        can use as delimters. If you need three consecutive backticks
            //        in your code, use four for delimiters, etc.
            //
            //    * You can use spaces to get literal backticks at the edges:
            //
            //          ... type `` `bar` `` ...
            //
            //        Turns to:
            //
            //          ... type <code>`bar`</code> ...
            //

            return(Replace(_codeSpan, text, CodeSpanEvaluator, locationMap));
        }
Esempio n. 4
0
        public static string Normalize(string text, PreprocessedTextLocationMap map)
        {
            text = Preprocessor.Replace(NewLinePattern, text, NewLineEvaluator, map);
            text = Preprocessor.Replace(TabPattern, text, m => TabReplacement(m, text), map);

            return(text);
        }
        public static string CutoutVariableInclusions(string text, PreprocessedTextLocationMap map)
        {
            text = Preprocessor.EscapeChars(text, map);

            text = Preprocessor.Replace(InLineVariableOrMetadata, text, "", map);

            return(Preprocessor.UnescapeChars(text, false, map));
        }
Esempio n. 6
0
        public static string EscapeChars(string text, PreprocessedTextLocationMap map)
        {
            foreach (var c in BackslashEscapedChars)
            {
                text = Replace(new Regex(Regex.Escape(@"\" + c)), text, string.Format("\x19{0}\x19", c.GetHashCode()), map);
            }

            return(text);
        }
Esempio n. 7
0
        public static string UnescapeChars(string text, bool leaveBackslash = false, PreprocessedTextLocationMap map = null)
        {
            foreach (var c in BackslashEscapedChars)
            {
                text = Replace(
                    new Regex(Regex.Escape(string.Format("\x19{0}\x19", c.GetHashCode()))),
                    text,
                    (leaveBackslash ? "\\" : "") + c.ToString(CultureInfo.InvariantCulture),
                    map);
            }

            return(text);
        }
Esempio n. 8
0
        public PreprocessedData(EMDocument document, ProcessedDocumentCache manager)
        {
            Excerpts               = new ExcerptsManager(this);
            Variables              = new VariableManager(this);
            Metadata               = new MetadataManager(this);
            ReferenceLinks         = new ReferenceLinksManager(this);
            TextMap                = new PreprocessedTextLocationMap();
            PreprocessedTextBounds = new List <PreprocessedTextBound>();

            Document = document;

            this.manager = manager;
        }
        public string ParseExcerpts(string text, TransformationData data, PreprocessedTextLocationMap map)
        {
            var excerptInfos = new Dictionary <string, ExcerptInfo>();

            text = ProcessExcerpt(ExcerptBlock, text, data, excerptInfos, map);
            text = ProcessExcerpt(ExcerptInline, text, data, excerptInfos, map);

            foreach (var excerptInfo in excerptInfos)
            {
                AddExcerpt(data, excerptInfo.Value, excerptInfo.Key);
            }

            AddExcerpt(data, new ExcerptInfo(map.GetOriginalPosition(0, PositionRounding.Down), 0, text), "");

            return(text);
        }
 public string ParseVariablesDefinition(string text, string relPath, TransformationData data, PreprocessedTextLocationMap map)
 {
     return(Preprocessor.Replace(VariableDefinitionPattern, text, everyMatch => ParseVariableDefinition(everyMatch, relPath, data), map));
 }
        public string ReplaceVariables(EMDocument doc, string text, TransformationData data, PreprocessedTextLocationMap map = null)
        {
            text = EMTOCInline.ConvertVariableLikeTOCInlines(text, map);

            var stack       = new Stack <Tuple <string, string> >();
            var currentFile = new FileInfo(doc.LocalPath);

            return(map == null
                       ? InLineVariableOrMetadata.Replace(
                       text,
                       everyMatch =>
                       ParseInLineVariableOrMetadata(everyMatch, currentFile, currentFile, data, doc, stack))
                       : Preprocessor.Replace(
                       InLineVariableOrMetadata,
                       text,
                       everyMatch =>
                       ParseInLineVariableOrMetadata(everyMatch, currentFile, currentFile, data, doc, stack),
                       map));
        }
        private static string ProcessExcerpt(Regex pattern, string text, TransformationData data, Dictionary <string, ExcerptInfo> excerptsInfos, PreprocessedTextLocationMap map)
        {
            var changes = new List <PreprocessingTextChange>();

            text = pattern.Replace(text, match => ParseExcerpt(match, excerptsInfos, data, changes));

            map.ApplyChanges(changes);

            return(text);
        }
Esempio n. 13
0
 private static string TrimRight(string text, char c, PreprocessedTextLocationMap textMap)
 {
     return(Replace(new Regex(Regex.Escape(c.ToString()) + @"+\z"), text, "", textMap));
 }
Esempio n. 14
0
 public static string Trim(string text, char c, PreprocessedTextLocationMap textMap)
 {
     text = TrimLeft(text, c, textMap);
     return(TrimRight(text, c, textMap));
 }
Esempio n. 15
0
 public static string Replace(Regex pattern, string text, string replacement, PreprocessedTextLocationMap locationMap)
 {
     return(Replace(pattern, text, m => replacement, locationMap));
 }
Esempio n. 16
0
        public static string Replace(Regex pattern, string text, MatchEvaluator evaluator, PreprocessedTextLocationMap locationMap, List <PreprocessingTextChange> changesDone = null)
        {
            if (locationMap == null && changesDone == null)
            {
                return(pattern.Replace(text, evaluator));
            }

            var changes = changesDone ?? new List <PreprocessingTextChange>();

            var output = pattern.Replace(text, m => PreprocessingTextChange.MatchEvaluatorWithTextChangeEmitWrapper(m, evaluator, changes));

            if (locationMap != null)
            {
                locationMap.ApplyChanges(changes);
            }

            return(output);
        }