Skip to content

Syntax highlighting for Markdig using Prism.js library

License

Notifications You must be signed in to change notification settings

retrokiller543/Markdig.Prism

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markdig.Prism (Forked Version)

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.

Usage

  1. Add this forked version of Markdig.Prism to your project.
dotnet add package WebStoating.Markdig.PrismWithPlugins --version 1.0.0
  1. Create Markdig pipeline
private static readonly MarkdownPipeline MarkdownPipeline = new MarkdownPipelineBuilder()
    .UseAdvancedExtensions()
    .UsePrism()
    .Build();
  1. 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>
  1. Convert Markdown to HTML
var html = Markdown.ToHtml(markdown, MarkdownPipeline);

Configuration

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 Plugins

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

Credits

This library is a fork of Markdig.Prism by Ilya Verbitskiy. All credit for the original work goes to them.

About

Syntax highlighting for Markdig using Prism.js library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%