yapp 5.0.8 → 5.0.11

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,7 +4,11 @@ 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.
7
+ Or see the Juxtapose site:
8
+
9
+ https://djalbat.com
10
+
11
+ Yapp in written using Juxtapose, by the way.
8
12
 
9
13
  ### Contents
10
14
 
@@ -17,15 +21,12 @@ Yet Another Pretty Printer.
17
21
  - [Styling Yapp](#styling-yapp)
18
22
  - [Plugins](#plugins)
19
23
  - [Building](#building)
20
- - [Contributions](#contributions)
21
24
  - [Acknowledgements](#acknowledgements)
22
25
  - [Contact](#contact)
23
26
 
24
27
  ## Introduction
25
28
 
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).
29
+ 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
30
 
30
31
  ## Installation
31
32
 
@@ -83,7 +84,7 @@ import Yapp from "yapp";
83
84
  import { renderYappStyles } from "yapp";
84
85
 
85
86
  const body = document.querySelector("body"),
86
- yapp = Yapp.fromContentAndOptions(` ... `, {});
87
+ yapp = Yapp.fromContentAndConfiguration(` ... `, {});
87
88
 
88
89
  renderYappStyles();
89
90
 
@@ -105,7 +106,7 @@ import { Body } from "easy";
105
106
  import { renderYappStyles } from "yapp";
106
107
 
107
108
  const body = new Body(),
108
- yapp = Yapp.fromContentAndOptions(` ... `, {});
109
+ yapp = Yapp.fromContentAndConfiguration(` ... `, {});
109
110
 
110
111
  renderYappStyles();
111
112
 
@@ -143,7 +144,7 @@ body.mount(
143
144
  ```
144
145
  Unless you plan to use Juxtapose to build your site, however, this may not be ideal.
145
146
 
146
- Note that in all of the three use cases above you must call the `renderYappStyles()` function before mounting any instance of Yapp.
147
+ Note that in all of the three use cases above you must call the `renderYappStyles()` function *before* mounting any instance of Yapp.
147
148
 
148
149
  ### Other considerations
149
150
 
@@ -160,17 +161,18 @@ rootDiv.mount(yapp);
160
161
 
161
162
  ## Configuration
162
163
 
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:
164
+ This is by way of the `configuration` argument of the `fromContentAndConfiguration(...)` factory method...
164
165
 
165
166
  ```
166
- const options = {
167
+ const configuration = {
167
168
  language: "json",
168
169
  editable: true,
169
170
  onCustomContentChange: coCustomntentChangeHandler
170
171
  },
171
- yapp = Yapp.fromContentAndOptions(` ... `, options);
172
+ yapp = Yapp.fromContentAndConfiguration(` ... `, configuration);
172
173
  ```
173
- When using JSX, the properties of the `options` parameter are in fact passed individually:
174
+
175
+ ...or by way of JSX attributes:
174
176
 
175
177
  ```
176
178
  <Yapp language="json" editable onCustomContentChange={coCustomntentChangeHandler} >{`
@@ -179,6 +181,7 @@ When using JSX, the properties of the `options` parameter are in fact passed ind
179
181
 
180
182
  `}</Yapp>
181
183
  ```
184
+
182
185
  If Yapp is made editable, the `coCustomntentChangeHandler(...)` callback should take the following form:
183
186
 
184
187
  ```
@@ -188,13 +191,12 @@ function coCustomntentChangeHandler(content) {
188
191
 
189
192
  }
190
193
  ```
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
194
 
193
- The only other option is the `firaCode` option, covered next.
195
+ 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
196
 
195
197
  ## Fira Code support
196
198
 
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:
199
+ 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
200
 
199
201
  ```
200
202
  <Yapp firaCode ... >{`
@@ -208,21 +210,22 @@ If you choose to enable Fira Code then you need to provide the necessary web fon
208
210
 
209
211
  ```
210
212
  @font-face {
211
- src: url("css/woff2/FiraCode-Light.woff2");
213
+ src: url("/css/woff2/FiraCode-Light.woff2");
212
214
  font-family: "Fira Code";
213
215
  font-weight: normal;
214
216
  }
215
217
  ```
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
218
 
218
- You can also preload the font files by putting the following in the header of the containing HTML page:
219
+ 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.
220
+
221
+ You can also preload the font files by putting something like the following in the header of the containing HTML page:
219
222
 
220
223
  ```
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 >
224
+ <link rel="preload" href="/css/woff2/FiraCode-Bold.woff2" as="font" type="font/woff2" crossorigin >
225
+ <link rel="preload" href="/css/woff2/FiraCode-Regular.woff2" as="font" type="font/woff2" crossorigin >
223
226
  ```
224
227
 
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.
228
+ 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
229
 
227
230
  ## Styling Yapp
228
231
 
@@ -236,133 +239,77 @@ import { renderYappStyles } from "yapp";
236
239
  renderYappStyles();
237
240
  ```
238
241
 
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.
242
+ 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
243
 
241
- ### Overall styles
242
-
243
- The following styles can be overridden. If you are using JSX then the best way is with programmatic styles:
244
+ 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
245
 
245
246
  ```
246
247
  "use strict";
247
248
 
248
- import Yapp from "yapp";
249
249
  import withStyle from "easy-with-style"; ///
250
250
 
251
- export default withStyle(Yapp)`
251
+ import { yappStyle, syntaxStyle, firaCodeStyle } from "yapp";
252
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;
265
-
266
- `;
267
- ```
253
+ const { renderStyle } = withStyle;
268
254
 
269
- Now simply import this class rather than the package's `Yapp` class.
255
+ renderStyle(yappStyle);
270
256
 
271
- If you are not using JSX then you can easily augment Yapp's styles by rendering a new style:
257
+ renderStyle(syntaxStyle);
272
258
 
259
+ renderStyle(firaCodeStyle);
273
260
  ```
274
- "use strict";
275
261
 
276
- import withStyle from "easy-with-style"; ///
262
+ 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.
277
263
 
278
- const { renderStyle } = withStyle;
279
-
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
- ```
264
+ We cover the three individual styles next.
299
265
 
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.
266
+ ### Overall styles
301
267
 
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"; ///
268
+ Here is the default overall style:
311
269
 
312
- const { renderStyle } = withStyle;
270
+ https://github.com/djalbat/yapp/blob/master/src/style/yapp.js
313
271
 
314
- renderStyle(`
272
+ 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
273
 
316
- .yaap > textarea::selection {
317
- color: white !important;
318
- background-color: orange !important;
319
- }
274
+ ### Syntax styles
320
275
 
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.
276
+ Here is the syntax style:
324
277
 
325
- ### Syntax styles
278
+ https://github.com/djalbat/yapp/blob/master/src/style/syntax.js
326
279
 
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.
280
+ 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
281
 
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:
282
+ 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
283
 
331
284
  ```
332
285
  .yapp .java.syntax > .keyword { color: #a93927; }
333
286
 
334
287
  .yapp .java.syntax > .string-literal { color: "#f5087a"; }
335
288
  ```
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
-
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:
339
289
 
340
- ```
341
- "use strict";
290
+ ### FiraCode styles
342
291
 
343
- import withStyle from "easy-with-style"; ///
292
+ If the paths of the web font files are different to the default then you may want to alter the FiraCode style:
344
293
 
345
- import { syntaxStyle, firaCodeStyle } from "yapp";
294
+ https://github.com/djalbat/yapp/blob/master/src/style/firaCode.js
346
295
 
347
- const { renderStyle, renderStyles } = withStyle;
296
+ 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...
348
297
 
349
- const host = "";
298
+ ```
299
+ "use strict";
350
300
 
351
- renderStyles(); // Always needed
301
+ import { renderYappStyles } from "yapp";
352
302
 
353
- renderStyle(syntaxStyle); // Leave this out if you wish.
303
+ const host = "...";
354
304
 
355
- renderStyle(firaCodeStyle(host)); // Only needed for Fira Code support.
305
+ renderYappStyles(host);
356
306
  ```
357
- 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.
358
-
359
- ### Hidden scrollbars and gutters, and fancy scrollbars
360
307
 
361
- 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.
308
+ ...which passes this down to the `firaCodeStyle()` function.
362
309
 
363
310
  ## Plugins
364
311
 
365
- 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.
312
+ 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.
366
313
 
367
314
  To begin to author your own plugin, follow these steps:
368
315
 
@@ -394,21 +341,6 @@ As well as building Yapp itself, this will build the examples. The source code f
394
341
 
395
342
  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.
396
343
 
397
- ## Contributions
398
-
399
- All development is best done in the context of the examples. There are three main areas that would benefit from contributions.
400
-
401
- 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.
402
-
403
- 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:
404
- - [`es6/style/syntax`](https://github.com/djalbat/yapp/tree/master/es6/style/syntax)
405
-
406
- 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:
407
- - [`es6/lexer/xml.js`](https://github.com/djalbat/yapp/blob/master/es6/lexer/xml.js)
408
- - [`es6/parser/xml.js`](https://github.com/djalbat/yapp/blob/master/es6/parser/xml.js)
409
-
410
- Contributions are best made in the form of pull requests.
411
-
412
344
  ## Acknowledgements
413
345
 
414
346
  * 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.