10000 docs(Editor): Document built-in toolsets (#2480) · telerik/blazor-docs@bdcd99a · GitHub
[go: up one dir, main page]

Skip to content

Commit bdcd99a

Browse files
authored
docs(Editor): Document built-in toolsets (#2480)
* docs(Editor): Document built-in toolsets * Fix Editor paste settings docs * Use uppercase Editor name
1 parent dc6505e commit bdcd99a

File tree

2 files changed

+77
-45
lines changed

2 files changed

+77
-45
lines changed

components/editor/paste-cleanup.md

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ position: 70
99

1010
# Editor Paste Cleanup
1111

12-
The Telerik Editor component for Blazor can improve the quality of the content pasted into it by removing tags and attributes, and by fixing issues such as lists pasted from Microsoft Word.
13-
14-
#### In this article
15-
16-
17-
* [Basics](#basics)
18-
* [Paste Settings Features](#paste-settings-features)
19-
* [Notes](#notes)
12+
The Telerik Editor component for Blazor can improve the quality of pasted content by removing invalid or unwanted tags and attributes. The Editor can also fix issues such as non-semantic lists pasted from Microsoft Word.
2013

2114

2215
## Basics
2316

24-
To control the behavior of the editor when content is pasted, you can set the desired parameters to its `EditorPasteSettings` tag that you can find under the `EditorSettings` tag.
17+
To enable paste cleanup, add the `<EditorPasteSettings>` tag as a child of the `<EditorSettings>` tag. The Editor does not perform paste cleanup by default.
18+
19+
To configure the behavior of the Editor when content is pasted, set the desired parameters in the `EditorPasteSettings` tag.
2520

2621
>caption Set pasting behaviors in the Telerik Editor
2722
@@ -42,7 +37,7 @@ To control the behavior of the editor when content is pasted, you can set the de
4237
</EditorSettings>
4338
</TelerikEditor>
4439
45-
The editor content as a string so you can see the differences with the original content above:
40+
The Editor content as a string so you can see the differences with the original content above:
4641
<br />
4742
@EditorValue
4843
@@ -53,9 +48,10 @@ The editor content as a string so you can see the differences with the original
5348
}
5449
````
5550

56-
## Paste Settings Features
5751

58-
The following list describes the behaviors and functionality each parameter of the `EditorPasteSettings` provides:
52+
## Paste Settings
53+
54+
The following list describes the behaviors and functionality of each parameter of `EditorPasteSettings`. The default values apply only if the `<EditorPasteSettings>` tag is present in the Editor markup.
5955

6056
* `ConvertMsList` - `bool` - If set to `true` (defaults to `true`), MS Word lists will be converted into HTML lists. By default, Word's list are paragraphs with the respective styling which is not accurate in html.
6157

@@ -73,49 +69,42 @@ For example, `<!-- comment --> <p> content </p>` will result in `<p> content </p
7369
* `RemoveAttributes` - `List<string>` - Specifies the DOM attributes that should be removed from the HTML. For example, when set to `{ "lang" }` , pasting `<p><span lang=EN-US>content</span></p>` will result in `<p><span>content</span></p>`.
7470

7571

72+
## Paste Images from Microsoft Word
7673

77-
## Notes
78-
79-
This section provides information on a few key concepts and behaviors that you should be aware of:
80-
81-
* [Content Size](#content-size)
82-
* [Content Sanitization](#content-sanitization)
83-
* [Paste Text and Image from MS Word](#paste-text-and-image-from-ms-word)
74+
If you copy both text and an image from MS Word and paste in the Editor, the image will not get pasted as expected. This behavior is due to the security policy of the browser.
8475

76+
Instead of reading the image data and loading it as a `base64` string to the `src` attribute of the `<img> `element, the browser generates an `<img>` tag which points to the clipboard location of the file on the client machine.
8577

86-
### Content Size
87-
@[template](/_contentTemplates/editor/general.md#content-size-signalr)
78+
A browser is not allowed to access such a resource, and so it throws an error and the image is not rendered which you can verify in the browser dev tools console, you will see an error such as: `"Not allowed to load local resource: <some image path>"`.
8879

89-
### Content Sanitization
80+
You can read more about this in <a href="https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource" target="_blank">this StackOverflow thread</a>.
9081

91-
>caution The content cleaning the editor performs happens on paste only. The user can still alter the HTML and if you are sending or receiving data over the wire, there is a chance such requests can be intercepted and altered maliciously if the application is not secured. Therefore, the paste cleanup functionality of the editor cannot and does not replace content sanitization according to the application's standards and logic.
92-
>
93-
> @[template](/_contentTemplates/editor/general.md#app-must-sanitize-content)
82+
### Work Around
9483

84+
To work around this browser behavior, copy only the text or a single image from the MS Word document, and paste the image in the content area of the Editor separately.
9585

96-
The editor clears `<script>` tags and removes DOM event handler attributes (e.g., `<img onerror="code();" onclick="otherCode();" alt="lorem ipsum" />` will become `<img alt="lorem ipsum" />`). The user can still alter this and data can be modified during transmission as well, as explained above.
86+
By default, the browser allows you to copy and paste a single image from Word in the Editor by converting its `src` to a `base64` string.
9787

98-
>tip To clean up content and ensure it is safe, before you store and reuse it, you can consider ready-made HTML sanitization libraries that are available on free package sources like nuget.org. While Telerik is not in a position to recommend particular packages, we recommend you consider such an approach.
88+
If you paste more images at the same time, their `src` attributes will not be converted to `base64` strings and the browser will paste them with their `http` protocol and `URL` pointing to the physical folder which will result in the error described above.
9989

100-
### Paste Text and Image from MS Word
10190

102-
If you copy both text and an image from MS Word and paste in the Editor, the image will not get pasted as expected. This behavior is due to the security policy of the browser.
91+
## Content Size
10392

104-
Instead of reading the image data and loading it as a `base64` string to the `src` attribute of the `<img> `element, the browser generates an `<img>` tag which points to the clipboard location of the file on the client machine.
93+
@[template](/_contentTemplates/editor/general.md#content-size-signalr)
10594

106-
A browser is not allowed to access such a resource, and so it throws an error and the image is not rendered which you can verify in the browser dev tools console, you will see an error such as: `"Not allowed to load local resource: <some image path>"`.
95+
## Content Sanitization
10796

108-
You can read more about this in <a href="https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource" target="_blank">this StackOverflow thread</a>.
97+
>caution The content cleaning the Editor performs happens on paste only. The user can still alter the HTML and if you are sending or receiving data over the wire, there is a chance such requests can be intercepted and altered maliciously if the application is not secured. Therefore, the paste cleanup functionality of the Editor cannot and does not replace content sanitization according to the application's standards and logic.
98+
>
99+
> @[template](/_contentTemplates/editor/general.md#app-must-sanitize-content)
109100
110-
#### Work Around
111101

112-
To work around this browser behavior, copy only the text or a single image from the MS Word document, and paste the image in the content area of the Editor separately.
102+
The Editor clears `<script>` tags and removes DOM event handler attributes (e.g., `<img onerror="code();" onclick="otherCode();" alt="lorem ipsum" />` will become `<img alt="lorem ipsum" />`). The user can still alter this and data can be modified during transmission as well, as explained above.
113103

114-
By default, the browser allows you to copy and paste a single image from Word in the Editor by converting its `src` to a `base64` string.
104+
>tip To clean up content and ensure it is safe, before you store and reuse it, you can consider ready-made HTML sanitization libraries that are available on free package sources like nuget.org. While Telerik is not in a position to recommend particular packages, we recommend you consider such an approach.
115105
116-
If you paste more images at the same time, their `src` attributes will not be converted to `base64` strings and the browser will paste them with their `http` protocol and `URL` pointing to the physical folder which will result in the error described above.
117106

118107
## See Also
119108

120-
* [Editor Overview]({%slug editor-overview%})
121-
* [Live Demo: Paste Cleanup](https://demos.telerik.com/blazor-ui/editor/paste-cleanup)
109+
* [Editor Overview]({%slug editor-overview%})
110+
* [Live Demo: Paste Cleanup](https://demos.telerik.com/blazor-ui/editor/paste-cleanup)

components/editor/toolbar.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,65 @@ To control the collection of buttons and commands available to the user, you pro
3333

3434
## Built-in Tool Lists
3535

36-
The Editor comes with two predefined sets of tools in the `EditorToolSets` static class:
36+
The Editor comes with [two predefined sets of tools](#predefined-toolset-configurations) in the `EditorToolSets` static class:
3737

38-
* `Default` - the default set of the most commonly used tools and commands.
39-
* `All` - All the available tools and commands the editor has.
38+
* `Default` includes the most commonly used tools and commands. If you do not apply any settings, the `Default` list of tools will be used.
39+
* `All` includes all the available tools and commands.
4040

41-
If you do not apply any settings, the `Default` list of tools will be used.
41+
The following example shows how to use the `All` toolset.
4242

43-
>caption Switch to the All tools built-in toolset
43+
>caption Use all built-in Editor tools
4444
4545
````CSHTML
4646
@using Telerik.Blazor.Components.Editor
4747
48-
<TelerikEditor Tools="@EditorToolSets.All">
48+
<TelerikEditor @bind-Value="@EditorValue"
49+
Tools="@EditorToolSets.All">
4950
</TelerikEditor>
51+
52+
@code {
53+
private string EditorValue { get; set; } = string.Empty;
54+
}
5055
````
5156

57+
### Predefined Toolset Configurations
58+
59+
The following code snippets show the built-in toolset configurations in `EditorToolSets`. See the [Built-in Editor Tools]({%slug editor-built-in-tools%}) article for more information on each tool.
60+
61+
<div class="skip-repl"></div>
62+
63+
````cs
64+
public static List<IEditorTool> Default = new List<IEditorTool>()
65+
{
66+
new EditorButtonGroup(new Bold(), new Italic(), new Underline()),
67+
new Format(),
68+
new EditorButtonGroup(new AlignLeft(), new AlignCenter(), new AlignRight(), new AlignJustify()),
69+
new EditorButtonGroup(new UnorderedList(), new OrderedList(), new Indent(), new Outdent()),
70+
new EditorButtonGroup(new CreateLink(), new Unlink()),
71+
new InsertImage()
72+
};
73+
74+
public static List<IEditorTool> All = new List<IEditorTool>()
75+
{
76+
new EditorButtonGroup(new Undo(), new Redo()),
77+
new EditorButtonGroup(new Bold(), new Italic(), new Underline(), new Strikethrough()),
78+
new EditorButtonGroup(new SubScript(), new SuperScript()),
79+
new Format(),
80+
new FontFamily(),
81+
new FontSize(),
82+
new ForeColor(),
83+
new BackgroundColor(),
84+
new EditorButtonGroup(new AlignLeft(), new AlignCenter(), new AlignRight(), new AlignJustify()),
85+
new EditorButtonGroup(new UnorderedList(), new OrderedList(), new Indent(), new Outdent()),
86+
new EditorButtonGroup(new CreateLink(), new Unlink()),
87+
new InsertImage(),
88+
new InsertTable(),
89+
new EditorButtonGroup(new AddColumnBefore(), new AddColumnAfter(), new AddRowBefore(), new AddRowAfter()),
90+
new EditorButtonGroup(new DeleteColumn(), new DeleteRow(), new DeleteTable()),
91+
new EditorButtonGroup(new MergeCells(), new SplitCell()),
92+
new ViewHtml()
93+
};
94+
````
5295

5396
## Choose Toolbar Items
5497

@@ -249,4 +292,4 @@ When adding a built-in tool to the collection, you can set various parameters to
249292

250293
## See Also
251294

252-
* [Editor Overview]({%slug editor-overview%})
295+
* [Editor Overview]({%slug editor-overview%})

0 commit comments

Comments
 (0)
0