Skip to content

Commit

Permalink
Release 0.1.1 version (#2)
Browse files Browse the repository at this point in the history
1. Refactor code
2. Add `widget` support
3. Add `LinkAttributes` support
  • Loading branch information
ling921 committed Jul 9, 2023
1 parent 2fa7648 commit 436d708
Show file tree
Hide file tree
Showing 45 changed files with 4,888 additions and 967 deletions.
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# ToastUI Editor Blazor

`ToastUIEditor.Blazor` is a Blazor component that provides a Markdown editor based on the [tui.editor](https://github.com/nhn/tui.editor) library.
`tui.editor.blazor` is a Blazor component that provides a Markdown editor based on the [tui.editor](https://github.com/nhn/tui.editor) library.


## Installation

Install the package using following command:

``` Package Manager
Install-Package ToastUIEditor.Blazor
Install-Package ToastUIEditor
```

or

``` powershell
dotnet add package ToastUIEditor.Blazor
dotnet add package ToastUIEditor
```

or just use nuget package manager.


## Usage

1. Add the following import statement to your `_Imports.razor` file
Expand All @@ -26,12 +28,14 @@ or just use nuget package manager.
@using ToastUI
```


2. Use the `Editor` component in your Blazor page or component

``` razor
<Editor @bind-Value="content" Options="@options" />
```


- `@bind-Value`: Binds the editor's content to a string property in your Blazor component.
- `Options`: Sets the configuration options for the editor. Refer to the `EditorOptions` class for available options.

Expand All @@ -43,31 +47,29 @@ or just use nuget package manager.

- `Value`: Sets the content to be displayed in the viewer. It will update automatically when `content` changes.

1. Handle the available events by specifying event callbacks

4. Handle the available events by specifying event callbacks

``` razor
<Editor @bind-Value="content"
OnLoad="HandleLoad"
OnChange="HandleChange"
OnCaretChange="HandleCaretChange"
OnFocus="HandleFocus"
OnBlur="HandleBlur"
OnKeydown="HandleKeydown"
OnKeyup="HandleKeyup"
Load="HandleLoad"
Change="HandleChange"
CaretChange="HandleCaretChange"
Focus="HandleFocus"
Blur="HandleBlur"
KeyDown="HandleKeyDown"
KeyUp="HandleKeyUp"
BeforePreviewRender="HandleBeforePreviewRender"
BeforeConvertWysiwygToMarkdown="HandleBeforeConvertWysiwygToMarkdown" />
BeforeConvertWYSIWYGToMarkdown="HandleBeforeConvertWYSIWYGToMarkdown" />
<Viewer Value="content"
OnLoad="HandleLoad"
OnChange="HandleChange"
OnCaretChange="HandleCaretChange"
OnFocus="HandleFocus"
OnBlur="HandleBlur" />
Load="HandleLoad"
Change="HandleChange"
UpdatePreview="HandleUpdatePreview" />
```

These events are the same as the native public events, and the parameters are detailed in the code comments.

> Notes: It seems that events for `Viewer` are not working in original library.

5. Access the `Editor` or `Viewer` instance to invoke methods

Expand Down Expand Up @@ -98,9 +100,11 @@ Most of all native methods have been implemented. Refer to the Editor class for

6. Add custom language

Use `EditorLanguage.Add` method to add custom language.
- Use `Editor.SetLanguage` static method to add custom language.
- Use `Editor.SetDefaultLanguage` static method to set default language, it will be used when no language is set in `EditorOptions`.

> Note: Please make sure Editor.SetLanguage and Editor.SetDefaultLanguage are called before `Editor` component is rendered.
You can check `EditorLanguage` class for more details.

## Implemented Features

Expand All @@ -110,8 +114,8 @@ You can check `EditorLanguage` class for more details.
- [x] `Editor` and `Viewer` instance methods
- [ ] Toolbar with custom button
- [ ] Add command and execute command
- [ ] Add widget and set widget rules
- [ ] Link attributes
- [x] Add widget and set widget rules
- [x] Link attributes
- [ ] Custom markdown renderer
- [ ] Custom HTML renderer
- [ ] Custom HTML Sanitizer
Expand Down
18 changes: 9 additions & 9 deletions samples/Sample.Server/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/"
@page "/"

<PageTitle>Index</PageTitle>

Expand All @@ -12,23 +12,23 @@ Welcome to your new app.
@bind-Value="content"
Options="options"
Placeholder="A sample editor."
OnLoad="MarkdownChanged"
OnChange="MarkdownChanged" />
Load="MarkdownChanged"
Change="MarkdownChanged" />

<Viewer Value="@markdown" EnableLogging />

<br />
<br />

<button class="btn btn-primary" @onclick="ShowHTML">Show HTML</button>
<div>@html</div>
<button class="btn btn-primary" @onclick="ShowHTML">Show HTML</button>
<div>@html</div>

@code {
@code {
Editor editorRef = default!;
EditorOptions options = new()
{
PreviewStyle = PreviewStyles.Vertical,
PreviewStyle = PreviewStyle.Vertical,
Language = "zh-CN",
Theme = EditorThemes.Auto,
Theme = Theme.Auto,
};
string content = "Hello, world!";
string markdown = "";
Expand Down
29 changes: 22 additions & 7 deletions samples/Sample.WebAssembly/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/"
@page "/"
@using System.Text.RegularExpressions;

<PageTitle>Index</PageTitle>

Expand All @@ -8,12 +9,14 @@ Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

<InputText @bind-Value="content" />

<Editor @ref="editorRef"
@bind-Value="content"
@bind-Value="content"
Options="options"
Placeholder="A sample editor."
OnLoad="MarkdownChanged"
OnChange="MarkdownChanged" />
Load="MarkdownChanged"
Change="MarkdownChanged" />

<Viewer Value="@markdown" />

Expand All @@ -26,11 +29,23 @@ Welcome to your new app.
Editor editorRef = default!;
EditorOptions options = new()
{
PreviewStyle = PreviewStyles.Vertical,
PreviewStyle = PreviewStyle.Vertical,
Language = "zh-CN",
Theme = EditorThemes.Auto,
Theme = Theme.Auto,
WidgetRules = new WidgetRule[]
{
new WidgetRule(
@"\bw\w+?d\b",
text => Regex.Replace(text, @"(w\w+?d)", "<span style=\"color: red;\">$1</span>")
),
},
LinkAttributes = new()
{
{ LinkAttributeNames.Target, "_blank" },
{ LinkAttributeNames.Rel, "nofollow"}
},
};
string content = "Hello, world!";
string content = "Hello, world! \n[tui.editor](https://github.com/nhn/tui.editor)";
string markdown = "";
string html = "";

Expand Down
3 changes: 2 additions & 1 deletion samples/Sample.WebAssembly/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using System.Net.Http
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
Expand All @@ -9,3 +9,4 @@
@using Sample.WebAssembly
@using Sample.WebAssembly.Shared
@using ToastUI
@using ToastUI.Extend;
4 changes: 2 additions & 2 deletions src/ToastUIEditor.Generators/LanguageGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void Execute(GeneratorExecutionContext context)
namespace ToastUI
{
partial class EditorLanguage
partial class Editor
{
static EditorLanguage()
static Editor()
{");

foreach (var translation in translations)
Expand Down
Loading

0 comments on commit 436d708

Please sign in to comment.