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\"><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 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()); }
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)); } } }
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 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 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; } }
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); }
public string Transform(string content) { var converter = new MarkdownConverter(); return(converter.Convert(content)); }
public string Transform(string content) { var converter = new MarkdownConverter(); return converter.Convert(content); }