Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
EngincanV committed Jan 5, 2023
1 parent 50c6efd commit 774cec8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

This package can be used for code line highlighting. It uses [Prism](https://prismjs.com/) for highlighting.

## Installation
## Installation & Configuration

You can use the following CLI command to add the package into your project:
1. Install the package:

```bash
dotnet add package Markdig.Extensions.LineHighlight
```

## Configurations
2. Download prism.js for code-highlighting support and put it into your libs folder:

First, download the prism.js for code-highligthing and put it into your libs folder.

> You can install from: https://prismjs.com/download.html
> You can install it from: https://prismjs.com/download.html
Then, add prism.cs and prism.js files to your layout.

Expand All @@ -34,7 +32,7 @@ Then, add prism.cs and prism.js files to your layout.

## Usage

Let's assume you have a markdown content as below:
Let's assume you have markdown content and want to highlight the 3rd line. You can do this as below (just specify `{line-number}` next to the language):

```html
```csharp {3}
Expand All @@ -48,17 +46,21 @@ Let's assume you have a markdown content as below:
\```
```

To render this markdown as HTML, you can use the `Markdown.ToHtml` method. To get benefit of code highlighting use `UseHighlightedCodeBlocks` method as below:
To render this markdown as HTML, you can use `Markdown.ToHtml` method. This method basically gets two parameters: the first one is the markdown content and the second one is a pipeline, which can be considered custom steps that we want to apply while rendering the content as HTML.

You need to add [HighlightedCodeBlockExtension](https://github.com/EngincanV/Markdig.Extensions.LineHighlight/blob/main/src/Markdig.Extensions.LineHighlight/Markdown/Extensions/HighlightedCodeBlockExtension.cs#L8) to this pipeline to the benefit of code-highlighting. For this purpose, you can use the `UseHighlightedCodeBlocks` method while building the pipeline and passing it through the `Markdown.ToHtml` method as below:

```csharp
var pipeline = new MarkdownPipelineBuilder()
.UseHighlightedCodeBlocks() //use highlighted code blocks
.Build();
var result = Markdown.ToHtml(text.ToString(), pipeline);
.UseHighlightedCodeBlocks() //use highlighted code blocks
.Build();
var result = Markdown.ToHtml(text.ToString(), pipeline);
```

Then the example output will be as follows:
Then, if you added the prism.js into your layout as mentioned above, you should see an output as follows:

![](assets/output.png)

> If you encounter a problem, you can examine [the sample application](demo/LineHighlightDemo/) in this repo anytime.
## Samples

This repository contains one sample application named `LineHighlightDemo`, which you can see [under the demo folder](demo/LineHighlightDemo/). If you encounter a problem, you can check this sample application.

0 comments on commit 774cec8

Please sign in to comment.