Example #1
0
        private static IEnumerable <WikiCodeBlockInfo> FindBlocks(string source)
        {
            int curPos   = 0;
            var infoList = new List <WikiCodeBlockInfo>();

            var match = Regex.Match(source, string.Format(@"(\[\s*{0}\(\s*\"")([^\""]*)(\""\s*\)\s*\])", BlockAttributeName));

            while (match.Success)
            {
                var info = new WikiCodeBlockInfo(match.Groups[2].Value, ReadBlock(source, match.Index + match.Length));
                infoList.Add(info);
                curPos += match.Length;

                match = match.NextMatch();
            }
            return(infoList);
        }
Example #2
0
        public static string ProcessTemplate(string templatePath, ICollection <WikiCodeBlockInfo> codeBlocks)
        {
            String templateText = File.ReadAllText(templatePath);

            var   pattern = string.Format(@"(<\s*{0}\s*>)([^<]*)(<\/\s*{0}\s*>)", WikiBlockTag);
            Match match   = Regex.Match(templateText, pattern);

            while (match.Success)
            {
                string            blockId   = match.Groups[2].Value;
                WikiCodeBlockInfo blockInfo = codeBlocks.First(cb => blockId.Equals(cb.Id));

                templateText = templateText.Replace(match.Value, blockInfo.Code);
                match        = Regex.Match(templateText, pattern);
            }

            return(templateText);
        }