Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autop: set up auto-generated API docs #14287

Merged
merged 2 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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