usfm-grammar-web 3.1.1 → 3.1.2
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 +21 -42
- 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.1.
|
|
27
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
28
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
29
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
26
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter-usfm.wasm",
|
|
27
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter.wasm");
|
|
28
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter-usfm.wasm",
|
|
29
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/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.1.
|
|
63
|
+
import { USFMParser, Filter, Validator } from 'https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/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.1.
|
|
67
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
68
|
-
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
69
|
-
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.
|
|
66
|
+
await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter-usfm.wasm",
|
|
67
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter.wasm");
|
|
68
|
+
await Validator.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/tree-sitter-usfm.wasm",
|
|
69
|
+
"https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.1.2/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
|
@@ -2012,7 +2012,8 @@ const $28b0061e56e1edf2$export$af42bd8f70df8555 = [
|
|
|
2012
2012
|
"tc",
|
|
2013
2013
|
"th",
|
|
2014
2014
|
"tcr",
|
|
2015
|
-
"thr"
|
|
2015
|
+
"thr",
|
|
2016
|
+
"tcc"
|
|
2016
2017
|
];
|
|
2017
2018
|
const $28b0061e56e1edf2$export$c4d2f24f22330b2a = [
|
|
2018
2019
|
"fig",
|
|
@@ -2239,7 +2240,7 @@ class $1bdca1468aa54399$var$USJGenerator {
|
|
|
2239
2240
|
type: "table:cell",
|
|
2240
2241
|
marker: style,
|
|
2241
2242
|
content: [],
|
|
2242
|
-
align: style.includes("r") ? "end" : "start"
|
|
2243
|
+
align: style.includes("tcc") ? "center" : style.includes("r") ? "end" : "start"
|
|
2243
2244
|
};
|
|
2244
2245
|
node.children.slice(1).forEach((child)=>{
|
|
2245
2246
|
this.nodeToUSJ(child, cellJsonObj);
|
|
@@ -2534,6 +2535,10 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
2534
2535
|
this.xmlRootNode = doc.documentElement;
|
|
2535
2536
|
this.xmlRootNode.setAttribute('version', '3.1');
|
|
2536
2537
|
} else this.xmlRootNode = usxRootElement;
|
|
2538
|
+
this.parseState = {
|
|
2539
|
+
prevVerseSid: null,
|
|
2540
|
+
prevVerseParent: null
|
|
2541
|
+
};
|
|
2537
2542
|
}
|
|
2538
2543
|
/**
|
|
2539
2544
|
* Builds the ID node in USX
|
|
@@ -2607,42 +2612,13 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
2607
2612
|
} else parentXmlNode.appendChild(vEndXmlNode);
|
|
2608
2613
|
}
|
|
2609
2614
|
}
|
|
2610
|
-
findPrevUncle(parentXmlNode) {
|
|
2611
|
-
// Get the grandparent node
|
|
2612
|
-
const grandParent = parentXmlNode.parentNode;
|
|
2613
|
-
let uncleIndex = grandParent.childNodes.length - 2; // Start from the previous sibling
|
|
2614
|
-
while(uncleIndex >= 0){
|
|
2615
|
-
const uncle = grandParent.childNodes[uncleIndex];
|
|
2616
|
-
// Skip 'sidebar' and 'ms' elements
|
|
2617
|
-
if (uncle.tagName === "sidebar" || uncle.tagName === "ms") uncleIndex--;
|
|
2618
|
-
else if (uncle.getAttribute('style') === 'ca' || uncle.getAttribute('style') === 'cp') uncleIndex--;
|
|
2619
|
-
else return uncle;
|
|
2620
|
-
}
|
|
2621
|
-
return null; // No suitable uncle found
|
|
2622
|
-
}
|
|
2623
2615
|
node2UsxVerse(node, parentXmlNode) {
|
|
2624
|
-
//
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
// If there is verse text in the current parent
|
|
2631
|
-
vEndXmlNode = parentXmlNode.ownerDocument.createElement('verse');
|
|
2632
|
-
parentXmlNode.appendChild(vEndXmlNode);
|
|
2633
|
-
} else {
|
|
2634
|
-
// If no text, find the previous uncle and attach the end verse
|
|
2635
|
-
const prevUncle = this.findPrevUncle(parentXmlNode);
|
|
2636
|
-
if (prevUncle.tagName === "para") {
|
|
2637
|
-
vEndXmlNode = prevUncle.ownerDocument.createElement('verse');
|
|
2638
|
-
prevUncle.appendChild(vEndXmlNode);
|
|
2639
|
-
} else if (prevUncle.tagName === "table") {
|
|
2640
|
-
const rows = prevUncle.getElementsByTagName('row');
|
|
2641
|
-
vEndXmlNode = prevUncle.ownerDocument.createElement('verse');
|
|
2642
|
-
rows[rows.length - 1].appendChild(vEndXmlNode);
|
|
2643
|
-
} else throw new Error(`prev_uncle is ${String(prevUncle)}`);
|
|
2644
|
-
}
|
|
2645
|
-
vEndXmlNode.setAttribute('eid', prevVerses[prevVerses.length - 1].getAttribute('sid'));
|
|
2616
|
+
// Check if there are previous verses to close
|
|
2617
|
+
if (this.parseState.prevVerseSid !== null) {
|
|
2618
|
+
let prevPara = this.parseState.prevVerseParent;
|
|
2619
|
+
let vEndXmlNode = prevPara.ownerDocument.createElement('verse');
|
|
2620
|
+
vEndXmlNode.setAttribute("eid", this.parseState.prevVerseSid);
|
|
2621
|
+
prevPara.appendChild(vEndXmlNode);
|
|
2646
2622
|
}
|
|
2647
2623
|
// Query to capture verse-related elements
|
|
2648
2624
|
const verseNumCap = this.usfmLanguage.query(`
|
|
@@ -2671,6 +2647,7 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
2671
2647
|
vXmlNode.setAttribute('number', verseNum.trim());
|
|
2672
2648
|
vXmlNode.setAttribute('style', 'v');
|
|
2673
2649
|
vXmlNode.setAttribute('sid', ref.trim());
|
|
2650
|
+
this.parseState.prevVerseSid = ref.trim();
|
|
2674
2651
|
}
|
|
2675
2652
|
node2UsxCaVa(node, parentXmlNode) {
|
|
2676
2653
|
// Build elements for independent ca and va away from c and v
|
|
@@ -2774,7 +2751,7 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
2774
2751
|
const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").trim();
|
|
2775
2752
|
const cellXmlNode = parentXmlNode.ownerDocument.createElement("cell");
|
|
2776
2753
|
cellXmlNode.setAttribute("style", style);
|
|
2777
|
-
cellXmlNode.setAttribute("align", style.includes("r") ? "end" : "start");
|
|
2754
|
+
cellXmlNode.setAttribute("align", style.includes("tcc") ? "center" : style.includes("r") ? "end" : "start");
|
|
2778
2755
|
parentXmlNode.appendChild(cellXmlNode);
|
|
2779
2756
|
node.children.slice(1).forEach((child)=>{
|
|
2780
2757
|
this.node2Usx(child, cellXmlNode);
|
|
@@ -2870,10 +2847,12 @@ class $02bc2da10d8b76e8$var$USXGenerator {
|
|
|
2870
2847
|
"va"
|
|
2871
2848
|
].includes(node.type)) this.node2UsxCaVa(node, parentXmlNode);
|
|
2872
2849
|
else if (node.type === "v") this.node2UsxVerse(node, parentXmlNode);
|
|
2873
|
-
else if (node.type === "verseText")
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2850
|
+
else if (node.type === "verseText") {
|
|
2851
|
+
node.children.forEach((child)=>{
|
|
2852
|
+
this.node2Usx(child, parentXmlNode);
|
|
2853
|
+
});
|
|
2854
|
+
this.parseState.prevVerseParent = parentXmlNode;
|
|
2855
|
+
} else if ([
|
|
2877
2856
|
"paragraph",
|
|
2878
2857
|
"pi",
|
|
2879
2858
|
"ph"
|