@@ -80,7 +80,7 @@ export function getData( view, options = {} ) {
80
80
getData . _stringify = stringify ;
81
81
82
82
/**
83
- * Sets the content of the {@link module:engine/view/document~Document document} provided as an HTML-like string.
83
+ * Sets the content of a view {@link module:engine/view/document~Document document} provided as an HTML-like string.
84
84
*
85
85
* @param {module:engine/view/view~View } view
86
86
* @param {String } data An HTML-like string to write into the document.
@@ -111,44 +111,47 @@ setData._parse = parse;
111
111
112
112
/**
113
113
* Converts view elements to HTML-like string representation.
114
+ *
114
115
* A root element can be provided as {@link module:engine/view/text~Text text}:
115
116
*
116
- * const text = new Text ( 'foobar' );
117
+ * const text = downcastWriter.createText ( 'foobar' );
117
118
* stringify( text ); // 'foobar'
118
119
*
119
120
* or as an {@link module:engine/view/element~Element element}:
120
121
*
121
- * const element = new Element ( 'p', null, new Text ( 'foobar' ) );
122
+ * const element = downcastWriter.createElement ( 'p', null, downcastWriter.createText ( 'foobar' ) );
122
123
* stringify( element ); // '<p>foobar</p>'
123
124
*
124
125
* or as a {@link module:engine/view/documentfragment~DocumentFragment document fragment}:
125
126
*
126
- * const text = new Text ( 'foobar' );
127
- * const b = new Element ( 'b', { name: 'test' }, text );
128
- * const p = new Element ( 'p', { style: 'color:red;' } );
129
- * const fragment = new DocumentFragment ( [ p, b ] );
127
+ * const text = downcastWriter.createText ( 'foobar' );
128
+ * const b = downcastWriter.createElement ( 'b', { name: 'test' }, text );
129
+ * const p = downcastWriter.createElement ( 'p', { style: 'color:red;' } );
130
+ * const fragment = downcastWriter.createDocumentFragment ( [ p, b ] );
130
131
*
131
132
* stringify( fragment ); // '<p style="color:red;"></p><b name="test">foobar</b>'
132
133
*
133
134
* Additionally, a {@link module:engine/view/documentselection~DocumentSelection selection} instance can be provided.
134
- * Ranges from the selection will then be included in output data.
135
+ * Ranges from the selection will then be included in the output data.
135
136
* If a range position is placed inside the element node, it will be represented with `[` and `]`:
136
137
*
137
- * const text = new Text ( 'foobar' );
138
- * const b = new Element ( 'b', null, text );
139
- * const p = new Element ( 'p', null, b );
140
- * const selection = new Selection (
141
- * Range._createFromParentsAndOffsets ( p, 0, p, 1 )
138
+ * const text = downcastWriter.createText ( 'foobar' );
139
+ * const b = downcastWriter.createElement ( 'b', null, text );
140
+ * const p = downcastWriter.createElement ( 'p', null, b );
141
+ * const selection = downcastWriter.createSelection (
142
+ * downcastWriter.createRangeIn ( p )
142
143
* );
143
144
*
144
145
* stringify( p, selection ); // '<p>[<b>foobar</b>]</p>'
145
146
*
146
147
* If a range is placed inside the text node, it will be represented with `{` and `}`:
147
148
*
148
- * const text = new Text( 'foobar' );
149
- * const b = new Element( 'b', null, text );
150
- * const p = new Element( 'p', null, b );
151
- * const selection = new Selection( Range._createFromParentsAndOffsets( text, 1, text, 5 ) );
149
+ * const text = downcastWriter.createText( 'foobar' );
150
+ * const b = downcastWriter.createElement( 'b', null, text );
151
+ * const p = downcastWriter.createElement( 'p', null, b );
152
+ * const selection = downcastWriter.createSelection(
153
+ * downcastWriter.createRange( downcastWriter.createPositionAt( text, 1 ), downcastWriter.createPositionAt( text, 5 ) )
154
+ * );
152
155
*
153
156
* stringify( p, selection ); // '<p><b>f{ooba}r</b></p>'
154
157
*
@@ -159,10 +162,10 @@ setData._parse = parse;
159
162
*
160
163
* Multiple ranges are supported:
161
164
*
162
- * const text = new Text ( 'foobar' );
163
- * const selection = new Selection ( [
164
- * Range._createFromParentsAndOffsets( text, 0, text, 1 ) ),
165
- * Range._createFromParentsAndOffsets( text, 3, text, 5 ) )
165
+ * const text = downcastWriter.createText ( 'foobar' );
166
+ * const selection = downcastWriter.createSelection ( [
167
+ * downcastWriter.createRange( downcastWriter.createPositionAt( text, 0 ), downcastWriter.createPositionAt( text, 1 ) ),
168
+ * downcastWriter.createRange( downcastWriter.createPositionAt( text, 3 ), downcastWriter.createPositionAt( text, 5 ) )
166
169
* ] );
167
170
*
168
171
* stringify( text, selection ); // '{f}oo{ba}r'
@@ -172,9 +175,9 @@ setData._parse = parse;
172
175
* is provided, it will be converted to a selection containing this range. If a position instance is provided, it will
173
176
* be converted to a selection containing one range collapsed at this position.
174
177
*
175
- * const text = new Text ( 'foobar' );
176
- * const range = Range._createFromParentsAndOffsets( text, 0, text, 1 );
177
- * const position = new Position ( text, 3 );
178
+ * const text = downcastWriter.createText ( 'foobar' );
179
+ * const range = downcastWriter.createRange( downcastWriter.createPositionAt( text, 0 ), downcastWriter.createPositionAt( text, 1 ) );
180
+ * const position = downcastWriter.createPositionAt ( text, 3 );
178
181
*
179
182
* stringify( text, range ); // '{f}oobar'
180
183
* stringify( text, position ); // 'foo{}bar'
@@ -186,10 +189,10 @@ setData._parse = parse;
186
189
* {@link module:engine/view/emptyelement~EmptyElement empty elements}
187
190
* and {@link module:engine/view/uielement~UIElement UI elements}:
188
191
*
189
- * const attribute = new AttributeElement ( 'b' );
190
- * const container = new ContainerElement ( 'p' );
191
- * const empty = new EmptyElement ( 'img' );
192
- * const ui = new UIElement ( 'span' );
192
+ * const attribute = downcastWriter.createAttributeElement ( 'b' );
193
+ * const container = downcastWriter.createContainerElement ( 'p' );
194
+ * const empty = downcastWriter.createEmptyElement ( 'img' );
195
+ * const ui = downcastWriter.createUIElement ( 'span' );
193
196
* getData( attribute, null, { showType: true } ); // '<attribute:b></attribute:b>'
194
197
* getData( container, null, { showType: true } ); // '<container:p></container:p>'
195
198
* getData( empty, null, { showType: true } ); // '<empty:img></empty:img>'
@@ -198,14 +201,14 @@ setData._parse = parse;
198
201
* If `options.showPriority` is set to `true`, a priority will be displayed for all
199
202
* {@link module:engine/view/attributeelement~AttributeElement attribute elements}.
200
203
*
201
- * const attribute = new AttributeElement ( 'b' );
204
+ * const attribute = downcastWriter.createAttributeElement ( 'b' );
202
205
* attribute._priority = 20;
203
206
* getData( attribute, null, { showPriority: true } ); // <b view-priority="20"></b>
204
207
*
205
208
* If `options.showAttributeElementId` is set to `true`, the attribute element's id will be displayed for all
206
209
* {@link module:engine/view/attributeelement~AttributeElement attribute elements} that have it set.
207
210
*
208
- * const attribute = new AttributeElement ( 'span' );
211
+ * const attribute = downcastWriter.createAttributeElement ( 'span' );
209
212
* attribute._id = 'marker:foo';
210
213
* getData( attribute, null, { showAttributeElementId: true } ); // <span view-id="marker:foo"></span>
211
214
*
@@ -249,7 +252,7 @@ export function stringify( node, selectionOrPositionOrRange = null, options = {}
249
252
}
250
253
251
254
/**
252
- * Parses an HTML-like string and returns view tree nodes .
255
+ * Parses an HTML-like string and returns a view tree.
253
256
* A simple string will be converted to a {@link module:engine/view/text~Text text} node:
254
257
*
255
258
* parse( 'foobar' ); // Returns an instance of text.
0 commit comments