Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/MyNihongo/MudBlazor.Markdown

Markdown component based on the MudBlazor environment
https://github.com/MyNihongo/MudBlazor.Markdown

blazor blazor-client blazor-components blazor-server blazor-webassembly markdown material mudblazor netcore wasm

Last synced: 4 days ago
JSON representation

Markdown component based on the MudBlazor environment

Awesome Lists containing this project

README

        

[![Version](https://img.shields.io/nuget/v/MudBlazor.Markdown?style=plastic)](https://www.nuget.org/packages/MudBlazor.Markdown/)
[![Nuget downloads](https://img.shields.io/nuget/dt/MudBlazor.Markdown?label=nuget%20downloads&logo=nuget&style=plastic)](https://www.nuget.org/packages/MudBlazor.Markdown/)
# Markdown component for [MudBlazor](https://github.com/MudBlazor/MudBlazor)

This README covers configuration steps for Blazor Server and Blazor WebAssembly. For images of how the markup component looks like in the browser go to the [README of samples](/samples).

## Update guide
For guidance with update errors please visit the [wiki page](https://github.com/MyNihongo/MudBlazor.Markdown/wiki/Update-guide).

## Getting started
> NB! MudBLazor does not work well with the static SSR format because some code is executed in `OnAfterRender` or `OnAfterRenderAsync` that is not invoked by default.
> Specify `@rendermode="InteractiveServer"` on the markdown component to make it work (e.g. ``)

Install the NuGet package.
```
dotnet add package MudBlazor.Markdown
```
Add the following using statement in `_Imports.razor`.
```razor
@using MudBlazor
```
Add the following nodes in either `App.razor` or `MainLayout.razor`.
```razor

```
Add the following nodes in `Pages/_Host.cstml` (Server) or `wwwroot/index.html` (WebAssembly).
In the `` node add these CSS stylesheets.
```html

```
At the bottom of the `` node add this JS source.
```html

```
Register MudBlazor services in the DI container.
For the Blazor Server in the `Startup.cs` add this method.
```cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMudServices();
services.AddMudMarkdownServices();
// Optionally if the default clipboard functionality fails it is possible to add a custom service
// NB! MauiClipboardService is just an example
services.AddMudMarkdownClipboardService();
}
```
For the Blazor WebAssembly in the `Program.cs` add this method.
```cs
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddMudServices();
builder.Services.AddMudMarkdownServices();
// Optionally if the default clipboard functionality fails it is possible to add a custom service
// NB! MauiClipboardService is just an example
builder.Services.AddMudMarkdownClipboardService();
```
## Using the component
```razor
My markdown

@code
{
private string Value { get; } = "text *italics* and **bold**";
}
```
### Available properties
- `Value` - string value of the markdown text;
- `LinkCommand` - `` components will not navigate to the provided URL, but instead invoke the command. If the property is `null` then `` will navigate to the link automatically (behaviour of ``);
- `TableCellMinWidth` - minimum width (in pixels) for a table cell. If the property is `null` or negative the min width is not applied;
- `OverrideHeaderTypo` - override a Typo parameter for tags `

`, `

`, etc.;
- `OverrideLinkUrl` - override a URL address for links;
- `CodeBlockTheme` - default theme for code blocks;
- `Styling` - override default styling.
### Palette (colour) configurations
Useful links for configuring the palette:
- [Default theme](https://mudblazor.com/customization/default-theme#mudtheme) - all CSS variables and their default values
- [Overview](https://mudblazor.com/customization/overview#theme-provider) - how the theme can be configured

The `` supports the palette of the `MudTheme` which makes styling easy (we hope). These are the colors which are used in the ``:
- DrawerBackground - background-color of the quoted text;
- ChipDefault - background-color of the code block;
- TextDisabled - border-color of the quoted text and border-color of the h1 and h2 bottom divider;
- TextPrimary - regular text in the markdown;
- TextSecondary - the colour of the quoted text;