Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 9b4a628

Browse files
yangshunfacebook-github-bot
authored andcommitted
Improve docs syntax and formatting (#2267)
Summary: **Summary** Reformat the docs in preparation for Docusaurus 2: - Add syntax highlighting for the code blocks - Remove `.html` from the Markdown link extensions. Docusaurus 1 allows clean URL but Docusaurus 2 doesn't, so this is necessary - Wrap API headings in code blocks - Change the level of some API headings so that they appear in the right table of contents **Test Plan** Run Docusaurus website locally and click through. Try it out - https://draft-js-pc0wv8qnv.now.sh Pull Request resolved: #2267 Reviewed By: claudiopro Differential Revision: D18758620 Pulled By: yangshun fbshipit-source-id: 73b9572e521cbf891abcf5099fec65f0cbef91d2
1 parent a1de5de commit 9b4a628

25 files changed

+615
-476
lines changed

docs/APIReference-APIMigration.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Here is a quick list of what has been changed and how to update your application
2323

2424
**Old Syntax**
2525

26-
```
26+
```js
2727
const entityKey = Entity.create(
2828
urlType,
2929
'IMMUTABLE',
@@ -33,7 +33,7 @@ const entityKey = Entity.create(
3333

3434
**New Syntax**
3535

36-
```
36+
```js
3737
const contentStateWithEntity = contentState.createEntity(
3838
urlType,
3939
'IMMUTABLE',
@@ -46,14 +46,14 @@ const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
4646

4747
**Old Syntax**
4848

49-
```
49+
```js
5050
const entityInstance = Entity.get(entityKey);
5151
// entityKey is a string key associated with that entity when it was created
5252
```
5353

5454
**New Syntax**
5555

56-
```
56+
```js
5757
const entityInstance = contentState.getEntity(entityKey);
5858
// entityKey is a string key associated with that entity when it was created
5959
```
@@ -62,7 +62,7 @@ const entityInstance = contentState.getEntity(entityKey);
6262

6363
**Old Syntax**
6464

65-
```
65+
```js
6666
const compositeDecorator = new CompositeDecorator([
6767
{
6868
strategy: (contentBlock, callback) => exampleFindTextRange(contentBlock, callback),
@@ -73,7 +73,7 @@ const compositeDecorator = new CompositeDecorator([
7373

7474
**New Syntax**
7575

76-
```
76+
```js
7777
const compositeDecorator = new CompositeDecorator([
7878
{
7979
strategy: (
@@ -90,7 +90,7 @@ Note that ExampleTokenComponent will receive contentState as a prop.
9090

9191
Why does the 'contentState' get passed into the decorator strategy now? Because we may need it if our strategy is to find certain entities in the contentBlock:
9292

93-
```
93+
```js
9494
const mutableEntityStrategy = function(contentBlock, callback, contentState) {
9595
contentBlock.findEntityRanges(
9696
(character) => {
@@ -113,7 +113,7 @@ const mutableEntityStrategy = function(contentBlock, callback, contentState) {
113113

114114
**Old Syntax**
115115

116-
```
116+
```js
117117
function findLinkEntities(contentBlock, callback) {
118118
contentBlock.findEntityRanges(
119119
(character) => {
@@ -130,7 +130,7 @@ function findLinkEntities(contentBlock, callback) {
130130

131131
**New Syntax**
132132

133-
```
133+
```js
134134
function findLinkEntities(contentBlock, callback, contentState) {
135135
contentBlock.findEntityRanges(
136136
(character) => {

docs/APIReference-AtomicBlockUtils.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ parameters and return `EditorState` objects.
1111

1212
## Static Methods
1313

14-
### insertAtomicBlock
14+
### `insertAtomicBlock()`
1515

16-
```
16+
```js
1717
insertAtomicBlock: function(
1818
editorState: EditorState,
1919
entityKey: string,
2020
character: string
2121
): EditorState
2222
```
2323

24-
### moveAtomicBlock
24+
### `moveAtomicBlock()`
2525

26-
```
26+
```js
2727
moveAtomicBlock: function(
2828
editorState: EditorState,
2929
atomicBlock: ContentBlock,

docs/APIReference-CharacterMetadata.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ operations are already implemented and available via utility modules. The getter
2121
methods, however, may come in handy at render time.
2222

2323
See the API reference on
24-
[ContentBlock](/docs/api-reference-content-block.html#representing-styles-and-entities)
24+
[ContentBlock](/docs/api-reference-content-block#representing-styles-and-entities)
2525
for information on how `CharacterMetadata` is used within `ContentBlock`.
2626

2727
## Overview
@@ -76,11 +76,12 @@ for information on how `CharacterMetadata` is used within `ContentBlock`.
7676
Under the hood, these methods will utilize pooling to return a matching object,
7777
or return a new object if none exists.
7878

79-
### create
79+
### `create()`
8080

81-
```
81+
```js
8282
static create(config?: CharacterMetadataConfig): CharacterMetadata
8383
```
84+
8485
Generates a `CharacterMetadata` object from the provided configuration. This
8586
function should be used in lieu of a constructor.
8687

@@ -89,29 +90,31 @@ configuration already exists. If so, the pooled object will be returned.
8990
Otherwise, a new `CharacterMetadata` will be pooled for this configuration,
9091
and returned.
9192

92-
### applyStyle
93+
### `applyStyle()`
9394

94-
```
95+
```js
9596
static applyStyle(
9697
record: CharacterMetadata,
9798
style: string
9899
): CharacterMetadata
99100
```
101+
100102
Apply an inline style to this `CharacterMetadata`.
101103

102-
### removeStyle
104+
### `removeStyle()`
103105

104-
```
106+
```js
105107
static removeStyle(
106108
record: CharacterMetadata,
107109
style: string
108110
): CharacterMetadata
109111
```
112+
110113
Remove an inline style from this `CharacterMetadata`.
111114

112-
### applyEntity
115+
### `applyEntity()`
113116

114-
```
117+
```js
115118
static applyEntity(
116119
record: CharacterMetadata,
117120
entityKey: ?string
@@ -123,26 +126,29 @@ Apply an entity key -- or provide `null` to remove an entity key -- on this
123126
124127
## Methods
125128
126-
### getStyle
129+
### `getStyle()`
127130
128-
```
131+
```js
129132
getStyle(): DraftInlineStyle
130133
```
134+
131135
Returns the `DraftInlineStyle` for this character, an `OrderedSet` of strings
132136
that represents the inline style to apply for the character at render time.
133137
134-
### hasStyle
138+
### `hasStyle()`
135139
136-
```
140+
```js
137141
hasStyle(style: string): boolean
138142
```
143+
139144
Returns whether this character has the specified style.
140145
141-
### getEntity
146+
### `getEntity()`
142147
143-
```
148+
```js
144149
getEntity(): ?string
145150
```
151+
146152
Returns the entity key (if any) for this character, as mapped to the global set of
147153
entities tracked by the [`Entity`](https://github.com/facebook/draft-js/blob/master/src/model/entity/DraftEntity.js)
148154
module.

docs/APIReference-CompositeDecorator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ title: CompositeDecorator
55

66
## Advanced Topic Article
77

8-
See the [advanced topic article on Decorators](/docs/advanced-topics-decorators.html#compositedecorator).
8+
See the [advanced topic article on Decorators](/docs/advanced-topics-decorators#compositedecorator).

docs/APIReference-ContentBlock.md

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -156,103 +156,101 @@ supplied text.
156156

157157
## Methods
158158

159-
### getKey()
159+
### `getKey()`
160160

161-
```
161+
```js
162162
getKey(): string
163163
```
164164
Returns the string key for this `ContentBlock`. Block keys are alphanumeric string. It is recommended to use `generateRandomKey` to generate block keys.
165165

166-
### getType()
166+
### `getType()`
167167

168-
```
168+
```js
169169
getType(): DraftBlockType
170170
```
171171
Returns the type for this `ContentBlock`. Type values are largely analogous to
172172
block-level HTML elements.
173173

174-
### getText()
174+
### `getText()`
175175

176-
```
176+
```js
177177
getText(): string
178178
```
179179
Returns the full plaintext for this `ContentBlock`. This value does not contain
180180
any styling, decoration, or HTML information.
181181

182-
### getCharacterList()
182+
### `getCharacterList()`
183183

184-
```
184+
```js
185185
getCharacterList(): List<CharacterMetadata>
186186
```
187-
Returns an immutable `List` of `CharacterMetadata` objects, one for each
188-
character in the `ContentBlock`. (See [CharacterMetadata](/docs/api-reference-character-metadata.html)
189-
for details.)
187+
188+
Returns an immutable `List` of `CharacterMetadata` objects, one for each character in the `ContentBlock`. (See [CharacterMetadata](/docs/api-reference-character-metadata) for details.)
190189

191190
This `List` contains all styling and entity information for the block.
192191

193-
### getLength()
192+
### `getLength()`
194193

195-
```
194+
```js
196195
getLength(): number
197196
```
197+
198198
Returns the length of the plaintext for the `ContentBlock`.
199199

200-
This value uses the standard JavaScript `length` property for the string, and
201-
is therefore not Unicode-aware -- surrogate pairs will be counted as two
202-
characters.
200+
This value uses the standard JavaScript `length` property for the string, and is therefore not Unicode-aware -- surrogate pairs will be counted as two characters.
203201

204-
### getDepth()
202+
### `getDepth()`
205203

206-
```
204+
```js
207205
getDepth(): number
208206
```
209-
Returns the depth value for this block, if any. This is currently used only
210-
for list items.
207+
Returns the depth value for this block, if any. This is currently used only for list items.
211208

212-
### getInlineStyleAt()
209+
### `getInlineStyleAt()`
213210

214-
```
211+
```js
215212
getInlineStyleAt(offset: number): DraftInlineStyle
216213
```
217-
Returns the `DraftInlineStyle` value (an `OrderedSet<string>`) at a given offset
218-
within this `ContentBlock`.
219214

220-
### getEntityAt()
215+
Returns the `DraftInlineStyle` value (an `OrderedSet<string>`) at a given offset within this `ContentBlock`.
221216

222-
```
217+
### `getEntityAt()`
218+
219+
```js
223220
getEntityAt(offset: number): ?string
224221
```
225-
Returns the entity key value (or `null` if none) at a given offset within this
226-
`ContentBlock`.
227222
228-
### getData()
223+
Returns the entity key value (or `null` if none) at a given offset within this `ContentBlock`.
229224
230-
```
225+
### `getData()`
226+
227+
```js
231228
getData(): Map<any, any>
232229
```
230+
233231
Returns block-level metadata.
234232

235-
### findStyleRanges()
233+
### `findStyleRanges()`
236234

237-
```
235+
```js
238236
findStyleRanges(
239237
filterFn: (value: CharacterMetadata) => boolean,
240238
callback: (start: number, end: number) => void
241239
): void
242240
```
243-
Executes a callback for each contiguous range of styles within this
244-
`ContentBlock`.
245241

246-
### findEntityRanges()
242+
Executes a callback for each contiguous range of styles within this `ContentBlock`.
247243

248-
```
244+
### `findEntityRanges()`
245+
246+
```js
249247
findEntityRanges(
250248
filterFn: (value: CharacterMetadata) => boolean,
251249
callback: (start: number, end: number) => void
252250
): void
253251
```
254-
Executes a callback for each contiguous range of entities within this
255-
`ContentBlock`.
252+
253+
Executes a callback for each contiguous range of entities within this `ContentBlock`.
256254

257255
## Properties
258256

@@ -261,20 +259,26 @@ Executes a callback for each contiguous range of entities within this
261259
> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Map)
262260
> for the `ContentBlock` constructor or to set properties.
263261
264-
### key
262+
### `key`
263+
265264
See `getKey()`.
266265

267-
### text
266+
### `text`
267+
268268
See `getText()`.
269269

270-
### type
270+
### `type`
271+
271272
See `getType()`.
272273

273-
### characterList
274+
### `characterList`
275+
274276
See `getCharacterList()`.
275277

276-
### depth
278+
### `depth`
279+
277280
See `getDepth()`.
278281

279-
### data
282+
### `data`
283+
280284
See `getData()`.

0 commit comments

Comments
 (0)