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 +48 -124
- package/example.js +254 -283
- package/lib/div/gutter.js +2 -2
- package/lib/div/lineNumbers.js +2 -2
- package/lib/div/pretty.js +2 -2
- package/lib/div/syntax.js +2 -2
- package/lib/example/yapp.js +6 -26
- package/lib/prettyPrinter.js +2 -2
- package/lib/renderYappStyles.js +2 -4
- package/lib/richTextarea.js +3 -13
- package/lib/style/firaCode.js +4 -2
- package/lib/style/yapp.js +3 -2
- package/lib/utilities/configuration.js +24 -0
- package/lib/yapp.js +7 -7
- package/package.json +1 -1
- package/src/div/gutter.js +0 -6
- package/src/div/lineNumbers.js +4 -10
- package/src/div/pretty.js +0 -4
- package/src/div/syntax.js +0 -4
- package/src/example/yapp.js +2 -8
- package/src/prettyPrinter.js +0 -4
- package/src/renderYappStyles.js +1 -3
- package/src/richTextarea.js +0 -35
- package/src/style/firaCode.js +3 -1
- package/src/style/yapp.js +52 -13
- package/src/utilities/{properties.js → configuration.js} +2 -2
- package/src/yapp.js +5 -5
- package/lib/utilities/properties.js +0 -24
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
|
|
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.
|
|
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.
|
|
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
|
-
|
|
158
|
+
This is by way of the `configuration` argument of the `fromContentAndConfiguration(...)` factory method...
|
|
164
159
|
|
|
165
160
|
```
|
|
166
|
-
const
|
|
161
|
+
const configuration = {
|
|
167
162
|
language: "json",
|
|
168
163
|
editable: true,
|
|
169
164
|
onCustomContentChange: coCustomntentChangeHandler
|
|
170
165
|
},
|
|
171
|
-
yapp = Yapp.
|
|
166
|
+
yapp = Yapp.fromContentAndConfiguration(` ... `, configuration);
|
|
172
167
|
```
|
|
173
|
-
|
|
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
|
-
|
|
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).
|
|
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
|
|
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="
|
|
222
|
-
<link rel="preload" href="
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
249
|
+
renderStyle(yappStyle);
|
|
270
250
|
|
|
271
|
-
|
|
251
|
+
renderStyle(syntaxStyle);
|
|
272
252
|
|
|
253
|
+
renderStyle(firaCodeStyle);
|
|
273
254
|
```
|
|
274
|
-
"use strict";
|
|
275
|
-
|
|
276
|
-
import withStyle from "easy-with-style"; ///
|
|
277
255
|
|
|
278
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
+
https://github.com/djalbat/yapp/blob/master/src/style/yapp.js
|
|
313
265
|
|
|
314
|
-
|
|
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
|
-
|
|
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
|
-
|
|
272
|
+
https://github.com/djalbat/yapp/blob/master/src/style/syntax.js
|
|
326
273
|
|
|
327
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
288
|
+
https://github.com/djalbat/yapp/blob/master/src/style/firaCode.js
|
|
348
289
|
|
|
349
|
-
|
|
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
|
-
|
|
292
|
+
```
|
|
293
|
+
"use strict";
|
|
352
294
|
|
|
353
|
-
|
|
295
|
+
import { renderYappStyles } from "yapp";
|
|
354
296
|
|
|
355
|
-
|
|
297
|
+
const host = "...";
|
|
356
298
|
|
|
357
|
-
|
|
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
|
-
|
|
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 `
|
|
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.
|