Skip to content

Commit 01e5c70

Browse files
Files are added
0 parents  commit 01e5c70

35 files changed

+1502
-0
lines changed

App.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>

BlazorMarkdig.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Markdig" Version="0.22.0" />
9+
<PackageReference Include="Syncfusion.Blazor" Version="18.3.0.44" />
10+
</ItemGroup>
11+
12+
</Project>

BlazorMarkdig.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30516.212
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorMarkdig", "BlazorMarkdig.csproj", "{07C4FFA6-EF3B-4681-BE8F-F7B5F1F75758}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{07C4FFA6-EF3B-4681-BE8F-F7B5F1F75758}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{07C4FFA6-EF3B-4681-BE8F-F7B5F1F75758}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{07C4FFA6-EF3B-4681-BE8F-F7B5F1F75758}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{07C4FFA6-EF3B-4681-BE8F-F7B5F1F75758}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {11AC6ADA-1CCA-48C1-9710-D51F6E9A9F3E}
24+
EndGlobalSection
25+
EndGlobal

Data/WeatherForecast.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace BlazorMarkdig.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}

Data/WeatherForecastService.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace BlazorMarkdig.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}

Pages/Counter.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}

Pages/Error.cshtml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model BlazorMarkdig.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html>
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/app.css" rel="stylesheet" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>

Pages/Error.cshtml.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace BlazorMarkdig.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
[IgnoreAntiforgeryToken]
14+
public class ErrorModel : PageModel
15+
{
16+
public string RequestId { get; set; }
17+
18+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
19+
20+
private readonly ILogger<ErrorModel> _logger;
21+
22+
public ErrorModel(ILogger<ErrorModel> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
public void OnGet()
28+
{
29+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
30+
}
31+
}
32+
}

Pages/FetchData.razor

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/fetchdata"
2+
3+
@using BlazorMarkdig.Data
4+
@inject WeatherForecastService ForecastService
5+
6+
<h1>Weather forecast</h1>
7+
8+
<p>This component demonstrates fetching data from a service.</p>
9+
10+
@if (forecasts == null)
11+
{
12+
<p><em>Loading...</em></p>
13+
}
14+
else
15+
{
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>Date</th>
20+
<th>Temp. (C)</th>
21+
<th>Temp. (F)</th>
22+
<th>Summary</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
@foreach (var forecast in forecasts)
27+
{
28+
<tr>
29+
<td>@forecast.Date.ToShortDateString()</td>
30+
<td>@forecast.TemperatureC</td>
31+
<td>@forecast.TemperatureF</td>
32+
<td>@forecast.Summary</td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
private WeatherForecast[] forecasts;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
45+
}
46+
}

Pages/Index.razor

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
@page "/"
2+
3+
@using Syncfusion.Blazor.RichTextEditor;
4+
@using Markdig;
5+
6+
<div class="control-section">
7+
<div class="e-rte-preview" style="height:500px;">
8+
<div class="container">
9+
<div class="row">
10+
<div class="col" style="height:500px;width:400px;">
11+
<SfRichTextEditor SaveInterval="1" EditorMode="EditorMode.Markdown" Height="100%" @bind-Value="@mdValue">
12+
<RichTextEditorEvents ValueChange="onValueChange"></RichTextEditorEvents>
13+
<RichTextEditorToolbarSettings Items="@tools" Type="ToolbarType.MultiRow"></RichTextEditorToolbarSettings>
14+
</SfRichTextEditor>
15+
</div>
16+
<div class="col" style="height:500px;width:400px">
17+
<SfRichTextEditor Readonly="true" Height="100%" @bind-Value="@htmlValue">
18+
<RichTextEditorToolbarSettings Enable="false"></RichTextEditorToolbarSettings>
19+
</SfRichTextEditor>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
@code {
26+
private List<ToolbarItemModel> tools = new List<ToolbarItemModel>()
27+
{
28+
new ToolbarItemModel() { Command = ToolbarCommand.Bold },
29+
new ToolbarItemModel() { Command = ToolbarCommand.Italic },
30+
new ToolbarItemModel() { Command = ToolbarCommand.StrikeThrough },
31+
new ToolbarItemModel() { Command = ToolbarCommand.SubScript },
32+
new ToolbarItemModel() { Command = ToolbarCommand.SuperScript },
33+
new ToolbarItemModel() { Command = ToolbarCommand.Separator },
34+
new ToolbarItemModel() { Command = ToolbarCommand.Formats },
35+
new ToolbarItemModel() { Command = ToolbarCommand.OrderedList },
36+
new ToolbarItemModel() { Command = ToolbarCommand.UnorderedList },
37+
new ToolbarItemModel() { Command = ToolbarCommand.Separator },
38+
new ToolbarItemModel() { Command = ToolbarCommand.CreateLink },
39+
new ToolbarItemModel() { Command = ToolbarCommand.Image },
40+
new ToolbarItemModel() { Command = ToolbarCommand.CreateTable },
41+
new ToolbarItemModel() { Command = ToolbarCommand.Separator },
42+
new ToolbarItemModel() { Command = ToolbarCommand.Undo },
43+
new ToolbarItemModel() { Command = ToolbarCommand.Redo }
44+
};
45+
46+
public static string mdValue { get; set; } = @"
47+
The sample is added to showcase **markdown editing**.
48+
Type or edit the content and apply formatting to view markdown formatted content.
49+
We can add our own custom formation syntax for the Markdown formation, [sample link] (https://ej2.syncfusion.com/home/).
50+
The third-party library <b>Marked</b> is used in this sample to convert markdown into HTML content";
51+
52+
private MarkdownPipeline pipeline { get; set; }
53+
private string htmlValue { get; set; }
54+
55+
protected override void OnInitialized()
56+
{
57+
pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
58+
this.htmlValue = Markdig.Markdown.ToHtml(mdValue, pipeline);
59+
base.OnInitialized();
60+
}
61+
private void onValueChange(Syncfusion.Blazor.RichTextEditor.ChangeEventArgs args)
62+
{
63+
if (args.Value == null)
64+
{
65+
this.htmlValue = null;
66+
}
67+
else
68+
{
69+
this.htmlValue = Markdig.Markdown.ToHtml(args.Value, pipeline);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)