Skip to content

Commit

Permalink
Set up auto-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Mar 6, 2019
1 parent 9bc7d09 commit 02a1101
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 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
36 changes: 18 additions & 18 deletions packages/autop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ 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

Import the desired function(s) from `@wordpress/autop`:

```js
import { autop, removep } from '@wordpress/autop';

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

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

### API

<!-- START TOKEN(Autogenerated API docs) -->

#### autop

[src/index.js#L122-L278](src/index.js#L122-L278)
[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 } 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.
`string`: Text which has been converted into paragraph tags.

#### removep

[src/index.js#L289-L412](src/index.js#L289-L412)
[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"
```

**Parameters**

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

**Returns**

`string` The content with stripped paragraph tags.
`string`: The content with stripped paragraph tags.


<!-- END TOKEN(Autogenerated API docs) -->
Expand Down
6 changes: 0 additions & 6 deletions packages/autop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
"dependencies": {
"@babel/runtime": "^7.3.1"
},
"devDependencies": {
"@wordpress/docgen": "file:../docgen"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"docs:generate": "docgen ./src/index.js --output ./README.md --to-token"
}
}
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 02a1101

Please sign in to comment.