usfm-grammar-web 3.2.0 → 3.2.1
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 +147 -9
- package/dist/bundle.mjs +756 -216
- package/dist/bundle.mjs.map +1 -1
- package/package.json +1 -1
- package/tree-sitter-usfm.wasm +0 -0
package/README.md
CHANGED
|
@@ -23,10 +23,10 @@ function App() {
|
|
|
23
23
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
const initParser = async () => {
|
|
26
|
-
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
27
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
28
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
29
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
26
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter-usfm.wasm",
|
|
27
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter.wasm");
|
|
28
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter-usfm.wasm",
|
|
29
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter.wasm");
|
|
30
30
|
|
|
31
31
|
};
|
|
32
32
|
initParser();
|
|
@@ -60,13 +60,13 @@ It can be used directly in the HTML script tag too. Please ensure its dependenci
|
|
|
60
60
|
|
|
61
61
|
```html
|
|
62
62
|
<script type="module">
|
|
63
|
-
import { USFMParser, Filter, Validator } from 'https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
63
|
+
import { USFMParser, Filter, Validator } from 'https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/dist/bundle.mjs';
|
|
64
64
|
console.log('Hello world');
|
|
65
65
|
(async () => {
|
|
66
|
-
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
67
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
68
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
69
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.
|
|
66
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter-usfm.wasm",
|
|
67
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter.wasm");
|
|
68
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter-usfm.wasm",
|
|
69
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter.wasm");
|
|
70
70
|
const usfmParser = new USFMParser('\\id GEN\n\\c 1\n\\p\n\\v 1 In the begining..\\v 2 more text')
|
|
71
71
|
const output = usfmParser.toUSJ()
|
|
72
72
|
console.log({ output })
|
|
@@ -237,6 +237,7 @@ The filtering on USJ, the JSON output, is a feature incorporated to allow data e
|
|
|
237
237
|
STUDY_BIBLE : \esb and \cat
|
|
238
238
|
BCV : \id, \c and \v
|
|
239
239
|
TEXT : 'text-in-excluded-parent'
|
|
240
|
+
ZNAMESPACES : all user-extended \z markers, as one group
|
|
240
241
|
```
|
|
241
242
|
To inspect which are the markers in each of these options, it could be just printed out, `print(Filter.TITLES)`. These could be used individually or concatinated to get the desired filtering of markers and data:
|
|
242
243
|
```javascript
|
|
@@ -254,6 +255,143 @@ The filtering on USJ, the JSON output, is a feature incorporated to allow data e
|
|
|
254
255
|
|
|
255
256
|
|
|
256
257
|
|
|
258
|
+
### User-extended markers (\z)
|
|
259
|
+
|
|
260
|
+
The USFM spec reserves markers beginning with `\z` for [user-defined extensions](https://docs.usfm.bible/usfm/3.1.2/extensions.html). usfm-grammar parses these, and represents them in USJ and USX using the type the extension belongs to. A `markers.ext` file can be supplied to declare which markers exist and what each one is, so that the output is what you expect. Without it, the type is guessed from how the marker is written.
|
|
261
|
+
|
|
262
|
+
- *Supplying a markers.ext*
|
|
263
|
+
|
|
264
|
+
`markersExt`, the sixth argument to the `USFMParser` constructor, takes the **contents** of the file, not its path. Supply it when parsing USFM; it is not needed, and should not be passed, when converting from USJ or USX.
|
|
265
|
+
```javascript
|
|
266
|
+
import {USFMParser, Filter} from 'usfm-grammar-web';
|
|
267
|
+
|
|
268
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter-usfm.wasm",
|
|
269
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.1/tree-sitter.wasm");
|
|
270
|
+
|
|
271
|
+
const myParser = new USFMParser(inputUsfm, null, null, null, null, markersExt);
|
|
272
|
+
const output = myParser.toUSJ();
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
- *The markers.ext file*
|
|
276
|
+
|
|
277
|
+
A plain text file, in a USFM-like syntax, with one block per extension marker. Blank lines separate the blocks.
|
|
278
|
+
```
|
|
279
|
+
\marker zheading
|
|
280
|
+
\category title
|
|
281
|
+
\description A custom section heading.
|
|
282
|
+
|
|
283
|
+
\marker zbadge
|
|
284
|
+
\category char
|
|
285
|
+
\description A custom character marker.
|
|
286
|
+
|
|
287
|
+
\marker zalign-s
|
|
288
|
+
\category milestone
|
|
289
|
+
\description A custom alignment milestone.
|
|
290
|
+
|
|
291
|
+
\marker znote
|
|
292
|
+
\category footnote
|
|
293
|
+
\description A custom note marker.
|
|
294
|
+
```
|
|
295
|
+
`\marker` and `\category` are the two fields that matter. `\description`, and any other field, is read but does not affect parsing. Only markers starting with `z` are accepted; a block declaring anything else is ignored.
|
|
296
|
+
|
|
297
|
+
- *Categories and the four major types*
|
|
298
|
+
|
|
299
|
+
`\category` must be one of the values below. Each maps onto one of four major types, and that major type is what decides how the marker is parsed and what it becomes in the output.
|
|
300
|
+
|
|
301
|
+
| Major type | `\category` values | USJ `type` | USX element |
|
|
302
|
+
| --- | --- | --- | --- |
|
|
303
|
+
| para | `para`, `header`, `title`, `introduction`, `section`, `versepara`, `list`, `otherpara` | `para` | `<para>` |
|
|
304
|
+
| char | `char`, `introchar`, `listchar`, `footnotechar`, `crossreferencechar` | `char` | `<char>` |
|
|
305
|
+
| note | `note`, `footnote`, `crossreference` | `note` | `<note>` |
|
|
306
|
+
| milestone | `milestone` | `ms` | `<ms>` |
|
|
307
|
+
|
|
308
|
+
A `\category` outside this list, or a block with no `\category` at all, raises an error.
|
|
309
|
+
|
|
310
|
+
:warning: Only the major type is used. The minor type, and the rules the spec attaches to it about where such a marker may occur, are not enforced — a declared extension marker is accepted anywhere in the document. So declaring `\category title` rather than `\category para` changes nothing about the output; both produce a `para`.
|
|
311
|
+
|
|
312
|
+
- *Expected syntax per major type*
|
|
313
|
+
|
|
314
|
+
Each major type has to be written the way the corresponding standard markers are written, otherwise parsing fails.
|
|
315
|
+
```
|
|
316
|
+
para \zheading A line of its own
|
|
317
|
+
char \zbadge inline content\zbadge* (closing marker required)
|
|
318
|
+
milestone \zalign-s\* or \zalign-s|x-strong="G25320"\*
|
|
319
|
+
note \znote + \zbadge note body\zbadge*\znote*
|
|
320
|
+
```
|
|
321
|
+
A note takes a caller as its first token, exactly like `\f` and `\x` do. Its body must be made of extension markers; plain text directly inside a note is not accepted.
|
|
322
|
+
|
|
323
|
+
- *What may appear inside an extension marker*
|
|
324
|
+
|
|
325
|
+
Within a user-extended marker, only other user-extended markers (`\z...`, or `\+z...` when nested) and custom attributes (`x-...`) are allowed. Markers from the common pool are not. So this parses:
|
|
326
|
+
```
|
|
327
|
+
\zbadge outer \+zbadge nested\+zbadge* text\zbadge*
|
|
328
|
+
\zbadge content|x-key="value"\zbadge*
|
|
329
|
+
```
|
|
330
|
+
and these are parsing errors:
|
|
331
|
+
```
|
|
332
|
+
\zbadge outer \nd Lord\nd* text\zbadge*
|
|
333
|
+
\zbadge content|lemma="value"\zbadge*
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
- *When no markers.ext is given*
|
|
337
|
+
|
|
338
|
+
The markers are still parsed, and the type is inferred from the syntax alone. A warning is recorded for each one, listing the node and suggesting that a markers.ext be supplied.
|
|
339
|
+
```
|
|
340
|
+
\zheading A line of its own -> para (no closing marker)
|
|
341
|
+
\zbadge inline\zbadge* -> char (closed with its own marker)
|
|
342
|
+
\zalign-s\* -> ms (closed with \*)
|
|
343
|
+
```
|
|
344
|
+
:warning: Notes cannot be told apart from character markers this way, since both are written as an opening marker closed by its own marker. An undeclared note-like marker is reported as `char`. Declare it in a markers.ext if you need it to come out as a `note`.
|
|
345
|
+
|
|
346
|
+
- *Filtering extension markers*
|
|
347
|
+
|
|
348
|
+
All `\z` markers are filtered as a single group, named `user-extension`, rather than one marker at a time. See the `ZNAMESPACES` option in [Filtering on USJ](#filtering-on-usj).
|
|
349
|
+
|
|
350
|
+
- *A worked example*
|
|
351
|
+
|
|
352
|
+
With this `markers.ext`
|
|
353
|
+
```
|
|
354
|
+
\marker zheading
|
|
355
|
+
\category title
|
|
356
|
+
\description A custom section heading.
|
|
357
|
+
|
|
358
|
+
\marker zbadge
|
|
359
|
+
\category char
|
|
360
|
+
\description A custom character marker.
|
|
361
|
+
|
|
362
|
+
\marker zalign-s
|
|
363
|
+
\category milestone
|
|
364
|
+
\description A custom alignment milestone.
|
|
365
|
+
```
|
|
366
|
+
this USFM
|
|
367
|
+
```
|
|
368
|
+
\id GEN
|
|
369
|
+
\c 1
|
|
370
|
+
\p
|
|
371
|
+
\v 1 Text with \zbadge inline content\zbadge* and more.
|
|
372
|
+
\zheading A line of its own
|
|
373
|
+
\v 2 Aligned \zalign-s|x-strong="G25320"\* text.
|
|
374
|
+
```
|
|
375
|
+
gives these USJ nodes
|
|
376
|
+
```json
|
|
377
|
+
{"type": "char", "content": [" inline content"], "marker": "zbadge"}
|
|
378
|
+
{"type": "para", "content": [" A line of its own\n"], "marker": "zheading"}
|
|
379
|
+
{"type": "ms", "content": [], "marker": "zalign-s", "x-strong": "G25320"}
|
|
380
|
+
```
|
|
381
|
+
and this USX
|
|
382
|
+
```xml
|
|
383
|
+
<usx version="3.1.2">
|
|
384
|
+
<book code="GEN" style="id"/>
|
|
385
|
+
<chapter number="1" style="c" sid="GEN 1"/>
|
|
386
|
+
<para style="p"><verse number="1" style="v" sid="GEN 1:1"/>Text with <char style="zbadge"> inline content</char> and more.
|
|
387
|
+
<para style="zheading"> A line of its own
|
|
388
|
+
</para><verse eid="GEN 1:1"/><verse number="2" style="v" sid="GEN 1:2"/>Aligned <ms style="zalign-s" x-strong="G25320"/> text.
|
|
389
|
+
<verse eid="GEN 1:2"/></para>
|
|
390
|
+
<chapter eid="GEN 1"/>
|
|
391
|
+
</usx>
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
|
|
257
395
|
## Contributing
|
|
258
396
|
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request on [GitHub](https://github.com/Bridgeconn/usfm-grammar).
|
|
259
397
|
|