Exemple #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);
        }
Exemple #2
0
 private TNode AssertNodeType <TNode>(
     MarkdownNode markdownNode,
     MarkdownNodeType expectedNodeType)
 {
     Assert.NotNull(markdownNode);
     Assert.Equal(expectedNodeType, markdownNode.NodeType);
     return(Assert.IsType <TNode>(markdownNode));
 }
Exemple #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);
 }
Exemple #4
0
        protected void UngetNode(MarkdownNode node)
        {
            if (_ungotNode != null)
            {
                throw new ArgumentException("Cannot ungot token, already ungot one");
            }

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

            _stack.Push(posInfo);
        }
Exemple #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");
     }
 }
Exemple #7
0
 public bool HandleLine(MarkdownNode context, string line)
 {
     if (string.IsNullOrWhiteSpace(line))
     {
         context.AddChild(new MarkdownNode()
         {
             Type = MarkdownType.BlankLine
         });
         return(true);
     }
     return(false);
 }
Exemple #8
0
        protected MarkdownNode GetNextNode()
        {
            if (_ungotNode != null)
            {
                _ungotNode = null;
                return(_rootEnumerator.Current);
            }

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

            return(null);
        }
Exemple #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));
        }
        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
 {
Exemple #12
0
 public MarkdownToken(TextFile file, int index, int start, int stop, MarkdownNode markdownNode)
     : base(file, index, start, stop)
 {
     MarkdownNode = markdownNode;
 }