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>")); }
public static TopicViewModel CreateFrom(Topic topic, List <Reply> replies) { return(new TopicViewModel(topic) { HtmlContent = MarkdownConverter.ToHtml(topic.Content), Replies = replies }); }
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\"><div><br>  <img alt=""/><br>  <p>Figure: Caption</p><br></div> </p><dd class=\"ssw15-rteElement-FigureBad\">Figure: Bad Example </dd><p>Instead, you should use \r\n <b><figure></b> and \r\n <b><figcaption> </b>as per <a href=\"https://www.w3schools.com/TAGS/tag_figcaption.asp\">https://www.w3schools.com/TAGS/tag_figcaption.asp</a>. This structure gives semantic meaning to the image and figure:<br></p><p class=\"ssw15-rteElement-CodeArea\"><figure><br>  <img src="image.jpg" alt="Image" /><br>  <figcaption>Figure: Caption</figcaption><br></figure> </p><dd class=\"ssw15-rteElement-FigureGood\">Figure: 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: Using <b><dl></b>, <b><dt></b> (which is the item in the list – in our case an image), and \r\n <b><dd></b>for a caption. \r\n <br></p><p class=\"ssw15-rteElement-CodeArea\"><dl class="image"> OR <dl class="badImage"> OR <dl class="goodImage"> <br>  <dt><img src="image.jpg" alt="Image"/></dt><br>  <dd>Figure: Caption</dd> <br></dl><br></p><dd class=\"ssw15-rteElement-FigureNormal\"> \r\n\r\n \r\n Figure: Good Example<br></dd><div>\r\n<p><b>Note:</b> <dl> stands for "<b>definition list</b>"; <dt> for "<b>definition term</b>"; and <dd> for "<b>definition description</b>".<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&TermSetId=07da3ddf-0924-4cd2-a6d4-a4809ae20160&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()); }
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)); }
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. } } }
private string TransformValue() { if (String.IsNullOrEmpty(Value)) { return(Value); } string html = MarkdownConverter.Convert(Value); return(html); }
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()); }
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); }
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 })); }
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)); }
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>")); }
public void should_convert_markdown_with_fenced_code_block_and_unescape_code_content() { var md = @"**Hello World** ```html <html> <title>title text</title> </html> ``` text after code block"; var html = MarkdownConverter.ToHtml(md); Assert.Equal("<p><strong>Hello World</strong></p>\n<pre><code class=\"language-html\"><html>\n<title>title text</title>\n</html>\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)); } } }
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); } } }
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)); }
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()); } }
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 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")); }
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; }
public string Transform(string content) { var converter = new MarkdownConverter(); return converter.Convert(content); }