public void GetConvertedContent_WithNo_ExtendedFeature()
        {
            var markdownConverter = new MarkdownConverter();

              var expected = "| 1 | 20% | 1 3 | 1 4 | 1 5 |\r\n|---|-----|-----|-----|-----|\r\n| **2 1** | *2 2* | ***2 3*** | 2 4 | 2 5 |\r\n| 3 1 | 3 2 | 3 3 | 3 4 | 3 5 |\r\n| 4 1 | 4 2 | 4 3 | 4 4 | 4 5 |\r\n";
              var result = markdownConverter.GetConvertedContent(Constants.GetTableWithAllFeatures());
              Assert.That(result, Is.EqualTo(expected));
        }
        public void ConvertMarkdownToHtml()
        {
            var markdownConverter = new MarkdownConverter();

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

            result.Should().Be("<h1>Test</h1>\r\n");
        }
        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>"));
        }
示例#4
0
 public static TopicViewModel CreateFrom(Topic topic, List <Reply> replies)
 {
     return(new TopicViewModel(topic)
     {
         HtmlContent = MarkdownConverter.ToHtml(topic.Content),
         Replies = replies
     });
 }
示例#5
0
        public void should_convert_markdown_to_html()
        {
            var md = "**Hello World**";

            var html = MarkdownConverter.ToHtml(md);

            Assert.Equal("<p><strong>Hello World</strong></p>\n", html);
        }
        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 GetConvertedContent_WithNo_ExtendedFeature()
        {
            var markdownConverter = new MarkdownConverter();

            var expected = "| 1 | 20% | 1 3 | 1 4 | 1 5 |\r\n|---|-----|-----|-----|-----|\r\n| **2 1** | *2 2* | ***2 3*** | 2 4 | 2 5 |\r\n| 3 1 | 3 2 | 3 3 | 3 4 | 3 5 |\r\n| 4 1 | 4 2 | 4 3 | 4 4 | 4 5 |\r\n";
            var result   = markdownConverter.GetConvertedContent(Constants.GetTableWithAllFeatures());

            Assert.That(result, Is.EqualTo(expected));
        }
        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());
        }
        private static async Task <ConvertionResult> ExecuteConverter(IReadOnlyList <string> pageContent, ConversionOptions options = null)
        {
            var mockHandler = CreateMockHttpMessageHandler(pageContent.ToArray());

            options ??= new ConversionOptions();

            var converter = new MarkdownConverter(options, httpClient: new HttpClient(mockHandler));

            return(await converter.ConvertAsync(Enumerable.Range(0, pageContent.Count).Select(ConstructPageUriForIndex)));
        }
        private static async Task <ConvertionResult> ExecuteConverter(string pageContent, ConversionOptions options = null)
        {
            var mockHandler = CreateMockHttpMessageHandler(pageContent);

            options ??= new ConversionOptions();

            var converter = new MarkdownConverter(options, httpClient: new HttpClient(mockHandler));

            return(await converter.ConvertAsync(pageUrl));
        }
示例#11
0
        public async Task <HttpResponseMessage> TranslateToUseCaseScenario()
        {
            if (Request.Content.IsMimeMultipartContent() == false)
            {
                return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
            }

            var workingPath = string.Empty;

            try {
                workingPath = CreateWorkingDirectory();

                var provider = new MultipartFormDataStreamProvider(workingPath);
                await Request.Content.ReadAsMultipartAsync(provider);

                var attachmentsProvider = new AttachmentsProvider(provider);
                var phrases             = attachmentsProvider.Validate();
                if (phrases.Any())
                {
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        ReasonPhrase = string.Join(Environment.NewLine, phrases)
                    });
                }

                UseCaseCatalog catalog;
                using (var reader = new StreamReader(attachmentsProvider.CatalogFileName)) {
                    catalog = new UseCaseReader(workingPath).ReadFrom(reader, attachmentsProvider.CatalogFileName, DateTime.Now);
                    MarkdownConverter.CreateConvertedMarkdownTo(catalog, workingPath);
                }

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = CreateUseCaseScenarioResponseContent(workingPath, provider.Contents[0].Headers.ContentDisposition.FileName, catalog),
                });
            }
            catch (ApplicationException e) {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = e.Message
                });
            }
            finally {
                try {
                    if (Directory.Exists(workingPath))
                    {
                        Directory.Delete(workingPath);
                    }
                }
                catch {
                    // Do nothing.
                }
            }
        }
示例#12
0
        private string TransformValue()
        {
            if (String.IsNullOrEmpty(Value))
            {
                return(Value);
            }

            string html = MarkdownConverter.Convert(Value);

            return(html);
        }
示例#13
0
        public void Should_Convert_Markdown_To_Html_Correctly()
        {
            string markdown = GetStream("BetterCms.Test.Module.Contents.Markdown.markdown.txt");
            string html     = GetStream("BetterCms.Test.Module.Contents.Markdown.html.txt");

            var result = MarkdownConverter.ToHtml(markdown);

            result = ClearSpaces(result);
            html   = ClearSpaces(html);

            Assert.AreEqual(html, result);
        }
        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 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 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 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());
        }
示例#18
0
        public void should_convert_markdown_with_fenced_code_block()
        {
            var md = @"**Hello World**

```js
console.log('hello js');
```

text after code block";

            var html = MarkdownConverter.ToHtml(md);

            Assert.Equal("<p><strong>Hello World</strong></p>\n<pre><code class=\"language-js\">console.log('hello js');\n</code></pre>\n\n<p>text after code block</p>\n", html);
        }
示例#19
0
        public ActionResult Display(int websiteID, int pageID, int sectionID)
        {
            IDBConnector   db      = DBConnectorFactory.GetDBConnector();
            DBSectionModel section = db.SelectSection(sectionID);

            if (section != null)
            {
                section.PageID = pageID;
                section.Text   = MarkdownConverter.MarkdownToHTML(section.Text, websiteID);

                return(View(ConvertSectionModel(section)));
            }

            return(RedirectToAction(StringKeys.EDIT_FROM_ID, StringKeys.PAGE_CONTROLLER, new { pageID }));
        }
示例#20
0
        public ActionResult Create(SectionModel section)
        {
            if (GetValid(section))
            {
                IDBConnector db    = DBConnectorFactory.GetDBConnector();
                int          index = db.InsertSection(ConvertSectionModel(section));

                List <SectionLinkModel> links = MarkdownConverter.FindInternalLinks(section.Text, index);
                db.InsertSectionLinks(links);

                return(RedirectToAction(StringKeys.EDIT_FROM_ID, StringKeys.PAGE_CONTROLLER, new { pageID = section.PageID }));
            }

            return(View(section));
        }
示例#21
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>"));
        }
示例#22
0
        public void should_convert_markdown_with_fenced_code_block_and_unescape_code_content()
        {
            var md = @"**Hello World**

```html
&lt;html&gt;
&lt;title&gt;title text&lt;/title&gt;
&lt;/html&gt;
```

text after code block";

            var html = MarkdownConverter.ToHtml(md);

            Assert.Equal("<p><strong>Hello World</strong></p>\n<pre><code class=\"language-html\">&lt;html&gt;\n&lt;title&gt;title text&lt;/title&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>text after code block</p>\n", html);
        }
        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());
        }
        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));
                }
            }
        }
示例#25
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);
                }
            }
        }
示例#26
0
        public ActionResult Edit(SectionModel section)
        {
            if (GetValid(section))
            {
                IDBConnector   db        = DBConnectorFactory.GetDBConnector();
                DBSectionModel dbSection = ConvertSectionModel(section);
                db.UpdateSection(dbSection);
                db.UpdatePosition(dbSection);

                List <SectionLinkModel> links = MarkdownConverter.FindInternalLinks(section.Text, section.SectionID);
                db.MergeSectionLinks(links, section.SectionID);

                return(RedirectToAction(StringKeys.EDIT_FROM_ID, StringKeys.PAGE_CONTROLLER, new { pageID = section.PageID }));
            }

            return(View(section));
        }
        public void ToHTml_EmptyMarkdown_Throws()
        {
            // Setup the test.
            string markdown = string.Empty;

            try
            {
                // Run the test.
                MarkdownConverter target = new MarkdownConverter();
                target.ToHtml(markdown);
            }
            catch (ArgumentException ex)
            {
                // Validate the results.
                Assert.AreEqual("markdown", ex.ParamName);
                throw;
            }
        }
        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));
        }
示例#29
0
 private void Update(string markdown)
 {
     if (markdown == null)
     {
         return;
     }
     try
     {
         markdown = Utility.RemoveYamlFrontMatter(markdown);
         var html = MarkdownConverter.ConvertToHtml(markdown);
         var div  = GetContentsDiv();
         div.InnerHtml = html;
         WordCount     = (div.InnerText as string).WordCount();
     }
     catch (CommonMarkException e)
     {
         MessageBox.Show(e.ToString());
     }
 }
示例#30
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);
        }
示例#31
0
 private void Update(string markdown)
 {
     if (markdown == null)
     {
         return;
     }
     try
     {
         markdown = Utility.RemoveYamlFrontMatter(markdown);
         var html = MarkdownConverter.ConvertToHtml(markdown);
         var div  = GetContentsDiv();
         div.innerHTML = ScrubHtml(html);
         WordCount     = div.innerText.WordCount();
     }
     catch (CommonMarkException e)
     {
         MessageBox.Show(e.ToString(), App.Title);
     }
 }
 public void GetFileExtension_ReturnsMd()
 {
     var result = new MarkdownConverter().GetFileExtension();
       Assert.That(result, Is.EqualTo("md"));
 }
示例#33
0
        private void InitializeWindow()
        {
            InitializeComponent();

            this.Size = UserSettings.LoadWindowSize();
            this.Icon = Properties.Resources.Marker;

            appName = Application.ProductName;

            markdownFont = Properties.Settings.Default.MarkdownFont;
            htmlFont = Properties.Settings.Default.HtmlFont;

            converter = new MarkdownConverter();
            converter.Font = htmlFont;

            fileHandler = new FileHandler();

            lastSavedFilename = "";
            lastSavedFilePath = "";

            markdownTextChanged = false;
        }
示例#34
0
 public string Transform(string content)
 {
     var converter = new MarkdownConverter();
     return converter.Convert(content);
 }