Git Product home page Git Product logo

mudblazor.markdown's Introduction

Version Nuget downloads

Markdown component for MudBlazor

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

Update guide

For guidance with update errors please visit the wiki page.

Getting started

Install the NuGet package.

dotnet add package MudBlazor.Markdown

Add the following using statement in _Imports.razor.

@using MudBlazor

Add the following nodes in either App.razor or MainLayout.razor.

<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />

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

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<link href="_content/MudBlazor.Markdown/MudBlazor.Markdown.min.css" rel="stylesheet" />

At the bottom of the <body> node add this JS source.

<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="_content/MudBlazor.Markdown/MudBlazor.Markdown.min.js"></script>

Register MudBlazor services in the DI container.
For the Blazor Server in the Startup.cs add this method.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMudServices();
    services.AddMudMarkdownServices();
    // Optionally if default clipboard functionality fails it is possible to add a custom service
    // NB! MauiClipboardService is just an example
    builder.Services.AddMudMarkdownClipboardService<MauiClipboardService>();
}

For the Blazor WebAssembly in the Program.cs add this method.

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddMudServices();
builder.Services.AddMudMarkdownServices();
// Optionally if default clipboard functionality fails it is possible to add a custom service
// NB! MauiClipboardService is just an example
builder.Services.AddMudMarkdownClipboardService<MauiClipboardService>();

Using the component

<MudText Typo="Typo.h3">My markdown</MudText>
<MudMarkdown Value="@Value" />

@code
{
    private string Value { get; } = "text *italics* and **bold**";
}

Available properties

  • Value - string value of the markdown text;
  • LinkCommand - <MudLink> components will not navigate to the provided URL, but instead invoke the command. If the property is null then <MudLink> will navigate to the link automatically (behaviour of <a>);
  • 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 <h1>, <h2>, 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:

The <MudMarkdown> supports the palette of the MudTheme which makes styling easy (we hope). These are the colors which are used in the <MudMarkdown>:

  • DrawerBackground - background-color of the quoted text;
  • OverlayDark - 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 - color of the quoted text;

mudblazor.markdown's People

Contributors

cabiste69 avatar dependabot[bot] avatar erri120 avatar lukazoid avatar mattparkerdev avatar mihailskuzmins avatar my-nihongo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mudblazor.markdown's Issues

Feature Request: Extensible rendering

Me, again.

It would also be useful to be able to extend this behavior:

case ParagraphBlock paragraph:
{
RenderParagraphBlock(paragraph, builder);
break;
}
case HeadingBlock heading:
{
var typo = (Typo)heading.Level;
typo = OverrideHeaderTypo?.Invoke(typo) ?? typo;
_enableLinkNavigation = true;
var id = heading.BuildIdString();
RenderParagraphBlock(heading, builder, typo, id);
break;
}
case QuoteBlock quote:
{
builder.OpenElement(_elementIndex++, "blockquote");
RenderMarkdown(quote, builder);
builder.CloseElement();
break;
}
case Table table:
{
RenderTable(table, builder);
break;
}
case ListBlock list:
{
RenderList(list, builder);
break;
}
case ThematicBreakBlock:
{
builder.OpenComponent<MudDivider>(_elementIndex++);
builder.CloseComponent();
break;
}
case FencedCodeBlock code:
{
var text = code.CreateCodeBlockText();
builder.OpenComponent<MudCodeHighlight>(_elementIndex++);
builder.AddAttribute(_elementIndex++, nameof(MudCodeHighlight.Text), text);
builder.AddAttribute(_elementIndex++, nameof(MudCodeHighlight.Language), code.Info ?? string.Empty);
builder.AddAttribute(_elementIndex++, nameof(MudCodeHighlight.Theme), CodeBlockTheme);
builder.CloseComponent();
break;
}
case HtmlBlock html:
{
if (html.TryGetDetails(out var detailsData))
RenderDetailsHtml(builder, detailsData);
else
RenderHtml(builder, html.Lines);
break;
}

So that one can provide rendering logic for custom blocks we introduce with custom pipelines. As always, I'd be happy to do the necessary refactoring along with any other changes required in a PR, if you prefer.

Broken Link in README in Palette Section

There is a broken link in the README in regards to how to use the pallette. I am having trouble with code blocks but im positive im doing something wrong but im just trying to learn

my project: https://github.com/alvaromon/BitbyBitBlog.git Sprint1 branch

Im running into an issue that my site Theme is overwriting the text color for fenced code blocks

example using CodeBlockTheme.DarkVioletBase16 where text is supposed to be light pink.
image
image

Code block copy to clipboard breaks on Android

I am using Mudblazor.Markdown in a .NET MAUI application intended to be used on Android, among other platforms. When running the app in an Android emulator (Pixel 5 - API 28), clicking the Copy button on a Markdown fenced code block generates the following error message in the console:

null
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
   at MudBlazor.MudCodeHighlight.CopyTextToClipboardAsync(MouseEventArgs args)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

From what I can tell, it appears the issue lies with the invocation of 'navigator.clipboard.writeText'. I attempted to invoke this function directly in my own code, and the same error occurred. When I run the app on Windows, everything works fine.

tested issue #114, still problems

Hi,
I tested the latest version of MudBlazor.Markdown 0.0.12 regarding issue #114 and the <details> tag.
There are still problems if you have a crlf between the lines in the content that you use :

<details>
  <summary markdown="span">Release 1.0.1</summary>

**New**
-  Error fixes.

</details>

This works OK:

<details>
  <summary markdown="span">Release 1.0.1</summary>
**New**
-  Error fixes.
</details>

In Visual Studio I use the extension Markdown Editor v2 to validate the markdown, example 1 render OK, example 2 does not.

I did have a look in the code, but couldnโ€™t figure out what to do.

Table not showing when indented

Table is not showing using if there is any indentation in the content, se example below:

## Prereq
The following requirements must be met outside this Terraform code in advance.

1. Created a new resource group..
2. Created a new AAD group using naming convention..
3. Created a new AAD group using naming convention..
4. Created a separate storage account..
5. Created a new app registration..
     
  |Permission | Type | Granted Through|
  |--|--|--|
  |User.Read | Delegated | Admin consent|
  | User.ReadBasic.All |Delegated| Admin consent|
  |User.Read.All|Delegated| Admin consent|
  |Directory.Read.Alll|Delegated| Admin consent|
  |Directory.AccessAsUser.All|Delegated| Admin consent|
  |User.Invite.All|Application| Admin consent|
  |Directory.Read.All|Application| Admin consent|
  |User.Read.All|Application| Admin consent|
  - Granted permissions User.Invite.All and GroupMember.ReadWrite.All. Admin consent has been granted
 
6. Create a new app registration..
7. Created the key vault..
8. Created secrets..

Style overrides

I noticed right away that tables were rendered with elevation and I can't really remove it. You may need to include additional delegates to override parameters on any mud components that you're using (e.g. tables) the same way you override typography styles. I'm not quite sure how it would look but maybe something where you take a delegate for the user to to implement, and you have your control pass in the instance of each table?

<MudMarkdown Value="@MyContent" OverrideTable="TransformTable" />

@code {
   MudTable TransformTable(MudTable tableInstance) {
    tableInstance.Elevation = 0; 
    return tableInstance;
   }
}

Render <details>

a <details> tag is not rendered correctly.
Example where the "Release 1.0.1" is not rendered:

Release 1.0.1 **New** - Error fixes.

Code markdown doesn't respect language tag

Markdown for code blocks with a language specified such as ```csharp doesn't highlight the code for the specified language, instead it is using the highlight.js language detection logic.

I believe this is due to the use of highlightElement:

hljs.highlightElement(element, { language: lang });

Which from the highlight.js docs doesn't take any options, instead the language should be specified in the class attribute of the DOM node (see https://highlightjs.readthedocs.io/en/latest/api.html#highlightelement)

Add BaseUrl option for relative links

GitHub readmes often contain relative links which GitHub converts to absolute Urls. eg:

![some image](assets/some_image.webp)

In the current version this will produce something like this:

<img src="assets/some_image.webp" alt="some image"/>

I suggset adding some sort of BaseUrl option for the component which will be combined with the relative Url before creating the image component. I would define relative Urls as links that do not start with #, https://, http:// or www but there might be other cases.

Nuget package includes package.json and package-lock.json files

As the title suggests the nuget package contains these files as seen in the nusepc file:

    <contentFiles>
      <files include="any/net5.0/package-lock.json" buildAction="Content" />
      <files include="any/net5.0/package.json" buildAction="Content" />
    </contentFiles>

I think you have to explicitly set these files to not be packed into the nuget package similar to how you did it with the favico:

<ItemGroup>
<None Include="..\..\favico.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

Code Markdown

Its possible to get support for code markdown? like

config: test
config2: test2

etc

Issue when code block is empty

First of all, I would like to thank you for the existence of this library. It made it effortless for me to integrate Markdown into my Blazor project. Thank you very much for your work ๐Ÿ˜€.

My issue:
I have been working on a ChatGPT-like UI in Blazor (MudBlazor). I experimented with the OpenAI API, which streams the responses to the client. In doing so, I noticed a problem. Whenever the AI streams the Markdown text for a code block, Blazor crashed with a strange exception: System.NotImplementedException: Unexpected frame type during RemoveOldFrame ๐Ÿคทโ€โ™‚๏ธ.

I quickly realized that it was due to empty code blocks. When the AI streams the Markdown text and there is code in the AI response, there is a temporary situation where an empty code block is created:

```

Then, a few milliseconds later, the Markdown code gets changed, e.g., into:

```
public

After some troubleshooting, I came to the conclusion that the issue lies in this library (okay, so actually the issue is in .NET, but here the situation can be easily avoided). Apparently, Blazor (at least in some places) has a problem with attributes being empty. I don't know what the underlying difficulty with this is exactly. It appears to be similar to dotnet/aspnetcore#17821.

The issue is straightforward to catch. See line 176 in MudMarkdown.razor.cs onwards:

var text = code.CreateCodeBlockText();

builder.OpenComponent<MudCodeHighlight>(ElementIndex++);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Text), text);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Language), code.Info ?? string.Empty);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Theme), CodeBlockTheme);
builder.CloseComponent();

The crash of Blazor occurs when text is empty. I have already created a PR #246.

Content after Code block is not rendered

Hello,

I found an issue with content not rendered after a code block.
The first element that happens to be after a code block will not be displayed with MudBlazor.Markdown. When inspecting the rendered HTML with Devtools the element is really not rendered to the website.

I use Blazor WASM 6.0.1, MudBlazor 6.0.5 and MudBlazor.Markdown 0.0.6.
I also first tried to repro this issue with Markdig 0.26.0 standalone to make sure it isn't a Markdig issue, but Markdig alone renders the samples correctly, so it seems to come from MudBlazor.Markdown itself.

Repro:

Given the following Markdown content:

# Heading 1
Some text.

```csharp
public int GetTheAnswer()
{
   return 42;
}
```

## Another headline <-- this element is NOT rendered with MudBlazor.Markdown
## Another headline <-- this element is shown again

It really doesn't matter what follows the code block. The whole next element will be ignored. In the following example the whole list with all three items is not rendered to the page and ignored:

```text
some
code
```

* List item 1
* List item 2
* List item 3

## Another headline <-- this element is shown again

Edit

Hi,
edit, sorry I miss understand.

After binding value changes, the code block fails to update the corresponding value even if call StateHasChanged

First, I would like to express my gratitude for providing such a great component.
Regarding the relative issue #166, it seems that the issuer had already provided an example code. However, the author used a different test code instead of the code-block to attempt to replicate the problem.
I have encountered the same problem when doing code-block re-rendering while other parts are OK.

Table shows if not indented but numbering is restarted

Table is showing using but numbering is restarted after. See code below:

## Prereq
The following requirements must be met outside this Terraform code in advance.

1. Created a new resource group..
2. Created a new AAD group using naming convention..
3. Created a new AAD group using naming convention..
4. Created a separate storage account..
5. Created a new app registration..
     
|Permission | Type | Granted Through|
|--|--|--|
|User.Read | Delegated | Admin consent|
| User.ReadBasic.All |Delegated| Admin consent|
|User.Read.All|Delegated| Admin consent|
|Directory.Read.Alll|Delegated| Admin consent|
|Directory.AccessAsUser.All|Delegated| Admin consent|
|User.Invite.All|Application| Admin consent|
|Directory.Read.All|Application| Admin consent|
|User.Read.All|Application| Admin consent|
- Granted permissions User.Invite.All and GroupMember.ReadWrite.All. Admin consent has been granted
 
6. Create a new app registration..
7. Created the key vault..
8. Created secrets..

new lines in tables

header1 header2
cell1
new line
cell2
|header1|header2|
|-|-|
|cell1<br>new line|cell2|

Now <br> or <br/> are ignored

Change the logo

Jonny said that saving the original logo caused some troubles. Let's adjust it. Maybe change the colour?

Rendering Math Expressions

I would like to include Math expressions like so:

When $a \ne 0$ , there are two solutions to $(ax^2 + bx + c = 0)$ and they are

$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$

this is supported in github markdown.

Can I make it work in MudMarkdown?

Nested text is not rendered correctly in list items

Ordered items (probably unordered as well) are not rendered correctly for nested text.

To prevent the warning message regarding the deprecation of the mysql_native_password plugin from being logged, you have a couple of options:

Option 1: Update User Authentication Method:

  1. Connect to your MySQL server using a MySQL client, such as the mysql command-line tool:

    mysql -u username -p
  2. Once connected, run the following command to alter the user's authentication method:

    ALTER USER 'username'@'hostname' IDENTIFIED WITH caching_sha2_password;

    Replace 'username' with the actual username and 'hostname' with the appropriate hostname or IP address. If you want to update for all users, replace 'username'@'hostname' with '*'@'%'.

  3. Repeat this process for each user on your MySQL server.

Compared to what is rendered on GitHub:
image

Probably this issue might be solved in #232, but maybe not, so keep this issue in case there is no progress on the afore cited PR.

Static resources missing in version 0.0.7

I've tryed using the latest version (0.0.7) and it seems that the static resources (CSS and JS) are missing from the NuGet package. From what I've seen, they are present in the project, but missing from package.

Add Src

Add a Src parameter.

Example

<MudMarkdown Src="wiki/getting_started.md" />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.