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

Commit 6fc9964

Browse files
yangshunfacebook-github-bot
authored andcommitted
Prettify docs files (#2275)
Summary: **Summary** Prettier can also be used to format more than just JS files, it can format Markdown files too. Instead of using Flow parser for all files in `prettier.config.js`, we can just limit Flow parser for JS files and let Prettier find the default parsers for the various file formats. Hence I tweaked the Prettier config and added overrides for: - JS format - Use Flow parser - Markdown format - Restrict to 80 characters so that it's easier to read I then ran Prettier on all the docs. I've added a `prettier:diff` command into the `lint-docs` step, ran alongside with Alex that will fail when there are unformatted docs. It's not part of the CI step as I think that might be a bit too strict given that some people (including myself) edit docs in the GitHub UI and that might cause formatting issues which can be fixed by running the `format-docs` command every now and then. The formatting is only restricted to the docs now and not code as it's potentially dangerous to format code that gets synced with internal FB repos. **Test Plan** Load website. Pull Request resolved: #2275 Reviewed By: mrkev Differential Revision: D18807420 Pulled By: yangshun fbshipit-source-id: b3f34282c2a2cad8e89cd90e8f3f6b3860b747fc
1 parent 5d37c03 commit 6fc9964

23 files changed

+210
-191
lines changed

docs/APIReference-APIMigration.md

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ to the `ContentState` record.
1111

1212
This API improvement unlocks the path for many benefits that will be available in v0.11:
1313

14-
* DraftEntity instances and storage will be immutable.
15-
* DraftEntity will no longer be globally accessible.
16-
* Any changes to entity data will trigger a re-render.
14+
- DraftEntity instances and storage will be immutable.
15+
- DraftEntity will no longer be globally accessible.
16+
- Any changes to entity data will trigger a re-render.
1717

1818
## Quick Overview
1919

@@ -24,21 +24,15 @@ Here is a quick list of what has been changed and how to update your application
2424
**Old Syntax**
2525

2626
```js
27-
const entityKey = Entity.create(
28-
urlType,
29-
'IMMUTABLE',
30-
{src: urlValue},
31-
);
27+
const entityKey = Entity.create(urlType, 'IMMUTABLE', {src: urlValue});
3228
```
3329

3430
**New Syntax**
3531

3632
```js
37-
const contentStateWithEntity = contentState.createEntity(
38-
urlType,
39-
'IMMUTABLE',
40-
{src: urlValue},
41-
);
33+
const contentStateWithEntity = contentState.createEntity(urlType, 'IMMUTABLE', {
34+
src: urlValue,
35+
});
4236
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
4337
```
4438

@@ -65,7 +59,8 @@ const entityInstance = contentState.getEntity(entityKey);
6559
```js
6660
const compositeDecorator = new CompositeDecorator([
6761
{
68-
strategy: (contentBlock, callback) => exampleFindTextRange(contentBlock, callback),
62+
strategy: (contentBlock, callback) =>
63+
exampleFindTextRange(contentBlock, callback),
6964
component: ExampleTokenComponent,
7065
},
7166
]);
@@ -76,36 +71,31 @@ const compositeDecorator = new CompositeDecorator([
7671
```js
7772
const compositeDecorator = new CompositeDecorator([
7873
{
79-
strategy: (
80-
contentBlock,
81-
callback,
82-
contentState
83-
) => exampleFindTextRange(contentBlock, callback, contentState),
74+
strategy: (contentBlock, callback, contentState) => (
75+
contentBlock, callback, contentState
76+
),
8477
component: ExampleTokenComponent,
8578
},
8679
]);
8780
```
8881

8982
Note that ExampleTokenComponent will receive contentState as a prop.
9083

91-
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:
84+
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:
9285

9386
```js
9487
const mutableEntityStrategy = function(contentBlock, callback, contentState) {
95-
contentBlock.findEntityRanges(
96-
(character) => {
97-
const entityKey = character.getEntity();
98-
if (entityKey === null) {
99-
return false;
100-
}
101-
// To look for certain types of entities,
102-
// or entities with a certain mutability,
103-
// you may need to get the entity from contentState.
104-
// In this example we get only mutable entities.
105-
return contentState.getEntity(entityKey).getMutability() === 'MUTABLE';
106-
},
107-
callback,
108-
);
88+
contentBlock.findEntityRanges(character => {
89+
const entityKey = character.getEntity();
90+
if (entityKey === null) {
91+
return false;
92+
}
93+
// To look for certain types of entities,
94+
// or entities with a certain mutability,
95+
// you may need to get the entity from contentState.
96+
// In this example we get only mutable entities.
97+
return contentState.getEntity(entityKey).getMutability() === 'MUTABLE';
98+
}, callback);
10999
};
110100
```
111101

@@ -115,34 +105,25 @@ const mutableEntityStrategy = function(contentBlock, callback, contentState) {
115105

116106
```js
117107
function findLinkEntities(contentBlock, callback) {
118-
contentBlock.findEntityRanges(
119-
(character) => {
120-
const entityKey = character.getEntity();
121-
return (
122-
entityKey !== null &&
123-
Entity.get(entityKey).getType() === 'LINK'
124-
);
125-
},
126-
callback,
127-
);
128-
};
108+
contentBlock.findEntityRanges(character => {
109+
const entityKey = character.getEntity();
110+
return entityKey !== null && Entity.get(entityKey).getType() === 'LINK';
111+
}, callback);
112+
}
129113
```
130114

131115
**New Syntax**
132116

133117
```js
134118
function findLinkEntities(contentBlock, callback, contentState) {
135-
contentBlock.findEntityRanges(
136-
(character) => {
137-
const entityKey = character.getEntity();
138-
return (
139-
entityKey !== null &&
140-
contentState.getEntity(entityKey).getType() === 'LINK'
141-
);
142-
},
143-
callback,
144-
);
145-
};
119+
contentBlock.findEntityRanges(character => {
120+
const entityKey = character.getEntity();
121+
return (
122+
entityKey !== null &&
123+
contentState.getEntity(entityKey).getType() === 'LINK'
124+
);
125+
}, callback);
126+
}
146127
```
147128

148129
## More Information

docs/APIReference-CharacterMetadata.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ for information on how `CharacterMetadata` is used within `ContentBlock`.
2626

2727
## Overview
2828

29-
*Static Methods*
29+
_Static Methods_
3030

3131
<ul class="apiIndex">
3232
<li>
@@ -51,7 +51,7 @@ for information on how `CharacterMetadata` is used within `ContentBlock`.
5151
</li>
5252
</ul>
5353

54-
*Methods*
54+
_Methods_
5555

5656
<ul class="apiIndex">
5757
<li>

docs/APIReference-ContentBlock.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ title: ContentBlock
77
[Record](http://facebook.github.io/immutable-js/docs/#/Record/Record) that
88
represents the full state of a single block of editor content, including:
99

10-
- Plain text contents of the block
11-
- Type, e.g. paragraph, header, list item
12-
- Entity, inline style, and depth information
10+
- Plain text contents of the block
11+
- Type, e.g. paragraph, header, list item
12+
- Entity, inline style, and depth information
1313

1414
A `ContentState` object contains an `OrderedMap` of these `ContentBlock` objects,
1515
which together comprise the full contents of the editor.
1616

1717
`ContentBlock` objects are largely analogous to block-level HTML elements like
1818
paragraphs and list items. The available types are:
1919

20-
- unstyled
21-
- paragraph
22-
- header-one
23-
- header-two
24-
- header-three
25-
- header-four
26-
- header-five
27-
- header-six
28-
- unordered-list-item
29-
- ordered-list-item
30-
- blockquote
31-
- code-block
32-
- atomic
20+
- unstyled
21+
- paragraph
22+
- header-one
23+
- header-two
24+
- header-three
25+
- header-four
26+
- header-five
27+
- header-six
28+
- unordered-list-item
29+
- ordered-list-item
30+
- blockquote
31+
- code-block
32+
- atomic
3333

3434
New `ContentBlock` objects may be created directly using the constructor.
3535
Expected Record values are detailed below.
@@ -54,7 +54,7 @@ supplied text.
5454

5555
## Overview
5656

57-
*Methods*
57+
_Methods_
5858

5959
<ul class="apiIndex">
6060
<li>
@@ -114,7 +114,7 @@ supplied text.
114114
</li>
115115
</ul>
116116

117-
*Properties*
117+
_Properties_
118118

119119
> Note
120120
>
@@ -161,13 +161,15 @@ supplied text.
161161
```js
162162
getKey(): string
163163
```
164+
164165
Returns the string key for this `ContentBlock`. Block keys are alphanumeric string. It is recommended to use `generateRandomKey` to generate block keys.
165166

166167
### `getType()`
167168

168169
```js
169170
getType(): DraftBlockType
170171
```
172+
171173
Returns the type for this `ContentBlock`. Type values are largely analogous to
172174
block-level HTML elements.
173175

@@ -176,6 +178,7 @@ block-level HTML elements.
176178
```js
177179
getText(): string
178180
```
181+
179182
Returns the full plaintext for this `ContentBlock`. This value does not contain
180183
any styling, decoration, or HTML information.
181184

@@ -204,6 +207,7 @@ This value uses the standard JavaScript `length` property for the string, and is
204207
```js
205208
getDepth(): number
206209
```
210+
207211
Returns the depth value for this block, if any. This is currently used only for list items.
208212

209213
### `getInlineStyleAt()`

docs/APIReference-ContentState.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ objects.
1818

1919
## Overview
2020

21-
*Static Methods*
21+
_Static Methods_
2222

2323
<ul class="apiIndex">
2424
<li>
@@ -33,7 +33,7 @@ objects.
3333
</li>
3434
</ul>
3535

36-
*Methods*
36+
_Methods_
3737

3838
<ul class="apiIndex">
3939
<li>
@@ -138,7 +138,7 @@ objects.
138138
</li>
139139
</ul>
140140

141-
*Properties*
141+
_Properties_
142142

143143
> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Map) to
144144
> set properties.
@@ -148,7 +148,10 @@ objects.
148148
> ```js
149149
> const editorState = EditorState.createEmpty();
150150
> const contentState = editorState.getCurrentContent();
151-
> const contentStateWithSelectionBefore = contentState.set('selectionBefore', SelectionState.createEmpty(contentState.getBlockForKey('1pu4d')));
151+
> const contentStateWithSelectionBefore = contentState.set(
152+
> 'selectionBefore',
153+
> SelectionState.createEmpty(contentState.getBlockForKey('1pu4d')),
154+
> );
152155
> ```
153156
154157
<ul class="apiIndex">
@@ -205,7 +208,7 @@ getEntityMap(): EntityMap
205208
```
206209
207210
Returns an object store containing all `DraftEntity` records that have been
208-
created. In upcoming v0.11.0 the map returned will be an Immutable ordered map
211+
created. In upcoming v0.11.0 the map returned will be an Immutable ordered map
209212
of `DraftEntity` records.
210213
211214
In most cases, you should be able to use the convenience methods below to target

docs/APIReference-Data-Conversion.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Given a `ContentState` object, convert it to a raw JS structure. This is useful
4141
when saving an editor state for storage, conversion to other formats, or
4242
other usage within an application.
4343

44-
4544
### `convertFromHTML()`
4645

4746
```js
@@ -52,7 +51,7 @@ const sampleMarkup =
5251
const blocksFromHTML = convertFromHTML(sampleMarkup);
5352
const state = ContentState.createFromBlockArray(
5453
blocksFromHTML.contentBlocks,
55-
blocksFromHTML.entityMap
54+
blocksFromHTML.entityMap,
5655
);
5756

5857
this.state = {

docs/APIReference-Editor.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ See [API Basics](/docs/quickstart-api-basics) for an introduction.
1616
### `editorState`
1717

1818
```js
19-
editorState: EditorState
19+
editorState: EditorState;
2020
```
2121

2222
The `EditorState` object to be rendered by the `Editor`.
@@ -84,6 +84,7 @@ Optionally set a function to define custom block rendering. See [Advanced Topics
8484
```js
8585
blockRendererMap?: DraftBlockRenderMap
8686
```
87+
8788
Provide a map of block rendering configurations. Each block type maps to element tag and an optional react element wrapper. This configuration is used for both rendering and paste processing. See
8889
[Advanced Topics: Custom Block Rendering](/docs/advanced-topics-custom-block-render-map) for details on usage.
8990
@@ -248,7 +249,7 @@ handleBeforeInput?: (
248249
Handle the characters to be inserted from a `beforeInput` event. Returning `'handled'`
249250
causes the default behavior of the `beforeInput` event to be prevented (i.e. it is
250251
the same as calling the `preventDefault` method on the event).
251-
Example usage: After a user has typed `- ` at the start of a new block, you might
252+
Example usage: After a user has typed `-` at the start of a new block, you might
252253
convert that `ContentBlock` into an `unordered-list-item`.
253254
254255
At Facebook, we also use this to convert typed ASCII quotes into "smart" quotes,

0 commit comments

Comments
 (0)