Пример #1
0
        public void CanUseMultiplyInputStrings()
        {
            MarkdownParser markdownParser = new MarkdownParser();
            DocumentNode   documentNode   =
                markdownParser.ParseString(new string[] {
                @"# Hello
", // TODO: bug: if there is no new-line after header, it fails to parse it.
                @"This is new line",
                @"```powershell
Code snippet
```"
            });


            Assert.Equal(3, documentNode.Children.Count());

            HeadingNode node1 =
                this.AssertNodeType <HeadingNode>(
                    documentNode.Children.ElementAtOrDefault(0),
                    MarkdownNodeType.Heading);
            ParagraphNode node2 =
                this.AssertNodeType <ParagraphNode>(
                    documentNode.Children.ElementAtOrDefault(1),
                    MarkdownNodeType.Paragraph);
            CodeBlockNode node3 =
                this.AssertNodeType <CodeBlockNode>(
                    documentNode.Children.ElementAtOrDefault(2),
                    MarkdownNodeType.CodeBlock);
        }
Пример #2
0
        private void AddAboutHeading(HeadingNode headingNode, DocumentNode document)
        {
            const int level1Heading = 1;
            const int level2Heading = 2;

            if (document.Children.ElementAt(0) as HeadingNode == headingNode)
            {
                _stringBuilder.AppendLine(MarkdownStrings.AboutTopicFirstHeader.ToUpper());
            }
            else if (headingNode.HeadingLevel == level1Heading)
            {
                _stringBuilder.AppendLine(headingNode.Text.ToUpper());
            }
            else if (headingNode.HeadingLevel == level2Heading && document.Children.ElementAt(1) == headingNode)
            {
                _stringBuilder.AppendFormat("{0}{1}{2}{3}", AboutIndentation, headingNode.Text.ToLower(), NewLine, NewLine);
            }
            else if (headingNode.HeadingLevel == level2Heading)
            {
                _stringBuilder.AppendLine(headingNode.Text);
            }
            else
            {
                _stringBuilder.AppendFormat("{0}{1}{2}", AboutIndentation, headingNode.Text.ToUpper(), NewLine);
            }
        }
Пример #3
0
        public void CanPaserEmptySourceBlock()
        {
            DocumentNode documentNode = MarkdownStringToDocumentNode(
                @"#### 1:

```powershell
```

```powershell
[Parameter(
  ValueFromPipeline = $true,
  ParameterSetName = 'Set 1')]
```
");
            HeadingNode headingNode =
                this.AssertNodeType <HeadingNode>(
                    documentNode.Children.ElementAtOrDefault(0),
                    MarkdownNodeType.Heading);

            Assert.Equal(4, headingNode.HeadingLevel);

            CodeBlockNode codeBlockNode =
                this.AssertNodeType <CodeBlockNode>(
                    documentNode.Children.ElementAtOrDefault(1),
                    MarkdownNodeType.CodeBlock);

            Assert.Equal("", codeBlockNode.Text);
        }
Пример #4
0
        public void ParsesDocumentWithMultipleNodes()
        {
            string documentText =
                string.Format(
                    @"
# {0}

{2}

```
{1}
```

## {0}
{2} [{3}]({4})
", headingText, codeBlockText, paragraphText, hyperlinkText, hyperlinkUri);

            MarkdownParser markdownParser = new MarkdownParser();
            DocumentNode   documentNode   =
                markdownParser.ParseString(
                    documentText);

            HeadingNode headingNode =
                this.AssertNodeType <HeadingNode>(
                    documentNode.Children.ElementAtOrDefault(0),
                    MarkdownNodeType.Heading);

            Assert.Equal(headingText, headingNode.Text);
            Assert.Equal(1, headingNode.HeadingLevel);

            CodeBlockNode codeBlockNode =
                this.AssertNodeType <CodeBlockNode>(
                    documentNode.Children.ElementAtOrDefault(2),
                    MarkdownNodeType.CodeBlock);

            Assert.Equal(codeBlockText, codeBlockNode.Text);

            headingNode =
                this.AssertNodeType <HeadingNode>(
                    documentNode.Children.ElementAtOrDefault(3),
                    MarkdownNodeType.Heading);

            Assert.Equal(headingText, headingNode.Text);
            Assert.Equal(2, headingNode.HeadingLevel);

            ParagraphNode paragraphNode =
                this.AssertNodeType <ParagraphNode>(
                    documentNode.Children.ElementAtOrDefault(4),
                    MarkdownNodeType.Paragraph);

            Assert.Equal(paragraphText.Replace("\r\n", " "), paragraphNode.Spans.First().Text);

            HyperlinkSpan hyperlinkSpan =
                Assert.IsType <HyperlinkSpan>(
                    paragraphNode.Spans.ElementAt(1));

            Assert.Equal(hyperlinkText, hyperlinkSpan.Text);
            Assert.Equal(hyperlinkUri, hyperlinkSpan.Uri);
        }
Пример #5
0
        protected override void Write(AdfRenderer renderer, HeadingBlock obj)
        {
            var heading = new HeadingNode(obj.Level);

            renderer.Push(heading);
            renderer.WriteLeafInline(obj);
            renderer.Pop();
        }
Пример #6
0
 public static Block ToBlock(this HeadingNode node, Channel _chan = null)
 {
     return(new Paragraph(node.ToInline())
     {
         FontSize = 14,
         KeepTogether = true,
         KeepWithNext = false,
         Margin = new Thickness(0, 10, 0, 10)
     });
 }
Пример #7
0
        public void ParsesHeadingsWithHashPrefix()
        {
            for (int i = 1; i <= 6; i++)
            {
                HeadingNode headingNode =
                    this.ParseAndGetExpectedChild <HeadingNode>(
                        new String('#', i) + headingText + "\r\n",
                        MarkdownNodeType.Heading);

                Assert.Equal(i, headingNode.HeadingLevel);
                Assert.Equal(headingText, headingNode.Text);
            }
        }
Пример #8
0
        public string TocAsHtml(MarkdownDocument doc)
        {
            var node = new HeadingNode();

            foreach (var item in doc.OfType <HeadingBlock>())
            {
                node.Insert(new HeadingNode
                {
                    Id    = item.GetAttributes().Id,
                    Level = item.Level,
                    Title = item.Inline?.FirstChild.ToString()
                });
            }

            return(node.ToString());
        }
Пример #9
0
        public void ParsesHeadingsWithUnderlines()
        {
            string[] headingUnderlines =
            {
                new String('=', headingText.Length),
                new String('-', headingText.Length)
            };

            for (int i = 1; i <= 2; i++)
            {
                HeadingNode headingNode =
                    this.ParseAndGetExpectedChild <HeadingNode>(
                        headingText + "\r\n" + headingUnderlines[i - 1] + "\r\n",
                        MarkdownNodeType.Heading);

                Assert.Equal(i, headingNode.HeadingLevel);
                Assert.Equal(headingText, headingNode.Text);
            }
        }
Пример #10
0
        public string AboutMarkdownToString(DocumentNode document)
        {
            //ensure that all node types in the about topic are handeled.
            var acceptableNodeTypes = new List <MarkdownNodeType>
            {
                MarkdownNodeType.Heading,
                MarkdownNodeType.Paragraph,
                MarkdownNodeType.CodeBlock
            };

            if (document.Children.Any(c => (!acceptableNodeTypes.Contains(c.NodeType))))
            {
                throw new NotSupportedException("About Topics can only have heading, parapgrah or code block nodes in their Markdown Model.");
            }

            //processes all nodes in order
            foreach (var currentNode in document.Children)
            {
                switch (currentNode.NodeType)
                {
                case MarkdownNodeType.Paragraph:
                    ParagraphNode paragraphNode = currentNode as ParagraphNode;
                    AddAboutParagraph(paragraphNode);
                    break;

                case MarkdownNodeType.Heading:
                    HeadingNode headingNode = currentNode as HeadingNode;
                    AddAboutHeading(headingNode, document);
                    break;

                case MarkdownNodeType.CodeBlock:
                    CodeBlockNode codeblockNode = currentNode as CodeBlockNode;
                    AddAboutCodeBlock(codeblockNode);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RenderCleaner.FullNormalization(_stringBuilder.ToString()));
        }
Пример #11
0
        public void Render(string source, out string html, out string tree)
        {
            using (var sw = new StringWriter())
            {
                var doc = Markdown.ToHtml(source, sw, Pipeline);
                html = sw.ToString();
                var node = new HeadingNode();

                foreach (var item in doc)
                {
                    if (item is HeadingBlock hb)
                    {
                        node.Insert(new HeadingNode
                        {
                            Id    = hb.GetAttributes().Id,
                            Level = hb.Level,
                            Title = hb.Inline?.FirstChild.ToString()
                        });
                    }
                }

                tree = node.ToString();
            }
        }
Пример #12
0
        /// <summary>
        /// Exports the category.
        /// </summary>
        /// <param name="toc">The toc.</param>
        /// <param name="category">The category.</param>
        /// <param name="level">The level.</param>
        private void ExportCategory(NodeCollection toc, Category category, int level)
        {
            var knowledges    = knowledgeManager.GetByCategoryID(category.CategoryID);
            var subCategories = categoryManager.GetByParentCategoryID(category.CategoryID);

            if (knowledges.Count == 0 && subCategories.Count == 0)
            {
                return;
            }

            string categoryFileName = GetCategoryFileName(category);
            var    categoryFilePath = Path.Combine(destinationFolder, categoryFileName);


            var node = new HeadingNode(category.Name, categoryFilePath);

            toc.Add(node);



            folderTree.AppendFormat(@"<tr><td>{0}<a href='{1}'>{2}</a></td></tr>{3}",
                                    StringUtil.Clone("&nbsp;", level),
                                    categoryFileName,
                                    HttpUtility.HtmlAttributeEncode(category.Name),
                                    Environment.NewLine
                                    );

            var categoryTocBuilder = new StringBuilder(defaultHeader);

            categoryTocBuilder.AppendFormat(@"<tr><td><H1>{0}</H1></td></tr>", category.Name);



            foreach (var subCategory in subCategories)
            {
                categoryTocBuilder.AppendFormat("<tr><td>&nbsp;<a href='{1}'><b>{0}</b></a></td></tr>{2}",
                                                HttpUtility.HtmlAttributeEncode(subCategory.Name),
                                                GetCategoryFileName(subCategory),
                                                Environment.NewLine
                                                );
                ExportCategory(node.ChildNodes, subCategory, level + 1);
            }

            foreach (var knowledge in knowledges)
            {
                try
                {
                    ExportKnowledge(node.ChildNodes, knowledge, categoryTocBuilder);
                }

                catch (Exception ex)
                {
                    //TODO:Uncommetn
                    //Log.BusinessLayer.Error(String.Format("Error ExportKnowledge KnowledgeID={0}", knowledge.KnowledgeID), ex);
                    return;
                }
            }

            File.WriteAllText(categoryFilePath, categoryTocBuilder.ToString());
            generatedFiles.Add(categoryFilePath);
        }
Пример #13
0
        public void ParsesExample3FromGetPSSnapin()
        {
            string codeblockText =
                @"The first command gets snap-ins that have been added to the current session, including the snap-ins that are installed with Windows PowerShell. In this example, ManagementFeatures is not returned. This indicates that it has not been added to the session.
PS C:\>get-pssnapin

The second command gets snap-ins that have been registered on your system (including those that have already been added to the session). It does not include the snap-ins that are installed with Windows PowerShell.In this case, the command does not return any snap-ins. This indicates that the ManagementFeatures snapin has not been registered on the system.
PS C:\>get-pssnapin -registered

The third command creates an alias, ""installutil"", for the path to the InstallUtil tool in .NET Framework.
PS C:\>set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe

The fourth command uses the InstallUtil tool to register the snap-in. The command specifies the path to ManagementCmdlets.dll, the file name or ""module name"" of the snap-in.
PS C:\>installutil C:\Dev\Management\ManagementCmdlets.dll

The fifth command is the same as the second command. This time, you use it to verify that the ManagementCmdlets snap-in is registered.
PS C:\>get-pssnapin -registered

The sixth command uses the Add-PSSnapin cmdlet to add the ManagementFeatures snap-in to the session. It specifies the name of the snap-in, ManagementFeatures, not the file name.
PS C:\>add-pssnapin ManagementFeatures

To verify that the snap-in is added to the session, the seventh command uses the Module parameter of the Get-Command cmdlet. It displays the items that were added to the session by a snap-in or module.
PS C:\>get-command -module ManagementFeatures

You can also use the PSSnapin property of the object that the Get-Command cmdlet returns to find the snap-in or module in which a cmdlet originated. The eighth command uses dot notation to find the value of the PSSnapin property of the Set-Alias cmdlet.
PS C:\>(get-command set-alias).pssnapin";
            string descriptionText =
                @"This example demonstrates the process of registering a snap-in on your system and then adding it to your session. It uses ManagementFeatures, a fictitious snap-in implemented in a file called ManagementCmdlets.dll.";
            string documentText = string.Format(@"
#### -------------------------- EXAMPLE 3 --------------------------

```powershell
{0}

```
{1}


### RELATED LINKS
[Online Version:](https://go.microsoft.com/fwlink/p/?linkid=289570)
[Get-PSSnapin]()
[Remove-PSSnapin]()
[about_Profiles]()
[about_PSSnapins]()

## Clear-History

### SYNOPSIS
Deletes entries from the command history.

### DESCRIPTION
The Clear-History cmdlet deletes commands from the command history, that is, the list of commands entered during the current session.
Without parameters, Clear-History deletes all commands from the session history, but you can use the parameters of Clear-History to delete selected commands.

### PARAMETERS

#### CommandLine [String[]]

```powershell
[Parameter(ParameterSetName = 'Set 2')]
```

Deletes commands with the specified text strings. If you enter more than one string, Clear-History deletes commands with any of the strings.

", codeblockText, descriptionText);

            DocumentNode documentNode = MarkdownStringToDocumentNode(documentText);

            HeadingNode headingNode =
                this.AssertNodeType <HeadingNode>(
                    documentNode.Children.ElementAtOrDefault(0),
                    MarkdownNodeType.Heading);

            Assert.Equal(4, headingNode.HeadingLevel);

            CodeBlockNode codeBlockNode =
                this.AssertNodeType <CodeBlockNode>(
                    documentNode.Children.ElementAtOrDefault(1),
                    MarkdownNodeType.CodeBlock);

            Common.AssertMultilineEqual(codeblockText, codeBlockNode.Text);

            ParagraphNode paragraphNode =
                this.AssertNodeType <ParagraphNode>(
                    documentNode.Children.ElementAtOrDefault(2),
                    MarkdownNodeType.Paragraph);

            Common.AssertMultilineEqual(descriptionText, paragraphNode.Spans.First().Text);
        }
Пример #14
0
 public void Apply(HeadingNode heading)
 {
     Console.WriteLine("text-heading");
 }
Пример #15
0
 public void Apply(HeadingNode heading)
 {
     Console.WriteLine("highlight-heading");
 }
 public void Apply(HeadingNode node)
 {
     System.Console.WriteLine("HeadingNode--PlainText");
 }
 public void apply(HeadingNode heading)
 {
     Console.WriteLine("Applied highlight to Heading node.");
 }
 public void Apply(HeadingNode node)
 {
     System.Console.WriteLine("HeadingNode--Highlight");
 }
Пример #19
0
 public void Apply(HeadingNode headingNode)
 {
     System.Console.WriteLine("Highlight Heading");
 }