Beispiel #1
0
        private int g_count = 0;   //global counter for tag numbering


        /// <summary>
        /// Replace markdown with <C0> style tags
        /// Assumes a single utterance. Do not pass in multi-paragraph strings.
        /// Writes to the global MDTags dictionary
        /// </summary>
        /// <param name="input">Markdown string</param>
        /// <returns>Same string with markdown replaced by <C0> style tags</returns>
        private string Markdown2Tagged(string input)
        {
            g_count = 0;
            MDTags.Clear();
            bool            inside          = false;
            string          output          = string.Empty;
            int             startofcopy     = 0;
            MatchCollection matchCollection = Regex.Matches(input, @"(#+)|(\*+)|(~~+)|(_+)|(')");

            foreach (Match match in matchCollection)
            {
                if (!inside)
                {
                    g_count++;
                }
                string key = inside ? "/a" : "a";
                if (match.Value[0] == '\'')
                {
                    key = inside ? "/c" : "c";
                }
                key   += g_count;
                inside = ((match.Value[0] == '*') || match.Value[0] == '~' || match.Value[0] == '_' || match.Value[0] == '\'') && !inside ? true : false;
                MDTag mdtag = new MDTag
                {
                    value = match.Value
                };
                MDTags.Add(key, mdtag);
                output     += input.Substring(startofcopy, match.Index - startofcopy) + "<" + key + ">";
                startofcopy = match.Index + match.Length;
            }
            output += input.Substring(startofcopy);
            return(output);
        }
Beispiel #2
0
 public void SetUp()
 {
     mdParser = new MdProcessor(new List <ITag>
     {
         MDTag.GetOneUnderscoreTag(),
         MDTag.GetTwoUnderscoreTag()
     },
                                new MDToHTMLWrapper(MDToHTMLWrapper.GetDefaultMap())
                                );
 }
Beispiel #3
0
        public static Dictionary <string, string> GetDefaultMap()
        {
            var dict = new Dictionary <string, string>
            {
                { MDTag.GetOneUnderscoreTag().StringTag, new HTMLTag("<em>", TagTypeEnum.StrongHtml).StringTag },
                { MDTag.GetTwoUnderscoreTag().StringTag, new HTMLTag("<strong>", TagTypeEnum.EmHtml).StringTag }
            };

            return(dict);
        }