public void TestConvert()
        {
            var    converter = new MarkdownConverter();
            string html      = converter.Convert("##Header##", typeof(string), null, CultureInfo.CurrentCulture) as string;

            Assert.That(html, Is.Not.Null);
            Assert.That(html, Contains.Substring("<h2>Header</h2>"));
        }
        public void ConvertMarkdownToHtml()
        {
            var markdownConverter = new MarkdownConverter();

            var result = markdownConverter.Convert("# Test");

            result.Should().Be("<h1>Test</h1>\r\n");
        }
        public void ConvertRuleToMarkdown() //https://rules.ssw.com.au/use-the-right-html-figure-caption
        {
            string content = "<p class=\"ssw15-rteElement-CodeArea\">&lt;div&gt;<br>&#160;&#160;&lt;img alt=&quot;&quot;/&gt;<br>&#160; &lt;p&gt;Figure&#58; Caption&lt;/p&gt;<br>&lt;/div&gt; </p><dd class=\"ssw15-rteElement-FigureBad\">Figure&#58; Bad Example​ </dd><p>Instead, you should use \r\n   <b>&lt;figure&gt;</b> and \r\n   <b>&lt;figcaption&gt; </b>as per&#160;<a href=\"https&#58;//www.w3schools.com/TAGS/tag_figcaption.asp\">https&#58;//www.w3schools.com/TAGS/tag_figcaption.asp​</a>.&#160;This structure gives semantic&#160;meaning&#160;to&#160;the image and&#160;figure&#58;<br></p><p class=\"ssw15-rteElement-CodeArea\">&lt;figure&gt;<br>&#160;&#160;&lt;img&#160;src=&quot;image.jpg&quot;&#160;alt=&quot;Image&quot; /&gt;<br>&#160;&#160;&lt;figcaption&gt;Figure&#58; Caption&lt;/figcaption&gt;<br>&lt;/figure&gt; </p><dd class=\"ssw15-rteElement-FigureGood\">Figure&#58; Good Example​​​​​​<br></dd><h3 class=\"ssw15-rteElement-H3\">​​The old way​<br></h3><p>For some internal sites, we still use the old way to place images&#58; Using&#160;<b>&lt;dl&gt;</b>,&#160;<b>&lt;dt&gt;</b> (which is the item in the list – in our case an image), and \r\n   <b>&lt;dd&gt;</b>for a caption. \r\n   <br></p><p class=\"ssw15-rteElement-CodeArea\">&lt;dl class=&quot;image&quot;&gt; OR &lt;dl class=&quot;badImage&quot;&gt; OR &lt;dl class=&quot;goodImage&quot;&gt; <br>&#160; &lt;dt&gt;&lt;img src=&quot;image.jpg&quot;​ alt=&quot;Image&quot;/&gt;&lt;/dt&gt;<br>&#160; &lt;dd&gt;Figure&#58; Caption&lt;/dd&gt; <br>&lt;/dl&gt;<br></p><dd class=\"ssw15-rteElement-FigureNormal\"> \r\n​\r\n      \r\n      Figure&#58; Good Example​<br></dd><div>\r\n<p><b>​Note&#58;</b>&#160;&lt;dl&gt; stands for &quot;<b>definition list</b>&quot;; &lt;dt&gt; for &quot;<b>definition term</b>&quot;; and &lt;dd&gt; for &quot;<b>definition description</b>&quot;.<br></p><h3 class=\"ssw15-rteElement-H3\">​Relate Rule<br></h3><ul><li> \r\n      <a href=\"/_layouts/15/FIXUPREDIRECT.ASPX?WebId=3dfc0e07-e23a-4cbb-aac2-e778b71166a2&amp;TermSetId=07da3ddf-0924-4cd2-a6d4-a4809ae20160&amp;TermId=810b7dab-f94c-4495-bf88-bb80c3bc9776\">Figures - Do you add useful and concise figure text?​​​</a><br></li></ul></div>";

            string converted = MarkdownConverter.Convert(content);

            converted.Should().Be(@"");
        }
        public void CorrectlyHandlesNewParagraph()
        {
            var speech = MarkdownConverter.Convert($"hello{Environment.NewLine}world.{Environment.NewLine}{Environment.NewLine}New Paragraph");

            Assert.Equal(2, speech.Elements.Count);
            Assert.True(speech.Elements.All(e => e is Paragraph));

            Output.WriteLine(speech.ToXml());
        }
Esempio n. 5
0
        private string TransformValue()
        {
            if (String.IsNullOrEmpty(Value))
            {
                return(Value);
            }

            string html = MarkdownConverter.Convert(Value);

            return(html);
        }
        public void CanHandleStrong()
        {
            var speech = MarkdownConverter.Convert("**hello!**");

            Assert.Single(speech.Elements);
            var first = NonStructureElement(speech) as Emphasis;

            Assert.NotNull(first);
            Assert.Equal(EmphasisLevel.Strong, first.Level);
            Assert.Equal("hello!", first.Text);
            Output.WriteLine(speech.ToXml());
        }
        public void CanHandleEmphasis()
        {
            var speech = MarkdownConverter.Convert("*hello*");

            Assert.Single(speech.Elements);

            var first = NonStructureElement(speech) as Prosody;

            Assert.NotNull(first);
            Assert.Equal(ProsodyPitch.ExtraHigh, first.Pitch);

            Output.WriteLine(speech.ToXml());
        }
        public void CanHandlePlainText()
        {
            var speech = MarkdownConverter.Convert("hello");

            Assert.Single(speech.Elements);

            var first = NonStructureElement(speech) as PlainText;

            Assert.NotNull(first);
            Assert.Equal("hello", first.Text);

            Output.WriteLine(speech.ToXml());
        }
        public void TreatLineBreakAsNewSentence()
        {
            var speech = MarkdownConverter.Convert($"hello{Environment.NewLine}world.");

            Assert.Single(speech.Elements);

            var paragraph = speech.Elements.First() as Paragraph;

            Assert.NotNull(paragraph);
            Assert.Equal(2, paragraph.Elements.Count);
            Assert.True(paragraph.Elements.All(e => e is Sentence));

            Output.WriteLine(speech.ToXml());
        }
Esempio n. 10
0
        public void TestConvert([Values] IssueTheme theme)
        {
            var options = Factory.Get <IOptionsProvider>();

            Assert.That(options, Is.Not.Null);
            Assert.That(options.Options, Is.Not.Null);

            options.Options.IssueTheme = theme;

            var    converter = new MarkdownConverter();
            string html      = converter.Convert("##Header##", typeof(string), null, CultureInfo.CurrentCulture) as string;

            Assert.That(html, Is.Not.Null);
            Assert.That(html, Contains.Substring("<h2>Header</h2>"));
        }
        private void ConvertEachFile(IEnumerable <string> paths, MarkdownConversionType conversionType, bool isLiteral, PSMarkdownOptionInfo optionInfo)
        {
            foreach (var path in paths)
            {
                var resolvedPaths = ResolvePath(path, isLiteral);

                foreach (var resolvedPath in resolvedPaths)
                {
                    WriteObject(
                        MarkdownConverter.Convert(
                            ReadContentFromFile(resolvedPath)?.Result,
                            conversionType,
                            optionInfo));
                }
            }
        }
Esempio n. 12
0
        public void CanHandleMulipleInlineInSingleSentence()
        {
            var speech = MarkdownConverter.Convert("**hello** world");

            Assert.Single(speech.Elements);

            var first  = NonStructureElement(speech) as Emphasis;
            var second = NonStructureElement(speech, 1) as PlainText;

            Assert.NotNull(first);
            Assert.NotNull(second);
            Assert.Equal("hello", first.Text);
            Assert.Equal(" world", second.Text);

            Output.WriteLine(speech.ToXml());
        }
Esempio n. 13
0
        private void WriteCategoryPages(SpRulesDataSet data)
        {
            foreach (var cat in data.Categories)
            {
                if (!cat.Rules.Any())
                {
                    continue;
                }
                var catPaths = new CategoryPaths(_config, cat);


                if (_config.ProcessHistory)
                {
                    ProcessCategoryHistory(cat);
                }


                var html = $@"
{cat.IntroText}
{cat.Content}
";


                string markdown =
                    $@"---
{YamlSerializer.Serialize(new CategoryMdModel(cat))}
---
{ MarkdownConverter.Convert(html)}

";
                _log.LogInformation($"writing {catPaths.CategoryFileFull}");
                using (var sw = new StreamWriter(catPaths.CategoryFileFull, false))
                {
                    sw.Write(markdown);
                    sw.Flush();
                }
                if (_config.ProcessHistory)
                {
                    GitCommit(
                        _config.TargetRepository,
                        $"Extracted from Sharepoint to Git",
                        new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow),
                        new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow),
                        catPaths.CategoryFileRelative);
                }
            }
        }
Esempio n. 14
0
        public static string ToMarkdownBody(string introText, string content, bool skipHtmlMarkdownConversion)
        {
            string html = $@"
{introText}
<br><excerpt class='endintro'></excerpt><br>
{content}

";

            if (skipHtmlMarkdownConversion)
            {
                //We don't want to convert all the history from HTML to Markdown so we skip it here
                return(html);
            }

            string result = MarkdownConverter.Convert(html);

            return(result);
        }
        private static string ConvertMessage(string message)
        {
            // Strip a@title attributes (which don't work with showdown), and undo Disqus link shortening.
            var html = AnchorFixer.Replace(message, match =>
            {
                if (match.Groups[2].Value.EndsWith("..."))
                {
                    var shortened = match.Groups[2].Value.Substring(0, match.Groups[2].Value.Length - 3);
                    if (match.Groups[1].Value.StartsWith(shortened))
                    {
                        return($"<a href=\"{match.Groups[1].Value}\">{match.Groups[1].Value}</a>");
                    }
                }

                return($"<a href=\"{match.Groups[1].Value}\">{match.Groups[2].Value}</a>");
            });

            return(MarkdownConverter.Convert(html));
        }
        /// <summary>
        /// Override ProcessRecord.
        /// </summary>
        protected override void ProcessRecord()
        {
            switch (ParameterSetName)
            {
            case InputObjParamSet:
                object baseObj = InputObject.BaseObject;

                if (baseObj is FileInfo fileInfo)
                {
                    WriteObject(
                        MarkdownConverter.Convert(
                            ReadContentFromFile(fileInfo.FullName)?.Result,
                            _conversionType,
                            _mdOption));
                }
                else if (baseObj is string inpObj)
                {
                    WriteObject(MarkdownConverter.Convert(inpObj, _conversionType, _mdOption));
                }
                else
                {
                    string      errorMessage = StringUtil.Format(ConvertMarkdownStrings.InvalidInputObjectType, baseObj.GetType());
                    ErrorRecord errorRecord  = new(
                        new InvalidDataException(errorMessage),
                        "InvalidInputObject",
                        ErrorCategory.InvalidData,
                        InputObject);

                    WriteError(errorRecord);
                }

                break;

            case PathParameterSet:
                ConvertEachFile(Path, _conversionType, isLiteral: false, optionInfo: _mdOption);
                break;

            case LiteralPathParameterSet:
                ConvertEachFile(LiteralPath, _conversionType, isLiteral: true, optionInfo: _mdOption);
                break;
            }
        }
Esempio n. 17
0
    public void PathShouldBeAdjustedToOutputFolder(string outputLocation)
    {
        var cliOptions = new CliOptions
        {
            OutputLocation = outputLocation
        };

        var converter = new MarkdownConverter(MockFactory.Get().Object, cliOptions);

        var markdownFile = new MarkdownFile
        {
            Name = "test.md"
        };

        var result = converter.Convert(markdownFile);

        // Since the null string can't be searched for, lets cast it to empty
        // (all strings contain the empty string, so this should just not throw an exception)
        Assert.Contains(outputLocation, result.Name);
    }
Esempio n. 18
0
        public string Transform(string content)
        {
            var converter = new MarkdownConverter();

            return(converter.Convert(content));
        }
Esempio n. 19
0
 public string Transform(string content)
 {
     var converter = new MarkdownConverter();
     return converter.Convert(content);
 }