Example #1
0
        public string Render(string markdownText)
        {
            var reader   = new TokenReader(MdTokenDescriptions);
            var tokens   = reader.SplitToTokens(markdownText);
            var rootTree = new SyntaxTree(SyntaxTreeType.Text, tokens);

            AddChildTrees(rootTree);
            var converter = new TreeConverter(SyntaxTreesDescriptions, rootTree);

            return(converter.GetTaggedText());
        }
        public static bool AddDefaultText(TreeConverter converter, List <SyntaxTree> children, int numberOfCurrentTree, StringBuilder builder,
                                          out int numberOfSyntaxTrees)
        {
            numberOfSyntaxTrees = 1;
            var tree = children[numberOfCurrentTree];

            builder.Append(tree.StartLine);
            converter.AddTreeText(tree, builder);
            builder.Append(tree.EndLine);
            return(true);
        }
        public static bool TryAddSurroundingTags(
            TreeConverter converter, List <SyntaxTree> children, int numberOfCurrentTree, StringBuilder builder,
            out int numberOfSyntaxTrees)
        {
            numberOfSyntaxTrees = 1;
            var tree          = children[numberOfCurrentTree];
            var needToAddTags = Md.TagsForTokenTypes.ContainsKey(tree.Type) &&
                                RuleForTagsAdding.IsNeedToAddTags(tree, converter.RootTree.Tokens);

            if (!needToAddTags)
            {
                return(false);
            }
            builder.Append(Md.TagsForTokenTypes[tree.Type].Item1);
            converter.AddTreeText(tree, builder);
            builder.Append(Md.TagsForTokenTypes[tree.Type].Item2);
            return(true);
        }
        public static bool TryAddLinkTag(
            TreeConverter converter, List <SyntaxTree> children, int numberOfCurrentTree, StringBuilder builder,
            out int numberOfSyntaxTrees)
        {
            numberOfSyntaxTrees = 2;
            if (numberOfCurrentTree >= children.Count - 1)
            {
                return(false);
            }
            if (children[numberOfCurrentTree].Type != SyntaxTreeType.TextInSquareBrackets ||
                children[numberOfCurrentTree + 1].Type != SyntaxTreeType.TextInParentheses)
            {
                return(false);
            }
            var link           = Token.ConcatenateTokens(children[numberOfCurrentTree + 1].Tokens);
            var linkOpeningTag = $"<a href=\"{link}\">";

            builder.Append(linkOpeningTag);
            converter.AddTreeText(children[numberOfCurrentTree], builder);
            builder.Append("</a>");
            return(true);
        }