Skip to content

Commit

Permalink
Packages: Create new grammar package
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jul 2, 2018
1 parent a2e29d2 commit 6340d99
Show file tree
Hide file tree
Showing 15 changed files with 1,664 additions and 51 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ build
build-module
coverage
node_modules
packages/grammar
test/e2e/test-plugins
vendor
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ module.exports = {
selector: 'ImportDeclaration[source.value=/^element$/]',
message: 'Use @wordpress/element as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^grammar$/]',
message: 'Use @wordpress/element as import path instead.',
},
{
selector: 'ImportDeclaration[source.value=/^keycodes$/]',
message: 'Use @wordpress/keycodes as import path instead.',
Expand Down
2 changes: 1 addition & 1 deletion bin/create-php-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const phpegjs = require( 'phpegjs' );
const fs = require( 'fs' );
const path = require( 'path' );

const peg = fs.readFileSync( 'blocks/api/post.pegjs', 'utf8' );
const peg = fs.readFileSync( 'packages/grammar/gutenberg.pegjs', 'utf8' );

const parser = pegjs.generate(
peg,
Expand Down
2 changes: 1 addition & 1 deletion bin/generate-public-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const parser = require( '../node_modules/pegjs/lib/parser.js' );
const fs = require( 'fs' );
const path = require( 'path' );
const grammarSource = fs.readFileSync( './blocks/api/post.pegjs', 'utf8' );
const grammarSource = fs.readFileSync( './packages/grammar/gutenberg.pegjs', 'utf8' );
const grammar = parser.parse( grammarSource );

function escape( text ) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { flow, castArray, mapValues, omit } from 'lodash';
* WordPress dependencies
*/
import { autop } from '@wordpress/autop';
import { parse as grammarParse } from '@wordpress/grammar';
import { applyFilters } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import { parse as grammarParse } from './post.pegjs';
import { getBlockType, getUnknownTypeHandlerName } from './registration';
import { createBlock } from './factory';
import { isValidBlock } from './validation';
Expand Down
2 changes: 1 addition & 1 deletion core-blocks/test/full-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { format } from 'util';
* WordPress dependencies
*/
import { getBlockTypes, parse, serialize } from '@wordpress/blocks';
import { parse as grammarParse } from '@wordpress/grammar';

/**
* Internal dependencies
*/
import { registerCoreBlocks } from '../';
import { parse as grammarParse } from '../../blocks/api/post.pegjs';

const fixturesDir = path.join( __dirname, 'fixtures' );

Expand Down
26 changes: 3 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@wordpress/a11y": "1.0.6",
"@wordpress/autop": "1.0.4",
"@wordpress/dom-ready": "1.0.4",
"@wordpress/grammar": "file:packages/grammar",
"@wordpress/hooks": "1.1.6",
"@wordpress/i18n": "1.1.0",
"@wordpress/is-shallow-equal": "1.0.2",
Expand Down Expand Up @@ -89,7 +90,6 @@
"extract-text-webpack-plugin": "4.0.0-beta.0",
"node-sass": "git://github.com/sass/node-sass.git#v4.7.0",
"pegjs": "0.10.0",
"pegjs-loader": "0.5.4",
"phpegjs": "1.0.0-beta7",
"postcss-color-function": "4.0.1",
"postcss-loader": "2.1.3",
Expand Down
22 changes: 22 additions & 0 deletions packages/grammar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @wordpress/grammar

This library provides a grammar defining what kinds of content can be represented inside a WordPress content.

## Installation

Install the module

```bash
npm install @wordpress/grammar --save
```

## Usage

```js
import { parse } from '@wordpress/grammar';

parse( '<!-- wp:core/more --><!--more--><!-- /wp:core/more -->' );
// [{"attrs": null, "blockName": "core/more", "innerBlocks": [], "innerHTML": "<!--more-->"}]
```

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
File renamed without changes.
Loading

0 comments on commit 6340d99

Please sign in to comment.