Jelajahi Sumber

Update documentation (API, guide).

panr 5 tahun lalu
induk
melakukan
08c8db3278

+ 24 - 0
packages/ckeditor5-link/docs/features/link.md

@@ -147,6 +147,30 @@ ClassicEditor
 	.catch( ... );
 ```
 
+#### Adding default link protocol for the external links
+
+Default link protocol can be usefull when user forget to type a full URL address to an external source, site etc. Sometimes copying the text, like for example `ckeditor.com` and converting it to a link may cause some issues. When you do this, the created link will direct you to `yourdomain.com/ckeditor.com`, because you forgot to pass the right protocol which makes the link relative to the site where it appears.
+
+Enabling the `{@link module:link/link~LinkConfig#defaultProtocol config.link.defaultProtocol}`, the {@link module:link/link~Link} feature will handle this issue for you. By default it doesn't fix the passed link value, but when you set `{@link module:link/link~LinkConfig#defaultProtocol config.link.defaultProtocol}` to — for example — `http://`, the plugin will add the given protocol to the every link that may need it (like `ckeditor.com`, `example.com` etc. where `[protocol://]example.com` is missing). Here's the basic configuration example:
+
+```js
+ClassicEditor
+	.create( document.querySelector( '#editor' ), {
+		// ...
+		link: {
+			defaultProtocol: 'http://'
+		}
+	} )
+	.then( ... )
+	.catch( ... );
+```
+
+<info-box>
+	Having `config.link.defaultProtocol` enabled you are still able to link things locally using `#` or `/`. Protocol won't be added to those links.
+
+	Enabled feature also gives you an **email addresses auto-detection** feature. When you submit `hello@example.com`, the plugin will change it automatically to `mailto:hello@example.com`.
+</info-box>
+
 #### Adding attributes to links based on pre–defined rules (automatic decorators)
 
 Automatic link decorators match all links in the editor content against a {@link module:link/link~LinkDecoratorAutomaticDefinition function} which decides whether the link should receive some set of attributes, considering the URL (`href`) of the link. These decorators work silently and are being applied during the {@link framework/guides/architecture/editing-engine#conversion data downcast} only.

+ 5 - 2
packages/ckeditor5-link/src/link.js

@@ -59,10 +59,12 @@ export default class Link extends Plugin {
 
 /**
  * When set, the editor will add the given protocol to the link when the user creates a link without one.
- * In case no configuration is provided, the value defaults to `http://`.
  * For example, when the user is creating a link and types `ckeditor.com` in the link form input — during link submission —
  * the editor will automatically add the `http://` protocol, so the link will be as follows: `http://ckeditor.com`.
  *
+ * The feature also comes with an email auto-detection. When you submit `hello@example.com`
+ * the plugin will automatically change it to `mailto:hello@example.com`.
+ *
  * 		ClassicEditor
  *			.create( editorElement, {
  * 				link: {
@@ -72,7 +74,8 @@ export default class Link extends Plugin {
  *			.then( ... )
  *			.catch( ... );
  *
- * @default 'http://'
+ * **NOTE:** In case no configuration is provided, the editor won't auto-fix the links.
+ *
  * @member {String} module:link/link~LinkConfig#defaultProtocol
  */