diff --git a/MLS.Agent.Tests/Markdown/MarkdownFileTests.cs b/MLS.Agent.Tests/Markdown/MarkdownFileTests.cs index db3631d68..a2ea9c7d2 100644 --- a/MLS.Agent.Tests/Markdown/MarkdownFileTests.cs +++ b/MLS.Agent.Tests/Markdown/MarkdownFileTests.cs @@ -279,6 +279,49 @@ static void MyProgram(string[] args) buttons.Should().BeNull(); } + [Fact] + public async Task Should_emit_math_inline_block_rendering() + { + var html = await RenderHtml( + ("Readme.md", @"this is math inline $$\sum ^{n}_{i=0}\left(x_{i}+a_{i}y_{i}\right)$$")); + + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(html); + + var math = htmlDocument.DocumentNode + .SelectSingleNode("//span"); + + math.HasClass("math").Should().BeTrue(); + math.InnerText.Should().Match(@"\(\sum ^{n}_{i=0}\left(x_{i}+a_{i}y_{i}\right)\)"); + } + + [Fact] + public async Task Should_emit_math_block_rendering() + { + var html = await RenderHtml( + ("Readme.md", @"$$ +\begin{equation} + \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} + \label{eq:sample} +\end{equation} +$$")); + + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(html); + + var math = htmlDocument.DocumentNode + .SelectSingleNode("//div"); + + math.HasClass("math").Should().BeTrue(); + math.InnerText.EnforceLF().Should().Match(@" +\[ +\begin{equation} + \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} + \label{eq:sample} +\end{equation} +\]".EnforceLF()); + } + [Fact] public async Task Should_emit_pre_style_for_hidden_blocks() { diff --git a/MLS.Agent/Controllers/DocumentationController.cs b/MLS.Agent/Controllers/DocumentationController.cs index 13979385d..1f2c58f3a 100644 --- a/MLS.Agent/Controllers/DocumentationController.cs +++ b/MLS.Agent/Controllers/DocumentationController.cs @@ -120,6 +120,7 @@ private IHtmlContent Layout(string hostUrl, MarkdownFile markdownFile, IHtmlCont + {MathSupport()} dotnet try - {markdownFile.Path.Value.HtmlEncode()} @@ -138,6 +139,17 @@ private IHtmlContent Layout(string hostUrl, MarkdownFile markdownFile, IHtmlCont ".ToHtmlContent(); + private IHtmlContent MathSupport() => + @" + + ".ToHtmlContent(); + private async Task OneColumnLayoutScaffold(string hostUrl, MarkdownFile markdownFile) => Layout(hostUrl, markdownFile, $@" diff --git a/MLS.Agent/MLS.Agent.csproj b/MLS.Agent/MLS.Agent.csproj index c7a0e019e..0739c58b6 100644 --- a/MLS.Agent/MLS.Agent.csproj +++ b/MLS.Agent/MLS.Agent.csproj @@ -56,7 +56,7 @@ all runtime; build; native; contentfiles; analyzers - + diff --git a/MLS.Agent/Markdown/MarkdownProject.cs b/MLS.Agent/Markdown/MarkdownProject.cs index 58a6e33df..8b9cfedd7 100644 --- a/MLS.Agent/Markdown/MarkdownProject.cs +++ b/MLS.Agent/Markdown/MarkdownProject.cs @@ -8,6 +8,7 @@ using System.Reactive.Disposables; using System.Threading.Tasks; using Markdig; +using Markdig.Extensions.Mathematics; using Microsoft.DotNet.Try.Markdown; using Recipes; using WorkspaceServer; @@ -71,7 +72,7 @@ public void WriteAllText(RelativeFilePath path, string text) { } } - + internal IDirectoryAccessor DirectoryAccessor { get; } private readonly PackageRegistry _packageRegistry; @@ -85,7 +86,7 @@ internal MarkdownProject(PackageRegistry packageRegistry) : this(new NullDirecto } public MarkdownProject( - IDirectoryAccessor directoryAccessor, + IDirectoryAccessor directoryAccessor, PackageRegistry packageRegistry, IDefaultCodeBlockAnnotations defaultAnnotations = null) { @@ -118,11 +119,12 @@ internal MarkdownPipeline GetMarkdownPipelineFor(RelativeFilePath filePath) var relativeAccessor = DirectoryAccessor.GetDirectoryAccessorForRelativePath(filePath.Directory); return new MarkdownPipelineBuilder() - .UseAdvancedExtensions() .UseCodeBlockAnnotations( - relativeAccessor, - _packageRegistry, + relativeAccessor, + _packageRegistry, defaultAnnotations) + .UseMathematics() + .UseAdvancedExtensions() .Build(); }); } diff --git a/Microsoft.DotNet.Try.Markdown.Tests/Microsoft.DotNet.Try.Markdown.Tests.csproj b/Microsoft.DotNet.Try.Markdown.Tests/Microsoft.DotNet.Try.Markdown.Tests.csproj index e1f0dc840..71cc15506 100644 --- a/Microsoft.DotNet.Try.Markdown.Tests/Microsoft.DotNet.Try.Markdown.Tests.csproj +++ b/Microsoft.DotNet.Try.Markdown.Tests/Microsoft.DotNet.Try.Markdown.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/Microsoft.DotNet.Try.Markdown/AnnotatedCodeBlockParser.cs b/Microsoft.DotNet.Try.Markdown/AnnotatedCodeBlockParser.cs index 31bed68a3..6acbf3b98 100644 --- a/Microsoft.DotNet.Try.Markdown/AnnotatedCodeBlockParser.cs +++ b/Microsoft.DotNet.Try.Markdown/AnnotatedCodeBlockParser.cs @@ -23,10 +23,7 @@ public AnnotatedCodeBlockParser(CodeFenceAnnotationsParser codeFenceAnnotationsP protected override AnnotatedCodeBlock CreateFencedBlock(BlockProcessor processor) => new AnnotatedCodeBlock(this, _order++); - protected bool ParseCodeOptions( - BlockProcessor state, - ref StringSlice line, - IFencedBlock fenced) + protected bool ParseCodeOptions(BlockProcessor state, ref StringSlice line, IFencedBlock fenced, char openingCharacter) { if (!(fenced is AnnotatedCodeBlock codeLinkBlock)) { diff --git a/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj b/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj index 55c42af0a..4c7ba20a9 100644 --- a/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj +++ b/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj @@ -12,7 +12,7 @@ - + diff --git a/docs/Learn math.md b/docs/Learn math.md new file mode 100644 index 000000000..8ae9123e0 --- /dev/null +++ b/docs/Learn math.md @@ -0,0 +1,15 @@ +# dotnet try + +Learn math with .NET. + +Given the following equation + +$$ +\sum ^{20}_{i=0}\left(x_{i}+a_{i}y_{i}\right) +$$ + +create an implementation using real code + + +```csharp --source-file ./samples/BasicConsole/Program.cs --project ./samples/BasicConsole/BasicConsole.csproj --region wat --session "say meow..." +``` \ No newline at end of file