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