Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arthurrump/MarkdigExtensions

Some useful extensions to the Markdig Markdown processor
https://github.com/arthurrump/MarkdigExtensions

markdig markdown

Last synced: 3 months ago
JSON representation

Some useful extensions to the Markdig Markdown processor

Awesome Lists containing this project

README

        

# MarkdigExtensions

[![Build Status](https://dev.azure.com/arthurrump/MarkdigExtensions/_apis/build/status/CI?branchName=master)](https://dev.azure.com/arthurrump/MarkdigExtensions/_build/latest?definitionId=15&branchName=master)

Some useful extensions to the [Markdig](https://github.com/lunet-io/markdig) Markdown processor.

## MarkdigExtensions.UrlRewriter

[![NuGet](https://img.shields.io/nuget/v/MarkdigExtensions.UrlRewriter.svg)](https://www.nuget.org/packages/MarkdigExtensions.UrlRewriter/)

Allows you to rewrite URLs in link and image tags. It's reason for existence was the need to convert local image paths to a path on the webserver, but it's flexible enough to rewrite any link or image URL.

### Example

```csharp
using Markdig;

var pipeline = new MarkdownPipelineBuilder()
.UseUrlRewriter(link => link.Url.Replace("http://", "https://"))
.Build();

var markdown = "[Anchor](http://example.net), ![Image](http://example.com/img.png)";
var html = Markdown.ToHtml(markdown, pipeline);
```

Result: `

Anchor, Image

`

## MarkdigExtensions.ImageAsFigure

[![NuGet](https://img.shields.io/nuget/v/MarkdigExtensions.ImageAsFigure.svg)](https://www.nuget.org/packages/MarkdigExtensions.ImageAsFigure/)

Wraps all images inside a `` element with a `` set to the title of the image. You can choose to only wrap images where a title is set by providing the `onlyWithTitle` argument set to `true`.

### Example

```csharp
using Markdig;

var pipeline = new MarkdownPipelineBuilder()
.UseImageAsFigure()
.Build();

var markdown = "![Alt-text](https://example.com/img.png \"Image title text\")";
var html = Markdown.ToHtml(markdown, pipeline);
```

This will result in the following HTML:

```html



Alt-text
Image title text


```

You can choose to only surround an image where a title is provided with a `` tag by using `.UseImageAsFigure(onlyWithTitle: true)`. Here's the output for `![Alt-text](https://example.com/img.png)` with both values:

- `onlyWithTitle = false` (default)

```html

Alt-text

```

- `onlyWithTitle = true`

```html
Alt-text
```

## MarkdigExtensions.SyntaxHighlighting

[![NuGet](https://img.shields.io/nuget/v/MarkdigExtensions.SyntaxHighlighting.svg)](https://www.nuget.org/packages/MarkdigExtensions.SyntaxHighlighting/)

Uses [ColorCode-Universal](https://github.com/WilliamABradley/ColorCode-Universal) to add syntax highlighting to fenced code blocks. Check out their [LanguageId.cs](https://github.com/WilliamABradley/ColorCode-Universal/blob/master/ColorCode.Core/Common/LanguageId.cs) file to get a list of all supported languages, code blocks with an unsupported language or no language specified will be rendered using the standard renderer.

### Example

```csharp
using Markdig;

var pipeline = new MarkdownPipelineBuilder()
.UseSyntaxHighlighting()
.Build();

var markdown = "```f# \nprintfn \"Hello, %s!\" \"world\" \n``` \n";
var html = Markdown.ToHtml(markdown, pipeline);
```

Instead of a normal code block, this will render a code block with inline CSS to add the colorization:

```html


printfn "Hello, %s!" "world"

```

You can specify a custom color scheme by providing a `StyleDictionary`:

```csharp
using Markdig;
using ColorCode.Styling;

var pipeline = new MarkdownPipelineBuilder()
.UseSyntaxHighlighting(StyleDictionary.DefaultDark)
.Build();
```