public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("MarkdigEngine processed a request."); // parse query parameter var text = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "text", true) == 0) .Value ?? string.Empty; if (text.Length > 1000) { text = text.Substring(0, 1000); } try { var result = _service.Markup(text, string.Empty); return(req.CreateResponse(HttpStatusCode.OK, new { name = MarkdownEngineName, html = result.Html, version = MARKIG_ENGINE_VERSION })); } catch (Exception ex) { return(req.CreateResponse(HttpStatusCode.OK, new { name = MarkdownEngineName, html = "exception: " + ex.Message, version = MARKIG_ENGINE_VERSION })); } }
public void LineNumberTest_CodeSnippet() { //arange var content = @"// <tag> line1 // </tag>"; if (!Directory.Exists("LineNumber")) { Directory.CreateDirectory("LineNumber"); } File.WriteAllText("LineNumber/Program.cs", content.Replace("\r\n", "\n")); // act var parameter = new MarkdownServiceParameters { BasePath = ".", Extensions = new Dictionary <string, object> { { LineNumberExtension.EnableSourceInfo, true } } }; var service = new MarkdigMarkdownService(parameter); var marked = service.Markup(@"[!code[tag-test](LineNumber/Program.cs#Tag)]", "Topic.md"); // assert var expected = @"<pre><code sourceFile=""Topic.md"" sourceStartLineNumber=""1"" sourceEndLineNumber=""1"" name=""tag-test"">line1 </code></pre>"; Assert.Equal(expected.Replace("\r\n", "\n"), marked.Html); }
public void CodeSnippetNotFound() { var parameter = new MarkdownServiceParameters { BasePath = ".", Tokens = new Dictionary <string, string> { { "codeIncludeNotFound", "你要查找的示例似乎已移动! 不要担心,我们正在努力解决此问题。" }, { "warning", "<h5>警告</h5>" } }.ToImmutableDictionary(), Extensions = new Dictionary <string, object> { { "EnableSourceInfo", false } } }; var service = new MarkdigMarkdownService(parameter); var marked = service.Markup(@"[!code-csharp[name](Program1.cs)]", "Topic.md"); // assert var expected = @"<div class=""WARNING""> <h5>警告</h5> <p>你要查找的示例似乎已移动! 不要担心,我们正在努力解决此问题。</p> </div>"; Assert.Equal(expected.Replace("\r\n", "\n"), marked.Html.Replace("\r\n", "\n")); }
public static MarkupResult Markup(string content, string filePath = null) { var parameter = new MarkdownServiceParameters { BasePath = "." }; var service = new MarkdigMarkdownService(parameter); return(service.Markup(content, filePath ?? string.Empty)); }
private static MarkupResult SimpleMarkup(string source) { var parameter = new MarkdownServiceParameters { BasePath = "." }; var service = new MarkdigMarkdownService(parameter); return(service.Markup(source, "Topic.md")); }
public static MarkupResult MarkupWithoutSourceInfo(string content, string filePath = null) { var parameter = new MarkdownServiceParameters { BasePath = ".", Extensions = new Dictionary <string, object> { { LineNumberExtension.EnableSourceInfo, false } } }; var service = new MarkdigMarkdownService(parameter); return(service.Markup(content, filePath ?? string.Empty)); }
private static MarkupResult SimpleMarkup(string source) { var parameter = new MarkdownServiceParameters { BasePath = ".", Extensions = new Dictionary <string, object> { { LineNumberExtension.EnableSourceInfo, true } } }; var service = new MarkdigMarkdownService(parameter); return(service.Markup(source, "Topic.md")); }
private static string Markup(string markdown, string filePath, string basePath = ".") { EnvironmentContext.FileAbstractLayerImpl = FileAbstractLayerBuilder.Default.ReadFromRealFileSystem(basePath).WriteToRealFileSystem(basePath).Create(); var parameter = new MarkdownServiceParameters { BasePath = basePath, Extensions = new Dictionary <string, object> { { "EnableSourceInfo", true } } }; var markupService = new MarkdigMarkdownService(parameter); return(markupService.Markup(markdown, filePath ?? "topic.md").Html); }
public bool CompareMarkupResult(string markdown, string file = "topic.md") { try { var dfmHtml = _dfmEngine.Markup(markdown, file); var markdigHtml = _service.Markup(markdown, file).Html; var compareTool = new HtmlDiffTool(dfmHtml, markdigHtml, true); return(compareTool.Compare()); } catch (Exception) { // TODO return(false); } }
public void TestDfmNote_NoteWithLocalization() { var source = @"# Note not in one line > [!NOTE] > hello > world > [!WARNING] > Hello world this is also warning"; var expected = @"<h1 id=""note-not-in-one-line"">Note not in one line</h1> <div class=""NOTE""> <h5>注意</h5> <p>hello world</p> </div> <div class=""WARNING""> <h5>警告</h5> <p>Hello world this is also warning</p> </div> "; var parameter = new MarkdownServiceParameters { BasePath = ".", Tokens = new Dictionary <string, string> { { "note", "<h5>注意</h5>" }, { "warning", "<h5>警告</h5>" } }.ToImmutableDictionary(), Extensions = new Dictionary <string, object> { { LineNumberExtension.EnableSourceInfo, false } } }; var service = new MarkdigMarkdownService(parameter); var marked = service.Markup(source, "Topic.md"); Assert.Equal(expected.Replace("\r\n", "\n"), marked.Html); }
public void TestSectionBlockLevel(string source) { var parameter = new MarkdownServiceParameters { BasePath = "." }; var service = new MarkdigMarkdownService(parameter); var content = service.Markup(source, "Topic.md"); // assert XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(content.Html); var tabbedCodeNode = xdoc.SelectSingleNode("//div[@class='tabbedCodeSnippets' and @data-resources='OutlookServices.Calendar']"); Assert.True(tabbedCodeNode != null); var csNode = tabbedCodeNode.SelectSingleNode("./pre/code[@class='lang-cs-i']"); Assert.True(csNode != null); var jsNode = tabbedCodeNode.SelectSingleNode("./pre/code[@class='lang-javascript-i']"); Assert.True(jsNode != null); }
public void TestFallback_InclusionWithCodeFences() { // -root_folder (this is also docset folder) // |- root.md // |- a_folder // |- a.md // |- code_folder // |- sample1.cs // -fallback_folder // |- a_folder // |- code_in_a.cs // |- code_folder // |- sample2.cs // 1. Prepare data var root = @"markdown root.md main content start. mardown a content in root.md content start [!include[a](a_folder/a.md ""This is a.md"")] mardown a content in root.md content end sample 1 code in root.md content start [!CODE-cs[this is sample 1 code](code_folder/sample1.cs)] sample 1 code in root.md content end sample 2 code in root.md content start [!CODE-cs[this is sample 2 code](code_folder/sample2.cs)] sample 2 code in root.md content end markdown root.md main content end."; var a = @"markdown a.md main content start. code_in_a code in a.md content start [!CODE-cs[this is code_in_a code](code_in_a.cs)] code_in_a in a.md content end markdown a.md a.md content end."; var code_in_a = @"namespace code_in_a{}"; var sample1 = @"namespace sample1{}"; var sample2 = @"namespace sample2{}"; var uniqueFolderName = Path.GetRandomFileName(); TestUtility.WriteToFile($"{uniqueFolderName}/root_folder/root.md", root); TestUtility.WriteToFile($"{uniqueFolderName}/root_folder/a_folder/a.md", a); TestUtility.WriteToFile($"{uniqueFolderName}/root_folder/code_folder/sample1.cs", sample1); TestUtility.WriteToFile($"{uniqueFolderName}/fallback_folder/a_folder/code_in_a.cs", code_in_a); TestUtility.WriteToFile($"{uniqueFolderName}/fallback_folder/code_folder/sample2.cs", sample2); var fallbackFolders = new List <string> { { Path.Combine(Directory.GetCurrentDirectory(), $"{uniqueFolderName}/fallback_folder") } }; // Verify root.md markup result var parameter = new MarkdownServiceParameters { BasePath = "." }; var service = new MarkdigMarkdownService(parameter); //var rootMarked = service.Markup(Path.Combine(Directory.GetCurrentDirectory(), $"{uniqueFolderName}/root_folder"), root, fallbackFolders, "root.md"); var rootMarked = service.Markup("place", "holder"); var rootDependency = rootMarked.Dependency; Assert.Equal(@"<p>markdown root.md main content start.</p> <p>mardown a content in root.md content start</p> <p>markdown a.md main content start.</p> <p>code_in_a code in a.md content start</p> <pre><code class=""lang-cs"" name=""this is code_in_a code"">namespace code_in_a{} </code></pre><p>code_in_a in a.md content end</p> <p>markdown a.md a.md content end.</p> <p>mardown a content in root.md content end</p> <p>sample 1 code in root.md content start</p> <pre><code class=""lang-cs"" name=""this is sample 1 code"">namespace sample1{} </code></pre><p>sample 1 code in root.md content end</p> <p>sample 2 code in root.md content start</p> <pre><code class=""lang-cs"" name=""this is sample 2 code"">namespace sample2{} </code></pre><p>sample 2 code in root.md content end</p> <p>markdown root.md main content end.</p> ".Replace("\r\n", "\n"), rootMarked.Html); Assert.Equal( new[] { "../fallback_folder/a_folder/code_in_a.cs", "../fallback_folder/code_folder/sample2.cs", "a_folder/a.md", "a_folder/code_in_a.cs", "code_folder/sample1.cs", "code_folder/sample2.cs" }, rootDependency.OrderBy(x => x).ToArray()); // Verify a.md markup result //var aMarked = service.Markup(Path.Combine(Directory.GetCurrentDirectory(), $"{uniqueFolderName}/root_folder"), a, fallbackFolders, "a_folder/a.md"); var aMarked = service.Markup("place", "holder"); var aDependency = aMarked.Dependency; Assert.Equal(@"<p>markdown a.md main content start.</p> <p>code_in_a code in a.md content start</p> <pre><code class=""lang-cs"" name=""this is code_in_a code"">namespace code_in_a{} </code></pre><p>code_in_a in a.md content end</p> <p>markdown a.md a.md content end.</p> ".Replace("\r\n", "\n"), aMarked.Html); Assert.Equal( new[] { "../../fallback_folder/a_folder/code_in_a.cs", "code_in_a.cs" }, aDependency.OrderBy(x => x).ToArray()); }
public void TestFallback_Inclusion_random_name() { // -root_folder (this is also docset folder) // |- root.md // |- a_folder // | |- a.md // |- token_folder // | |- token1.md // -fallback_folder // |- token_folder // |- token2.md // 1. Prepare data var uniqueFolderName = Path.GetRandomFileName(); var root = $@"1markdown root.md main content start. [!include[a](a_folder_{uniqueFolderName}/a_{uniqueFolderName}.md ""This is a.md"")] markdown root.md main content end."; var a = $@"1markdown a.md main content start. [!include[token1](../token_folder_{uniqueFolderName}/token1_{uniqueFolderName}.md ""This is token1.md"")] [!include[token1](../token_folder_{uniqueFolderName}/token2_{uniqueFolderName}.md ""This is token2.md"")] markdown a.md main content end."; var token1 = $@"1markdown token1.md content start. [!include[token2](token2_{uniqueFolderName}.md ""This is token2.md"")] markdown token1.md content end."; var token2 = @"**1markdown token2.md main content**"; TestUtility.WriteToFile($"{uniqueFolderName}/root_folder_{uniqueFolderName}/root_{uniqueFolderName}.md", root); TestUtility.WriteToFile($"{uniqueFolderName}/root_folder_{uniqueFolderName}/a_folder_{uniqueFolderName}/a_{uniqueFolderName}.md", a); TestUtility.WriteToFile($"{uniqueFolderName}/root_folder_{uniqueFolderName}/token_folder_{uniqueFolderName}/token1_{uniqueFolderName}.md", token1); TestUtility.WriteToFile($"{uniqueFolderName}/fallback_folder_{uniqueFolderName}/token_folder_{uniqueFolderName}/token2_{uniqueFolderName}.md", token2); var fallbackFolders = new List <string> { { Path.Combine(Directory.GetCurrentDirectory(), $"{uniqueFolderName}/fallback_folder_{uniqueFolderName}") } }; var parameter = new MarkdownServiceParameters { BasePath = "." }; var service = new MarkdigMarkdownService(parameter); //var marked = service.Markup(Path.Combine(Directory.GetCurrentDirectory(), $"{uniqueFolderName}/root_folder_{uniqueFolderName}"), root, fallbackFolders, $"root_{uniqueFolderName}.md"); var marked = service.Markup("place", "holder"); var dependency = marked.Dependency; Assert.Equal(@"<p>1markdown root.md main content start.</p> <p>1markdown a.md main content start.</p> <p>1markdown token1.md content start.</p> <p><strong>1markdown token2.md main content</strong></p> <p>markdown token1.md content end.</p> <p><strong>1markdown token2.md main content</strong></p> <p>markdown a.md main content end.</p> <p>markdown root.md main content end.</p> ".Replace("\r\n", "\n"), marked.Html); Assert.Equal( new[] { $"../fallback_folder_{uniqueFolderName}/token_folder_{uniqueFolderName}/token2_{uniqueFolderName}.md", $"a_folder_{uniqueFolderName}/a_{uniqueFolderName}.md", $"token_folder_{uniqueFolderName}/token1_{uniqueFolderName}.md", $"token_folder_{uniqueFolderName}/token2_{uniqueFolderName}.md" }, dependency.OrderBy(x => x).ToArray()); }