This is an extension for Markdig that allows C# scripting to generate markdown or HTML content.
Instantiate Markdig.Extensions.ScriptCs into the scripting runtime:
```ScriptCs
#r Markdig.Extensions.ScriptCs.dll
using Markdig.Extensions.ScriptCs;
```
This only needs to be done once in your document. This gives access to MarkdownDocument.Instance
.
This is some `ScriptCs MarkdownDocument.Instance.InsertMarkdown("_italic_");` text.
This is some italic text.
This is some `ScriptCs MarkdownDocument.Instance.InsertHtml("<em>italic</em>");` text.
This is some italic text.
```ScriptCs
MarkdownDocument.Instance.InsertMarkdown("Hello World!");
```
Hello World!
```ScriptCs
MarkdownDocument.Instance.InsertHtml("<p>Hello World!</p>");
```
Hello World!
```ScriptCs
#r OxyPlot.dll
#r System.Runtime.dll
using OxyPlot;
using OxyPlot.Series;
var myModel = new PlotModel { Title = "Example 1" };
myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
var exporter = new SvgExporter { Width = 800, Height = 400 };
MarkdownDocument.Instance.InsertHtml(exporter.ExportToString(myModel));
```
It is possible to separate large amounts of code into csx
files which can be referenced in the markdown. The csx
file must be located in the bin directory.
```ScriptCs
#load OxyPlot.csx
RenderChart();
```
#r OxyPlot.dll
#r System.Runtime.dll
using OxyPlot;
using OxyPlot.Series;
public void RenderChart()
{
var myModel = new PlotModel { Title = "Example 1" };
myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
var exporter = new SvgExporter { Width = 800, Height = 400 };
MarkdownDocument.Instance.InsertHtml(exporter.ExportToString(myModel));
}
```ScriptCs
var fakeModel = new FakeModel { Title = "Test" };
```
ScriptCs exception:
(1,21): error CS0246: The type or namespace name 'FakeModel' could not be found (are you missing a using directive or an assembly reference?)
This PDF was generated by the Chrome print dialog from the HTML generated by Markdig using input.md as the source. It coincidentally shows the use of CSS to get page breaks in the PDF output. https://github.com/macaba/Markdig.Extensions.ScriptCs/blob/master/Markdig.Extensions.ScriptCs.ConsoleApp/Example%20output/output.pdf