Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="level"></param>
        /// <returns>
        /// return headingNode if expected heading level encounterd.
        /// null, if higher level encountered.
        /// throw exception, if unexpected node encountered.
        /// </returns>
        protected HeadingNode GetHeadingWithExpectedLevel(MarkdownNode node, int level)
        {
            if (node == null)
            {
                return(null);
            }

            // check for appropriate header
            if (node.NodeType != MarkdownNodeType.Heading)
            {
                throw new HelpSchemaException(GetExtent(node), "Expect Heading");
            }

            var headingNode = node as HeadingNode;

            if (headingNode.HeadingLevel < level)
            {
                UngetNode(node);
                return(null);
            }

            if (headingNode.HeadingLevel != level)
            {
                throw new HelpSchemaException(headingNode.SourceExtent, "Expect Heading level " + level);
            }
            return(headingNode);
        }
Esempio n. 2
0
 private TNode AssertNodeType <TNode>(
     MarkdownNode markdownNode,
     MarkdownNodeType expectedNodeType)
 {
     Assert.NotNull(markdownNode);
     Assert.Equal(expectedNodeType, markdownNode.NodeType);
     return(Assert.IsType <TNode>(markdownNode));
 }
Esempio n. 3
0
 public static void Test(this MarkdownNode node, Action <MarkdownNode> theTest)
 {
     if (node == null)
     {
         Assert.Fail("Markdown node was null when it shouldn't have been");
     }
     theTest(node);
 }
Esempio n. 4
0
        protected void UngetNode(MarkdownNode node)
        {
            if (_ungotNode != null)
            {
                throw new ArgumentException("Cannot ungot token, already ungot one");
            }

            _ungotNode = node;
        }
Esempio n. 5
0
        public MDTester(MarkdownNode root)
        {
            var posInfo = new PosInfo()
            {
                parent       = root,
                currentIndex = -1
            };

            _stack.Push(posInfo);
        }
Esempio n. 6
0
 public static void TestIsBlankLine(this MarkdownNode node)
 {
     if (node == null)
     {
         Assert.Fail("Null node.  Expected blank line");
     }
     else if (node.Type != MarkdownType.BlankLine)
     {
         Assert.Fail("Node not a blank line as expected");
     }
 }
Esempio n. 7
0
 public bool HandleLine(MarkdownNode context, string line)
 {
     if (string.IsNullOrWhiteSpace(line))
     {
         context.AddChild(new MarkdownNode()
         {
             Type = MarkdownType.BlankLine
         });
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
        protected MarkdownNode GetNextNode()
        {
            if (_ungotNode != null)
            {
                _ungotNode = null;
                return(_rootEnumerator.Current);
            }

            if (_rootEnumerator.MoveNext())
            {
                return(_rootEnumerator.Current);
            }

            return(null);
        }
Esempio n. 9
0
        protected SourceExtent GetExtent(MarkdownNode node)
        {
            TextNode textNode = node as TextNode;

            if (textNode != null)
            {
                return(textNode.SourceExtent);
            }
            ParagraphNode paragraphNode = node as ParagraphNode;

            if (paragraphNode != null && paragraphNode.Spans.Any())
            {
                return(paragraphNode.Spans.First().SourceExtent);
            }

            return(new SourceExtent("", 0, 0, 0, 0));
        }
Esempio n. 10
0
        public XElement Format(INode node, IEnumerable <INode> features)
        {
            /*
             * <div id="feature">
             * <h1>Folder Name</h1>
             * <ul class="list">
             * <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
             * <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
             * <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
             * </ul>
             * <div>
             */
            var directoryInfo = node.OriginalLocation as DirectoryInfoBase;

            if (directoryInfo == null)
            {
                throw new ArgumentOutOfRangeException("node", "Argument node must contain a DirectoryInfo.");
            }

            string[] files = directoryInfo.GetFiles().Select(f => f.FullName).ToArray();

            INode[] featuresThatAreDirectChildrenOfFolder =
                features.Where(f => f.OriginalLocation is FileInfoBase).Where(
                    f => files.Contains(f.OriginalLocation.FullName)).ToArray();

            var div = new XElement(
                this.xmlns + "div",
                new XAttribute("id", "feature"),
                new XElement(this.xmlns + "h1", node.Name));

            MarkdownNode markdownNode =
                featuresThatAreDirectChildrenOfFolder.Where(n => n.IsIndexMarkDownNode()).OfType <MarkdownNode>().FirstOrDefault();

            if (markdownNode != null)
            {
                div.Add(
                    new XElement(
                        this.xmlns + "div",
                        new XAttribute("class", "folderDescription"),
                        markdownNode.MarkdownContent));
            }

            div.Add(this.FormatList(node, featuresThatAreDirectChildrenOfFolder.OfType <FeatureNode>().OrderBy(feature => feature.Name)));

            return(div);
        }
 public MarkdownNode Visit(MarkdownNode node) => node switch
 {
Esempio n. 12
0
 public MarkdownToken(TextFile file, int index, int start, int stop, MarkdownNode markdownNode)
     : base(file, index, start, stop)
 {
     MarkdownNode = markdownNode;
 }