This is a forked version of the Markdig.Prism library, an extension that adds syntax highlighting to a Markdig pipeline through Prism.js JavaScript library.
This forked version includes additional features such as a download button for code blocks. Please note that some of these features require additional JavaScript to function correctly.
- Add this forked version of
Markdig.Prism
to your project.
dotnet add package WebStoating.Markdig.PrismWithPlugins --version 1.0.0
- Create Markdig pipeline
private static readonly MarkdownPipeline MarkdownPipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UsePrism()
.Build();
- Download Prism and add it to your Razor page or layout template. Make sure to include the additional JavaScript required for the plugins.
<!DOCTYPE html>
<html>
<head>
...
<link href="themes/prism.css" rel="stylesheet" />
</head>
<body>
...
<script src="prism.js"></script>
<!--This would be where to put the aditiional javascript if needed for the plugin you need-->
<script src="yourAdditionalScript.js"></script>
</body>
</html>
- Convert Markdown to HTML
var html = Markdown.ToHtml(markdown, MarkdownPipeline);
You can configure the extension by passing a PrismExtensionOptions
object to the UsePrism
method.
private static readonly MarkdownPipeline MarkdownPipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UsePrism(new PrismExtensionOptions
{
UseDownloadButton = true,
UseLineNumbers = true,
})
.Build();
It will default to the following options:
new PrismExtensionOptions
{
UseDownloadButton = false,
UseLineNumbers = false,
}
Supported | Plugin Name | Usage Guide |
---|---|---|
❌ | Line Highlight | Guide |
✅ | Line Numbers | Guide |
❌ | Show Invisibles | Guide |
❌ | Autolinker | Guide |
❌ | WebPlatform Docs | Guide |
❌ | Custom Class | Guide |
❌ | File Highlight | Guide |
❌ | Show Language | Guide |
❌ | JSONP Highlight | Guide |
❌ | Highlight Keywords | Guide |
❌ | Remove initial line feed | Guide |
❌ | Inline color | Guide |
❌ | Previewers | Guide |
❌ | Autoloader | Guide |
❌ | Keep Markup | Guide |
❌ | Command Line | Guide |
❌ | Unescaped Markup | Guide |
❌ | Normalize Whitespace | Guide |
❌ | Data-URI Highlight | Guide |
✅ | Toolbar | Guide |
✅ | Copy to Clipboard Button | Guide |
✅ | Download Button | Guide |
❌ | Match braces | Guide |
❌ | Diff Highlight | Guide |
❌ | Filter highlightAll | Guide |
❌ | Treeview | Guide |
This library is a fork of Markdig.Prism by Ilya Verbitskiy. All credit for the original work goes to them.