Skip to content

Commit ccff857

Browse files
committed
DOC-3147: Removed property from Editor instances, use instead.
Add distinction between tinymce.documentBaseURL and editor.documentBaseURI Expand documentBaseURI documentation with accurate method examples Remove incorrect API method examples Add detailed path resolution explanations Retain documentBaseURL in TinyMCE root API docs
1 parent b3a9cdd commit ccff857

File tree

8 files changed

+175
-77
lines changed

8 files changed

+175
-77
lines changed

modules/ROOT/examples/live-demos/url-conversion-relative-2/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ tinymce.init({
33
height: 300,
44
plugins: 'link image code',
55
relative_urls: true,
6-
document_base_url: '//www.tiny.cloud/docs/demo',
6+
// The documentBaseURI will be set to the current page's URL
7+
setup: function(editor) {
8+
editor.on('init', function() {
9+
console.log('Base URI:', editor.documentBaseURI.getURI());
10+
});
11+
},
712
content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }'
813
});

modules/ROOT/pages/8.0-release-notes.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ For information on using Enhanced Skins & Icon Packs, see: xref:enhanced-skins-a
136136
// #TINY-vwxyz1
137137

138138
// CCFR here.
139+
=== Removed `documentBaseUrl` property from Editor instances, use `documentBaseURI` instead.
140+
// #TINY-12182
141+
142+
{productname} {release-version} has removed the undocumented `documentBaseUrl` property from `Editor` instances. This internal property was not part of the public API and may have caused confusion for developers accessing editor internals. The supported and documented alternative is `documentBaseURI`, which should be used instead. This change improves API clarity by eliminating unsupported and untracked editor properties.
143+
144+
For more information on the `documentBaseURI` property, see the {api_url}/tinymce.editor/#documentBaseURI[Editor API - documentBaseURI] documentation.
139145

140146

141147
[[bug-fixes]]

modules/ROOT/pages/url-handling.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
= URL handling options
22
:navtitle: URL handling options
33
:description: These settings affect the way URLs are handled by the editor.
4-
:keywords: url, urls, relative, absolute, domain, document_base_url
4+
:keywords: url, urls, relative, absolute, domain, documentBaseURI
55

66
include::partial$misc/url-handling.adoc[]
77

@@ -17,7 +17,7 @@ include::partial$configuration/allow_script_urls.adoc[leveloffset=+1]
1717

1818
include::partial$configuration/convert_urls.adoc[leveloffset=+1]
1919

20-
include::partial$configuration/document_base_url.adoc[leveloffset=+1]
20+
include::partial$configuration/document_base_uri.adoc[leveloffset=+1]
2121

2222
include::partial$configuration/relative_urls.adoc[leveloffset=+1]
2323

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
[[document_base_uri]]
2+
== `documentBaseURI`
3+
4+
The `documentBaseURI` property provides methods for URL manipulation in the editor. It is an instance of the {api_url}/tinymce.util.uri/[URI] class that represents the editor's base URL.
5+
6+
NOTE: This is different from `tinymce.documentBaseURL` (the global EditorManager property). While `tinymce.documentBaseURL` is a string property containing the document's base URL, `editor.documentBaseURI` is the recommended way to handle URL manipulations within an editor instance as it provides helpful methods for URL conversion.
7+
8+
=== Example: URL Manipulation
9+
10+
[source,js]
11+
----
12+
tinymce.init({
13+
selector: 'textarea',
14+
setup: function(editor) {
15+
editor.on('init', function() {
16+
const baseUri = editor.documentBaseURI;
17+
18+
// Get the base URL
19+
console.log('Base URL:', baseUri.getURI());
20+
// Output: "Base URL: https://fiddle.tiny.cloud/"
21+
22+
// Convert relative to absolute URL
23+
console.log('Absolute URL:', baseUri.toAbsolute('images/logo.png'));
24+
// Output: "Absolute URL: https://fiddle.tiny.cloud/images/logo.png"
25+
26+
// Convert absolute to relative URL
27+
console.log('Relative URL:', baseUri.toRelative('https://fiddle.tiny.cloud/images/logo.png'));
28+
// Output: "Relative URL: images/logo.png"
29+
});
30+
}
31+
});
32+
----
33+
34+
=== Available Methods
35+
36+
The `documentBaseURI` object provides the following methods for URL handling:
37+
38+
* `getURI()` - Gets the complete base URI as a string
39+
* `toAbsolute(url)` - Converts a relative URL to an absolute URL based on the editor's base URL
40+
* `toRelative(url)` - Converts an absolute URL to a relative URL based on the editor's base URL
41+
* `toAbsPath(base, path)` - Converts a relative path to an absolute path
42+
43+
NOTE: While `documentBaseURI` is an instance of the URI class, it primarily exposes methods for URL conversion. For more complex URI manipulation, you can create a new instance of `tinymce.util.URI`.
44+
45+
=== Examples
46+
47+
==== URL Manipulation
48+
49+
[source,js]
50+
----
51+
tinymce.init({
52+
selector: 'textarea',
53+
setup: function(editor) {
54+
editor.on('init', function() {
55+
const baseUri = editor.documentBaseURI;
56+
57+
// Get the complete base URL
58+
console.log('Base URL:', baseUri.getURI());
59+
// Example output: "https://example.com/path/to/editor/"
60+
61+
// Basic URL conversions
62+
console.log('To Absolute:', baseUri.toAbsolute('images/logo.png'));
63+
// Example output: "https://example.com/path/to/editor/images/logo.png"
64+
65+
console.log('To Relative:', baseUri.toRelative('https://example.com/path/to/editor/images/logo.png'));
66+
// Example output: "images/logo.png"
67+
68+
console.log('To Absolute Path:', baseUri.toAbsPath('/root/', 'path/file.txt'));
69+
// Example output: "/root/path/file.txt"
70+
});
71+
}
72+
});
73+
----
74+
75+
==== Additional URL Manipulation Examples
76+
77+
[source,js]
78+
----
79+
tinymce.init({
80+
selector: 'textarea',
81+
setup: function(editor) {
82+
editor.on('init', function() {
83+
const baseUri = editor.documentBaseURI;
84+
85+
// Working with content URLs
86+
const imageUrl = 'images/logo.png';
87+
const styleUrl = '/styles/custom.css';
88+
const fullUrl = 'https://example.com/resources/file.pdf';
89+
90+
// Converting relative URLs to absolute
91+
console.log('Image absolute:', baseUri.toAbsolute(imageUrl));
92+
console.log('Style absolute:', baseUri.toAbsolute(styleUrl));
93+
94+
// Converting absolute URLs to relative
95+
console.log('Document relative:', baseUri.toRelative(fullUrl));
96+
97+
// Working with paths (resolves and normalizes paths)
98+
console.log('Absolute path 1:', baseUri.toAbsPath('/content/', '../images/photo.jpg'));
99+
// Output: "/images/photo.jpg" (../ moves up from /content/ to /, then adds images/photo.jpg)
100+
101+
console.log('Absolute path 2:', baseUri.toAbsPath('/content/sub/', '../../images/photo.jpg'));
102+
// Output: "/images/photo.jpg" (../../ moves up twice from /content/sub/ to /)
103+
104+
console.log('Absolute path 3:', baseUri.toAbsPath('/content/', './images/photo.jpg'));
105+
// Output: "/content/images/photo.jpg" (./ keeps us in /content/)
106+
});
107+
}
108+
});
109+
----

modules/ROOT/partials/configuration/document_base_url.adoc

Lines changed: 0 additions & 18 deletions
This file was deleted.

modules/ROOT/partials/configuration/relative_urls.adoc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
[[relative_urls]]
22
== `+relative_urls+`
33

4-
For URLs with the same domain as the page containing the {productname} editor. If set to:
4+
For URLs with the same domain as the editor content. This option controls whether URLs are converted to:
55

6-
* `+true+` -- All URLs created in {productname} will be converted to a link relative to the xref:url-handling.adoc#document_base_url[`+document_base_url+`].
7-
* `+false+` -- All URLs will be converted to absolute URLs.
6+
* `+true+` (default) - Relative URLs based on the configured base URL (see xref:apis/tinymce.editor.adoc#documentBaseURI[documentBaseURI])
7+
* `+false+` - Absolute URLs
88

9-
*Type:* `+Boolean+`
10-
11-
*Default value:* `+true+`
12-
13-
*Possible values:* `+true+`, `+false+`
9+
The actual URL conversion is handled by the editor's `documentBaseURI` property. For more details on URL manipulation methods, see the {api_url}/tinymce.util.uri/[URI API documentation].
1410

1511
=== Example: using `+relative_urls+`
1612

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
11
[[remove_script_host]]
22
== `+remove_script_host+`
33

4-
This option is used if the xref:url-handling.adoc#relative_urls[`+relative_urls+`] option is set to `+false+` and only applies to links with the same domain as the xref:url-handling.adoc#document_base_url[`+document_base_url+`].
4+
This option controls whether the protocol and domain are included in URLs when `relative_urls` is set to `false`.
55

6-
If this option is set to `+true+`, the protocol and host of the `+document_base_url+` is _excluded_ for relative links.
6+
* `+true+` (default) - Protocol and domain are removed from URLs
7+
* `+false+` - Protocol and domain are included in URLs
78

8-
If this option is set to `+false+`, the protocol and host of the `+document_base_url+` is _added_ for relative links.
9+
This setting affects both the visual representation of URLs in the editor and the results from the `documentBaseURI` URL manipulation methods.
910

10-
*Type:* `+Boolean+`
11-
12-
*Default value:* `+true+`
13-
14-
*Possible values:* `+true+`, `+false+`
15-
16-
=== Examples: Using `+remove_script_host+`
17-
18-
When `+remove_script_host+` is set to `+true+`, such as:
11+
=== Example: URL handling with remove_script_host
1912

2013
[source,js]
2114
----
2215
tinymce.init({
23-
selector: 'textarea', // change this value according to your HTML
24-
document_base_url: 'http://www.example.com/path1/',
16+
selector: 'textarea',
2517
relative_urls: false,
2618
remove_script_host: true
2719
});
28-
----
29-
30-
Adding a relative URL such as `+test.html+`, the editor will convert the URL to: `+/path1/test.html+`.
3120
32-
When `+remove_script_host+` is set to `+false+`, such as:
21+
// With remove_script_host: true
22+
editor.documentBaseURI.toAbsolute('page.html'); // Returns: /path1/page.html
3323
34-
[source,js]
35-
----
36-
tinymce.init({
37-
selector: 'textarea', // change this value according to your HTML
38-
document_base_url: 'http://www.example.com/path1/',
39-
relative_urls: false,
40-
remove_script_host: false
41-
});
24+
// With remove_script_host: false
25+
editor.documentBaseURI.toAbsolute('page.html'); // Returns: http://www.example.com/path1/page.html
4226
----
43-
44-
Adding a relative URL such as `+test.html+`, the editor will convert the URL to: `+http://www.example.com/path1/test.html+`.

modules/ROOT/partials/misc/url-handling.adoc

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,81 @@
1-
== Convert URLs to relative, absolute, or absolute with domain
1+
== URL Handling in TinyMCE
22

3-
=== Relative URLs
3+
=== The documentBaseURI API
44

5-
This will convert all URLs within the same domain to relative URLs. The URLs will be relative from the xref:url-handling.adoc#document_base_url[document_base_url].
5+
The `documentBaseURI` property on the editor instance provides methods for manipulating URLs. This URI object represents the base URL for the editor and provides methods for converting between relative and absolute URLs.
6+
7+
For detailed information on using the documentBaseURI API, see: xref:apis/tinymce.editor.adoc#documentBaseURI[documentBaseURI].
8+
9+
=== URL Conversion Settings
10+
11+
Two configuration options control how URLs are displayed in the editor:
12+
13+
* `relative_urls` - When true, URLs are converted to be relative to the editor's base URL
14+
* `remove_script_host` - When true, the protocol and host are excluded from absolute URLs
15+
16+
=== URL Conversion Examples
17+
18+
==== Relative URLs
19+
20+
This converts URLs to be relative to the base URL:
621

722
[source,js]
823
----
924
tinymce.init({
10-
selector: 'textarea', // change this value according to your HTML
11-
relative_urls: true,
12-
document_base_url: 'http://www.example.com/path1/'
25+
selector: 'textarea',
26+
relative_urls: true
1327
});
28+
29+
// The editor's documentBaseURI can be used to manipulate URLs:
30+
editor.documentBaseURI.toRelative('http://www.example.com/path1/path2/file.htm'); // Returns: path2/file.htm
1431
----
1532

1633
Example: `+http://www.example.com/path1/path2/file.htm+` >> `+path2/file.htm+`
1734

18-
==== Example: relative URLs on links and images
35+
===== Example: relative URLs on links and images
1936

2037
liveDemo::url-conversion-relative-1[]
2138

22-
==== Example: relative URLs on links and images to a specific page
39+
===== Example: relative URLs on links and images to a specific page
2340

2441
liveDemo::url-conversion-relative-2[]
2542

26-
=== Absolute URLs
43+
==== Absolute URLs
2744

28-
This will convert all relative URLs to absolute URLs. The URLs will be absolute based on the xref:url-handling.adoc#document_base_url[document_base_url].
45+
This converts URLs to be absolute based on the document base URL:
2946

3047
[source,js]
3148
----
3249
tinymce.init({
33-
selector: 'textarea', // change this value according to your HTML
50+
selector: 'textarea',
3451
relative_urls: false,
35-
remove_script_host: true,
36-
document_base_url: 'http://www.example.com/path1/'
52+
remove_script_host: true
3753
});
54+
55+
// The editor's documentBaseURI can be used to manipulate URLs:
56+
editor.documentBaseURI.toAbsolute('path2/file.htm'); // Returns: /path1/path2/file.htm
3857
----
3958

4059
Example: `+path2/file.htm+` >> `+/path1/path2/file.htm+`
4160

42-
==== Example: absolute URLs on links and images
61+
===== Example: absolute URLs on links and images
4362

4463
liveDemo::url-conversion-absolute-1[]
4564

46-
==== Example: absolute URLs and including domain on links and images
65+
===== Example: absolute URLs and including domain on links and images
4766

4867
liveDemo::url-conversion-absolute-2[]
4968

50-
=== Domain absolute URLs
69+
==== Domain absolute URLs
5170

52-
This will convert all relative URLs to absolute URLs. The URLs will be absolute based on the xref:url-handling.adoc#document_base_url[document_base_url] with domain.
71+
This converts URLs to be absolute with the domain included:
5372

5473
[source,js]
5574
----
5675
tinymce.init({
57-
selector: 'textarea', // change this value according to your HTML
76+
selector: 'textarea',
5877
relative_urls: false,
59-
remove_script_host: false,
60-
document_base_url: 'http://www.example.com/path1/'
78+
remove_script_host: false
6179
});
6280
----
6381

0 commit comments

Comments
 (0)