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 +53 -121
- 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,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
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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
|
-
|
|
164
|
+
This is by way of the `configuration` argument of the `fromContentAndConfiguration(...)` factory method...
|
|
164
165
|
|
|
165
166
|
```
|
|
166
|
-
const
|
|
167
|
+
const configuration = {
|
|
167
168
|
language: "json",
|
|
168
169
|
editable: true,
|
|
169
170
|
onCustomContentChange: coCustomntentChangeHandler
|
|
170
171
|
},
|
|
171
|
-
yapp = Yapp.
|
|
172
|
+
yapp = Yapp.fromContentAndConfiguration(` ... `, configuration);
|
|
172
173
|
```
|
|
173
|
-
|
|
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
|
-
|
|
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).
|
|
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
|
|
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="
|
|
222
|
-
<link rel="preload" href="
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
251
|
+
import { yappStyle, syntaxStyle, firaCodeStyle } from "yapp";
|
|
252
252
|
|
|
253
|
-
|
|
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
|
-
|
|
255
|
+
renderStyle(yappStyle);
|
|
270
256
|
|
|
271
|
-
|
|
257
|
+
renderStyle(syntaxStyle);
|
|
272
258
|
|
|
259
|
+
renderStyle(firaCodeStyle);
|
|
273
260
|
```
|
|
274
|
-
"use strict";
|
|
275
261
|
|
|
276
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
270
|
+
https://github.com/djalbat/yapp/blob/master/src/style/yapp.js
|
|
313
271
|
|
|
314
|
-
|
|
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
|
-
|
|
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
|
-
|
|
278
|
+
https://github.com/djalbat/yapp/blob/master/src/style/syntax.js
|
|
326
279
|
|
|
327
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
294
|
+
https://github.com/djalbat/yapp/blob/master/src/style/firaCode.js
|
|
346
295
|
|
|
347
|
-
|
|
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
|
-
|
|
298
|
+
```
|
|
299
|
+
"use strict";
|
|
350
300
|
|
|
351
|
-
|
|
301
|
+
import { renderYappStyles } from "yapp";
|
|
352
302
|
|
|
353
|
-
|
|
303
|
+
const host = "...";
|
|
354
304
|
|
|
355
|
-
|
|
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
|
-
|
|
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 `
|
|
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.
|