usfm-grammar-web 3.2.0-beta.1 → 3.2.0-beta.3
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 +9 -9
- package/dist/bundle.mjs +11 -13
- 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.0-beta.
|
|
27
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
28
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
29
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
26
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter-usfm.wasm",
|
|
27
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter.wasm");
|
|
28
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter-usfm.wasm",
|
|
29
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/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.0-beta.
|
|
63
|
+
import { USFMParser, Filter, Validator } from 'https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/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.0-beta.
|
|
67
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
68
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
69
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.
|
|
66
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter-usfm.wasm",
|
|
67
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter.wasm");
|
|
68
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/tree-sitter-usfm.wasm",
|
|
69
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.2.0-beta.3/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 })
|
package/dist/bundle.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as $5OpyM$fspromises from "fs/promises";
|
|
2
2
|
import * as $5OpyM$module from "module";
|
|
3
|
-
import $5OpyM$assert from "assert";
|
|
4
3
|
import {DOMImplementation as $5OpyM$DOMImplementation} from "xmldom";
|
|
5
4
|
import $5OpyM$ajv from "ajv";
|
|
6
5
|
|
|
@@ -3468,7 +3467,6 @@ module.exports = new URL("tree-sitter.0080292a.wasm", import.meta.url).toString(
|
|
|
3468
3467
|
});
|
|
3469
3468
|
|
|
3470
3469
|
|
|
3471
|
-
|
|
3472
3470
|
var $dc2P8 = parcelRequire("dc2P8");
|
|
3473
3471
|
const $142605215cbb4f88$export$b32929182cc4fefe = [
|
|
3474
3472
|
'USJ',
|
|
@@ -3834,7 +3832,8 @@ const $28b0061e56e1edf2$export$af42bd8f70df8555 = [
|
|
|
3834
3832
|
'th',
|
|
3835
3833
|
'tcr',
|
|
3836
3834
|
'thr',
|
|
3837
|
-
'tcc'
|
|
3835
|
+
'tcc',
|
|
3836
|
+
'thc'
|
|
3838
3837
|
];
|
|
3839
3838
|
const $28b0061e56e1edf2$export$c4d2f24f22330b2a = [
|
|
3840
3839
|
'fig',
|
|
@@ -4099,7 +4098,7 @@ class $1bdca1468aa54399$var$USJGenerator {
|
|
|
4099
4098
|
// Build USJ nodes for character markups, both regular and nested
|
|
4100
4099
|
const tagNode = node.children[0];
|
|
4101
4100
|
let childrenRange = node.children.length;
|
|
4102
|
-
|
|
4101
|
+
for(let i = node.children.length - 1; i > 0; i--)if (node.children[i].type.startsWith('\\') || node.children[i].type === '*' || node.children[i].type.endsWith('Tag')) childrenRange -= 1;
|
|
4103
4102
|
const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace('\\', '').replace('+', '').trim();
|
|
4104
4103
|
const charJsonObj = {
|
|
4105
4104
|
type: 'char',
|
|
@@ -4139,7 +4138,7 @@ class $1bdca1468aa54399$var$USJGenerator {
|
|
|
4139
4138
|
type: 'table:cell',
|
|
4140
4139
|
marker: style,
|
|
4141
4140
|
content: [],
|
|
4142
|
-
align: style.includes('tcc') ? 'center' : style.includes('r') ? 'end' : 'start'
|
|
4141
|
+
align: style.includes('tcc') || style.includes('thc') ? 'center' : style.includes('r') ? 'end' : 'start'
|
|
4143
4142
|
};
|
|
4144
4143
|
node.children.slice(1).forEach((child)=>{
|
|
4145
4144
|
this.nodeToUSJ(child, cellJsonObj);
|
|
@@ -4701,7 +4700,7 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
4701
4700
|
// Build USJ nodes for character markups, both regular and nested
|
|
4702
4701
|
const tagNode = node.children[0];
|
|
4703
4702
|
let childrenRange = node.children.length;
|
|
4704
|
-
|
|
4703
|
+
for(let i = node.children.length - 1; i > 0; i--)if (node.children[i].type.startsWith('\\') || node.children[i].type === '*' || node.children[i].type.endsWith('Tag')) childrenRange -= 1;
|
|
4705
4704
|
const charXmlNode = parentXmlNode.ownerDocument.createElement('char');
|
|
4706
4705
|
const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace('\\', '').replace('+', '').trim();
|
|
4707
4706
|
charXmlNode.setAttribute('style', style);
|
|
@@ -4745,7 +4744,7 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
4745
4744
|
const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace('\\', '').trim();
|
|
4746
4745
|
const cellXmlNode = parentXmlNode.ownerDocument.createElement('cell');
|
|
4747
4746
|
cellXmlNode.setAttribute('style', style);
|
|
4748
|
-
cellXmlNode.setAttribute('align', style.includes('tcc') ? 'center' : style.includes('r') ? 'end' : 'start');
|
|
4747
|
+
cellXmlNode.setAttribute('align', style.includes('tcc') || style.includes('thc') ? 'center' : style.includes('r') ? 'end' : 'start');
|
|
4749
4748
|
parentXmlNode.appendChild(cellXmlNode);
|
|
4750
4749
|
node.children.slice(1).forEach((child)=>{
|
|
4751
4750
|
this.node2Usx(child, cellXmlNode);
|
|
@@ -47147,9 +47146,9 @@ Only one of USFM, USJ, USX or BibleNLP is supported in one object.`);
|
|
|
47147
47146
|
}
|
|
47148
47147
|
convertUSXToUSFM() {
|
|
47149
47148
|
try {
|
|
47150
|
-
|
|
47149
|
+
if (!(1 <= this.usx.nodeType && this.usx.nodeType <= 12)) throw new Error('Input must be an instance of xmldom Document or Element');
|
|
47151
47150
|
if (this.usx.tagName !== 'usx') {
|
|
47152
|
-
|
|
47151
|
+
if (!(this.usx.getElementsByTagName('usx').length === 1)) throw new Error(`Expects a <usx> node.
|
|
47153
47152
|
Refer docs: https://docs.usfm.bible/usfm/3.1/syntax.html#_usx_usfm_xml`);
|
|
47154
47153
|
this.usx = this.usx.getElementsByTagName('usx')[0];
|
|
47155
47154
|
}
|
|
@@ -47206,10 +47205,9 @@ Refer docs: https://docs.usfm.bible/usfm/3.1/syntax.html#_usx_usfm_xml`);
|
|
|
47206
47205
|
}
|
|
47207
47206
|
convertBibleNLPtoUSFM(bookCode) {
|
|
47208
47207
|
try {
|
|
47209
|
-
(
|
|
47210
|
-
|
|
47211
|
-
|
|
47212
|
-
(0, $5OpyM$assert)(Array.isArray(this.bibleNlp.text), "'text' should contain an array of strings.");
|
|
47208
|
+
if (typeof this.bibleNlp !== 'object' || this.bibleNlp === null) throw new Error('Input must be a non-null object');
|
|
47209
|
+
if (!this.bibleNlp.hasOwnProperty('vref') || !this.bibleNlp.hasOwnProperty('text')) throw new Error("Input object must have 'vref' and 'text' properties");
|
|
47210
|
+
if (!Array.isArray(this.bibleNlp.vref) || !Array.isArray(this.bibleNlp.text) || this.bibleNlp.vref.length === 0 || this.bibleNlp.text.length === 0) throw new Error("'vref' and 'text' properties must be non empty arrays!");
|
|
47213
47211
|
let vrefs = this.bibleNlp.vref;
|
|
47214
47212
|
if ([
|
|
47215
47213
|
31170,
|