yapp 5.0.10 → 5.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,8 +4,6 @@ Yet Another Pretty Printer.
4
4
 
5
5
  *If you just want to see Yapp in action without further ado*, then clone this repository, run `npm install` and `npm start`, and then open your browser at http://localhost:8888.
6
6
 
7
- *If you are interested in contributing to Yapp, in particular in contributing to its grammars*, then see the contributions section below.
8
-
9
7
  ### Contents
10
8
 
11
9
  - [Introduction](#introduction)
@@ -17,15 +15,12 @@ Yet Another Pretty Printer.
17
15
  - [Styling Yapp](#styling-yapp)
18
16
  - [Plugins](#plugins)
19
17
  - [Building](#building)
20
- - [Contributions](#contributions)
21
18
  - [Acknowledgements](#acknowledgements)
22
19
  - [Contact](#contact)
23
20
 
24
21
  ## Introduction
25
22
 
26
- Yapp is an advanced pretty printer and text editor. It has a powerful lexer and parser under the hood, and can process content after parsing in order to refine its appearance still further. The result is an experience that rivals the best open source and commercial editors. Yapp is also fully configurable. You can style it overall or target specific syntaxes. Its plugin architecture additionally makes it easy to support any language.
27
-
28
- Yapp also supports [Fira Code](https://github.com/tonsky/FiraCode).
23
+ Yapp is another pretty printer and a basic text editor. It has both a lexer and a parser under the hood, and can process content after parsing in order to refine its appearance still further. The result is an experience that rivals the best open source and commercial pretty printers. Yapp is also configurable. You can style it overall or target the syntax highlighting for specific languages. Its plugin architecture allows it to support additional languages. It also supports [Fira Code](https://github.com/tonsky/FiraCode).
29
24
 
30
25
  ## Installation
31
26
 
@@ -83,7 +78,7 @@ import Yapp from "yapp";
83
78
  import { renderYappStyles } from "yapp";
84
79
 
85
80
  const body = document.querySelector("body"),
86
- yapp = Yapp.fromContentAndOptions(` ... `, {});
81
+ yapp = Yapp.fromContentAndConfiguration(` ... `, {});
87
82
 
88
83
  renderYappStyles();
89
84
 
@@ -105,7 +100,7 @@ import { Body } from "easy";
105
100
  import { renderYappStyles } from "yapp";
106
101
 
107
102
  const body = new Body(),
108
- yapp = Yapp.fromContentAndOptions(` ... `, {});
103
+ yapp = Yapp.fromContentAndConfiguration(` ... `, {});
109
104
 
110
105
  renderYappStyles();
111
106
 
@@ -143,7 +138,7 @@ body.mount(
143
138
  ```
144
139
  Unless you plan to use Juxtapose to build your site, however, this may not be ideal.
145
140
 
146
- Note that in all of the three use cases above you must call the `renderYappStyles()` function before mounting any instance of Yapp.
141
+ Note that in all of the three use cases above you must call the `renderYappStyles()` function *before* mounting any instance of Yapp.
147
142
 
148
143
  ### Other considerations
149
144
 
@@ -160,17 +155,18 @@ rootDiv.mount(yapp);
160
155
 
161
156
  ## Configuration
162
157
 
163
- Yapp takes some parameters, These can be passed as arguments to the `fromContentAndOptions(...)` factory method or as attributes in the JSX. Intermediate arguments can be left as falsey when passing the latter arguments to the `fromContentAndOptions(...)` factory method:
158
+ This is by way of the `configuration` argument of the `fromContentAndConfiguration(...)` factory method...
164
159
 
165
160
  ```
166
- const options = {
161
+ const configuration = {
167
162
  language: "json",
168
163
  editable: true,
169
164
  onCustomContentChange: coCustomntentChangeHandler
170
165
  },
171
- yapp = Yapp.fromContentAndOptions(` ... `, options);
166
+ yapp = Yapp.fromContentAndConfiguration(` ... `, configuration);
172
167
  ```
173
- When using JSX, the properties of the `options` parameter are in fact passed individually:
168
+
169
+ ...or by way of JSX attributes:
174
170
 
175
171
  ```
176
172
  <Yapp language="json" editable onCustomContentChange={coCustomntentChangeHandler} >{`
@@ -179,6 +175,7 @@ When using JSX, the properties of the `options` parameter are in fact passed ind
179
175
 
180
176
  `}</Yapp>
181
177
  ```
178
+
182
179
  If Yapp is made editable, the `coCustomntentChangeHandler(...)` callback should take the following form:
183
180
 
184
181
  ```
@@ -188,13 +185,12 @@ function coCustomntentChangeHandler(content) {
188
185
 
189
186
  }
190
187
  ```
191
- Note that the second of the callback's arguments is a reference to the instance of Yapp, in case one is not available by other means. Note also that a `getContent()` method is supplied.
192
188
 
193
- The only other option is the `firaCode` option, covered next.
189
+ Note that the second of the callback's arguments is a reference to the instance of Yapp, in case one is not available by other means. Note also that a `getContent()` method is supplied.
194
190
 
195
191
  ## Fira Code support
196
192
 
197
- Yapp supports [Fira Code](https://github.com/tonsky/FiraCode). To enable it, add the `firaCode` option either to the `options` object if you are using the `fromContentAndOptions(...)` factory method or as an attribute if using JSX:
193
+ Yapp supports [Fira Code](https://github.com/tonsky/FiraCode). In order to enable it, either add a `firaCode` property set to `true` to the ' `configuration` object if you are using the `fromContentAndConfiguration(...)` factory method or add a `firaCode` boolean attribute if using JSX:
198
194
 
199
195
  ```
200
196
  <Yapp firaCode ... >{`
@@ -208,21 +204,22 @@ If you choose to enable Fira Code then you need to provide the necessary web fon
208
204
 
209
205
  ```
210
206
  @font-face {
211
- src: url("css/woff2/FiraCode-Light.woff2");
207
+ src: url("/css/woff2/FiraCode-Light.woff2");
212
208
  font-family: "Fira Code";
213
209
  font-weight: normal;
214
210
  }
215
211
  ```
216
- You do not have to provide this, rendering Yapp's styles will do so, but it is recommended that you check the network tab in your browser's developer tools to ensure that these files are being served.
217
212
 
218
- You can also preload the font files by putting the following in the header of the containing HTML page:
213
+ You do not have to provide this, rendering Yapp's styles will do so for you, but it is recommended that you check the network tab in your browser's developer tools to ensure that these files are being served.
214
+
215
+ You can also preload the font files by putting something like the following in the header of the containing HTML page:
219
216
 
220
217
  ```
221
- <link rel="preload" href="${host}/css/woff2/FiraCode-Bold.woff2" as="font" type="font/woff2" crossorigin >
222
- <link rel="preload" href="${host}/css/woff2/FiraCode-Regular.woff2" as="font" type="font/woff2" crossorigin >
218
+ <link rel="preload" href="/css/woff2/FiraCode-Bold.woff2" as="font" type="font/woff2" crossorigin >
219
+ <link rel="preload" href="/css/woff2/FiraCode-Regular.woff2" as="font" type="font/woff2" crossorigin >
223
220
  ```
224
221
 
225
- A `host` variable has been included here, the value of which should be the same as the `host` argument passed to the `firaCodeStyle()` function mentioned in the section on syntax styles further down. You may need to change the markup in the above snippet, depending on your templating library.
222
+ Note that both the path and the host of the URLs are assumed fixed in the snippets above but this may not be the case. Instructions on how to rectify this can be found in the section on styling Yapp that follows:
226
223
 
227
224
  ## Styling Yapp
228
225
 
@@ -236,135 +233,77 @@ import { renderYappStyles } from "yapp";
236
233
  renderYappStyles();
237
234
  ```
238
235
 
239
- Rendering the styles in this manner should always be done before any instance of Yapp is mounted, but only needs to be done once. If you do not want to alter Yapp's styles, either overall or for a particular syntax, then you never need to do any more than this.
236
+ Rendering the styles in this manner should always be done before any instance of Yapp is mounted, but only needs to be done once.
240
237
 
241
- ### Overall styles
242
-
243
- The following styles can be overridden. If you are using JSX then the best way is with programmatic styles:
238
+ If you do not want to alter Yapp's styles any further then you never need to do any more than this. On the other hand if you do want to make changes to Yapp's styles then you must eschew the `renderYappStyles()` function in favour of a more refined approach:
244
239
 
245
240
  ```
246
241
  "use strict";
247
242
 
248
- import Yapp from "yapp";
249
243
  import withStyle from "easy-with-style"; ///
250
244
 
251
- export default withStyle(Yapp)`
252
-
253
- border: 2px dotted;
254
-
255
- color: green;
256
- font-size: 14px;
257
- line-height: 20px;
258
- font-family: monospace;
259
- font-weight: bold;
260
- caret-color: white;
261
- border-color: yellow;
262
- text-rendering: initial;
263
- background-color: black;
264
- font-feature-settings: initial;
245
+ import { yappStyle, syntaxStyle, firaCodeStyle } from "yapp";
265
246
 
266
- `;
267
- ```
247
+ const { renderStyle } = withStyle;
268
248
 
269
- Now simply import this class rather than the package's `Yapp` class.
249
+ renderStyle(yappStyle);
270
250
 
271
- If you are not using JSX then you can easily augment Yapp's styles by rendering a new style:
251
+ renderStyle(syntaxStyle);
272
252
 
253
+ renderStyle(firaCodeStyle);
273
254
  ```
274
- "use strict";
275
-
276
- import withStyle from "easy-with-style"; ///
277
255
 
278
- const { renderStyle } = withStyle;
256
+ Now the `renderStyle()` function is being utilised to render each of Yapp's styles individually. This is pretty much all that the `renderYappStyles()` function, in fact.
279
257
 
280
- renderStyle(`
281
-
282
- .yapp {
283
- border: 2px dotted;
284
-
285
- color: green;
286
- font-size: 14px;
287
- line-height: 20px;
288
- font-family: monospace;
289
- font-weight: bold;
290
- caret-color: white;
291
- border-color: yellow;
292
- text-rendering: initial;
293
- background-color: black;
294
- font-feature-settings: initial;
295
- }
296
-
297
- `);
298
- ```
258
+ We cover the three individual styles next.
299
259
 
300
- Note that all of the above styles will be inherited by all of the child elements with the exception of the `border` style, which is only used at the topmost level; a few other sty3es such as the `background` style, which some child elements need to override. A little experimentation is recommended.
260
+ ### Overall styles
301
261
 
302
- ```
303
- .yaap > textarea::selection {
304
- color: white !important;
305
- background-color: orange !important;
306
- }
307
- ```
308
- This style can be applied either by way of your own CSS file or programmatically if you prefer:
309
- ```
310
- import withStyle from "easy-with-style"; ///
262
+ Here is the default overall style:
311
263
 
312
- const { renderStyle } = withStyle;
264
+ https://github.com/djalbat/yapp/blob/master/src/style/yapp.js
313
265
 
314
- renderStyle(`
266
+ If you want something different, simply copy this style and make the requisite changes. Or you can override specific styles by making use of CSS classes.
315
267
 
316
- .yaap > textarea::selection {
317
- color: white !important;
318
- background-color: orange !important;
319
- }
268
+ ### Syntax styles
320
269
 
321
- `);
322
- ```
323
- All the HTML elements of which Yapp is comprised have placeholder classes and can therefore be targeted in this way. To see these placeholder classes, simply have a look at an instance of Yapp in your browser's developer tools.
270
+ Here is the syntax style:
324
271
 
325
- ### Syntax styles
272
+ https://github.com/djalbat/yapp/blob/master/src/style/syntax.js
326
273
 
327
- How to approach styling Yapp's syntax broadly boils down to whether you want to set the style for the syntax of a new language, supported by a plugin that you supply, or to override the style for an existing language.
274
+ You can see that it is comprised of styles for three of the four languages that Yapp supports by default. There is no spefiic style for plain text. There is a default style, however.
328
275
 
329
- In the first instance, the approach can be the same as for overall styles, that is, you can supply a set of CSS properties that target the syntax elements either programmatically or in a CSS file. For example, if you have have a plugin for the Java language, then you could add the following style to go with it:
276
+ In a similar vein to the overall style you can either copy and completely replace syntax styles of override specific ones. For example, if you added support for the Java language then you might want to add something like the following to a new, Java-specific style:
330
277
 
331
278
  ```
332
279
  .yapp .java.syntax > .keyword { color: #a93927; }
333
280
 
334
281
  .yapp .java.syntax > .string-literal { color: "#f5087a"; }
335
282
  ```
336
- Bear in mind that a default syntax style that is applied, found in the [default.js](https://github.com/djalbat/yapp/blob/master/es6/style/syntax/default.js) file. You can override its individual CSS properties easily enough, however, because the specificity of your own style, given the additional language selector, will be greater.
337
283
 
338
- In the second instance, or if you want to remove the default style altogether rather than override it, the approach is to render Yapp's styles individually to give yourself the opportunity of leaving out specific ones:
284
+ ### FiraCode styles
339
285
 
340
- ```
341
- "use strict";
342
-
343
- import withStyle from "easy-with-style"; ///
344
-
345
- import { yappStyle, syntaxStyle, firaCodeStyle } from "yapp";
286
+ If the paths of the web font files are different to the default then you may want to alter the FiraCode style:
346
287
 
347
- const { renderStyle, renderStyles } = withStyle;
288
+ https://github.com/djalbat/yapp/blob/master/src/style/firaCode.js
348
289
 
349
- const host = "";
290
+ Note that it also takes a `host` argument. In fact if all you want to do is change the host then you can do this directly from the `renderYappStyles()` function...
350
291
 
351
- renderStyles();
292
+ ```
293
+ "use strict";
352
294
 
353
- renderStyle(yappStyle);
295
+ import { renderYappStyles } from "yapp";
354
296
 
355
- renderStyle(syntaxStyle);
297
+ const host = "...";
356
298
 
357
- renderStyle(firaCodeStyle(host)); // Only needed for Fira Code support.
299
+ renderYappStyles(host);
358
300
  ```
359
- In fact the above is just what the `renderYappStyles()` function does. In leaving out the syntax style, which includes the defaults, you have clean slate to work with.
360
-
361
- ### Hidden scrollbars and gutters, and fancy scrollbars
362
301
 
363
- You can hide the scrollbars and gutter with the `hiddenScrollbars` and `hiddenGutter` JSX attributes, respectively, and enable fancy scrollbars with the `fancyScrollbars` JSX attribute. These attributes can also be included as options. Fancy scrollbars have hidden tracks and thinner, rounded thumbs. They look something like old Mac scrollbars. Appearances will differ across browsers.
302
+ ...which passes this down to the `firaCodeStyle()` function.
364
303
 
365
304
  ## Plugins
366
305
 
367
- If you have been supplied with a plugin, or have written your own, it is straightforward to appraise Yapp of it by way of a property of the `options` argument of the `fromContentAndOptions(...)` factory method or as a JSX attribute. The remainder of this section covers authoring plugins. It assumes that you are able to build the examples, each of which corresponds to a built-in plugin. See the section on building later on for details.
306
+ If you have been supplied with a plugin, or have written your own, it is straightforward to appraise Yapp of it by way of a property of the `configuration` argument of the `fromContentAndConfiguration(...)` factory method or as a JSX attribute. The remainder of this section covers authoring plugins. It assumes that you are able to build the examples, each of which corresponds to a built-in plugin. See the section on building later on for details.
368
307
 
369
308
  To begin to author your own plugin, follow these steps:
370
309
 
@@ -396,21 +335,6 @@ As well as building Yapp itself, this will build the examples. The source code f
396
335
 
397
336
  If you wish to make use of live reloading while working on the examples, use `npm start` and the examples index page wll be available at http://localhost:8888.
398
337
 
399
- ## Contributions
400
-
401
- All development is best done in the context of the examples. There are three main areas that would benefit from contributions.
402
-
403
- 1. **Creating new plugins.** This is likely to a lot of work, however it should not be considered out of reach. See the plugins section above for more details.
404
-
405
- 2. **Work on the existing syntax styles.** There is no need to do any programming beyond changing the existing styles. The following files are relevant:
406
- - [`es6/style/syntax`](https://github.com/djalbat/yapp/tree/master/es6/style/syntax)
407
-
408
- 3. **Improving the grammars for existing languages.** This can also be done with virtually no programming at all, since both the lexical entries and BNF can be changed dynamically in the examples. Changes can then be copied to the requisite variables in the relevant lexer and parser files. For example for the XML grammar:
409
- - [`es6/lexer/xml.js`](https://github.com/djalbat/yapp/blob/master/es6/lexer/xml.js)
410
- - [`es6/parser/xml.js`](https://github.com/djalbat/yapp/blob/master/es6/parser/xml.js)
411
-
412
- Contributions are best made in the form of pull requests.
413
-
414
338
  ## Acknowledgements
415
339
 
416
340
  * The [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) and [Expressions and operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators) MDN articles were invaluable when writing the JavaScript grammar.