Beispiel #1
0
        private string ParseToMarkdownFormat(TextFormatClientTypeEnum formatType)
        {
            var convertRules = new Dictionary <TextFormatClientTypeEnum, string>()
            {
                { TextFormatClientTypeEnum.orderedListItem, "{0}.{1}" },
                { TextFormatClientTypeEnum.unorderedListItem, "*{0}" },
                { TextFormatClientTypeEnum.unstyled, "{0}" } //text or line break
            };

            return(convertRules.ContainsKey(formatType) ? convertRules[formatType] : string.Empty);
        }
Beispiel #2
0
        private VmTextBlock ParseMarkdownToTextBlock(string text)
        {
            VmTextBlock textBlock = new VmTextBlock();
            var         lines     = text?.Split('\n') ?? new string[0] {
            };

            var typePatterns = new Dictionary <TextFormatClientTypeEnum, string>()
            {
                { TextFormatClientTypeEnum.unorderedListItem, @"\*" },  //ordered
                { TextFormatClientTypeEnum.orderedListItem, @"\d+\." }, //unoredered
                { TextFormatClientTypeEnum.unstyled, @"[^\d+\.\*\s]+" } //rest
            };

            foreach (var line in lines)
            {
                int index      = int.MaxValue;
                int textLength = 0;
                var lineText   = line;
                TextFormatClientTypeEnum type = TextFormatClientTypeEnum.unstyled;

                foreach (KeyValuePair <TextFormatClientTypeEnum, string> valueTypePattern in typePatterns)
                {
                    if (Regex.IsMatch(lineText, valueTypePattern.Value)) //find first occurence
                    {
                        var match = Regex.Match(lineText, valueTypePattern.Value);
                        if (match.Index < index)
                        {
                            index      = match.Index;
                            textLength = match.Length;
                            type       = valueTypePattern.Key;
                        }
                    }
                }

                if (type == TextFormatClientTypeEnum.unorderedListItem)
                {
                    lineText = line.Remove(index, 1);
                }

                if (type == TextFormatClientTypeEnum.orderedListItem)
                {
                    lineText = line.Remove(index, textLength);
                }

                textBlock.Blocks.Add(new VmTextLine()
                {
                    Text = lineText, Type = type, Key = GetUniqueKey(5)
                });
            }

            return(textBlock);
        }
Beispiel #3
0
        private VmTextBlock ParseLineBreaksToTextBlock(string text)
        {
            VmTextBlock textBlock = new VmTextBlock();
            var         lines     = text?.Split('\n') ?? new string[0] {
            };

            foreach (var line in lines)
            {
                TextFormatClientTypeEnum type = TextFormatClientTypeEnum.unstyled;
                textBlock.Blocks.Add(new VmTextLine()
                {
                    Text = line, Type = type, Key = GetUniqueKey(5)
                });
            }

            return(textBlock);
        }