Skip to content

Commit

Permalink
autop: set up auto-generated API docs (#14287)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Mar 7, 2019
1 parent 6ead099 commit 032d96e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const childProcess = require( 'child_process' );

const packages = [
'a11y',
//'autop',
'autop',
'blob',
//'block-editor',
'block-library',
Expand Down
58 changes: 48 additions & 10 deletions packages/autop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,61 @@ npm install @wordpress/autop --save

_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._

### Usage
### API

Import the desired function(s) from `@wordpress/autop`:
<!-- START TOKEN(Autogenerated API docs) -->

#### autop

[src/index.js#L129-L285](src/index.js#L129-L285)

Replaces double line-breaks with paragraph elements.

A group of regex replaces used to identify text formatted with newlines and
replace double line-breaks with HTML paragraph tags. The remaining line-
breaks after conversion become `<br />` tags, unless br is set to 'false'.

**Usage**

```js
import { autop, removep } from '@wordpress/autop';
import { autop } from '@wordpress/autop';
autop( 'my text' ); // "<p>my text</p>"
```

**Parameters**

- **text** `string`: The text which has to be formatted.
- **br** `boolean`: Optional. If set, will convert all remaining line- breaks after paragraphing. Default true.

**Returns**

`string`: Text which has been converted into paragraph tags.

autop( 'my text' );
// "<p>my text</p>"
#### removep

removep( '<p>my text</p>' );
// "my text"
[src/index.js#L303-L426](src/index.js#L303-L426)

Replaces `<p>` tags with two line breaks. "Opposite" of autop().

Replaces `<p>` tags with two line breaks except where the `<p>` has attributes.
Unifies whitespace. Indents `<li>`, `<dt>` and `<dd>` for better readability.

**Usage**

```js
import { removep } from '@wordpress/autop';
removep( '<p>my text</p>' ); // "my text"
```

### API Usage
**Parameters**

- **html** `string`: The content from the editor.

**Returns**

`string`: The content with stripped paragraph tags.


* `autop( text: string ): string`
* `removep( text: string ): string`
<!-- END TOKEN(Autogenerated API docs) -->

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
14 changes: 14 additions & 0 deletions packages/autop/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ function replaceInHtmlTags( haystack, replacePairs ) {
* @param {string} text The text which has to be formatted.
* @param {boolean} br Optional. If set, will convert all remaining line-
* breaks after paragraphing. Default true.
*
* @example
*```js
* import { autop } from '@wordpress/autop';
* autop( 'my text' ); // "<p>my text</p>"
* ```
*
* @return {string} Text which has been converted into paragraph tags.
*/
export function autop( text, br = true ) {
Expand Down Expand Up @@ -284,6 +291,13 @@ export function autop( text, br = true ) {
* Unifies whitespace. Indents `<li>`, `<dt>` and `<dd>` for better readability.
*
* @param {string} html The content from the editor.
*
* @example
* ```js
* import { removep } from '@wordpress/autop';
* removep( '<p>my text</p>' ); // "my text"
* ```
*
* @return {string} The content with stripped paragraph tags.
*/
export function removep( html ) {
Expand Down

0 comments on commit 032d96e

Please sign in to comment.