Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/arthurrump/MarkdigExtensions
- Owner: arthurrump
- License: bsd-2-clause
- Created: 2019-04-27T19:35:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-24T21:18:57.000Z (almost 5 years ago)
- Last Synced: 2024-07-29T10:46:54.243Z (3 months ago)
- Topics: markdig, markdown
- Language: F#
- Homepage:
- Size: 43 KB
- Stars: 17
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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: `
`## 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
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
```- `onlyWithTitle = true`
```html
```## 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();
```