var $a9A1a$treesitter = require("tree-sitter"); var $a9A1a$assert = require("assert"); var $a9A1a$treesitterusfm3 = require("tree-sitter-usfm3"); var $a9A1a$xmldom = require("xmldom"); var $a9A1a$xpath = require("xpath"); var $a9A1a$nodefs = require("node:fs"); var $a9A1a$ajv = require("ajv"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "USFMParser", () => $4fa36e821943b400$export$db89aa78daab09ca, (v) => $4fa36e821943b400$export$db89aa78daab09ca = v); $parcel$export(module.exports, "Filter", () => $4fa36e821943b400$export$ec91da630f36d5ea, (v) => $4fa36e821943b400$export$ec91da630f36d5ea = v); $parcel$export(module.exports, "Format", () => $4fa36e821943b400$export$93514d28bd18d75a, (v) => $4fa36e821943b400$export$93514d28bd18d75a = v); $parcel$export(module.exports, "Validator", () => $4fa36e821943b400$export$9eeb22c0bba4ed5e, (v) => $4fa36e821943b400$export$9eeb22c0bba4ed5e = v); var $4fa36e821943b400$export$db89aa78daab09ca; var $4fa36e821943b400$export$ec91da630f36d5ea; var $4fa36e821943b400$export$93514d28bd18d75a; var $4fa36e821943b400$export$9eeb22c0bba4ed5e; var $be3194b3d68e926d$exports = {}; $parcel$export($be3194b3d68e926d$exports, "USFMParser", () => $be3194b3d68e926d$export$db89aa78daab09ca, (v) => $be3194b3d68e926d$export$db89aa78daab09ca = v); $parcel$export($be3194b3d68e926d$exports, "Filter", () => $be3194b3d68e926d$export$ec91da630f36d5ea, (v) => $be3194b3d68e926d$export$ec91da630f36d5ea = v); var $be3194b3d68e926d$export$db89aa78daab09ca; var $be3194b3d68e926d$export$ec91da630f36d5ea; var $b37353ce824c37f3$export$69486ebd11f334d1; var $0783021dea42787b$export$b32929182cc4fefe; var $0783021dea42787b$export$75b2f422ff60acaf; var $0783021dea42787b$export$aa24f570494ce8d0; var $0783021dea42787b$export$1790a88fa433c8d6; var $0783021dea42787b$export$c63c0b6e358f0774; var $0783021dea42787b$export$1187115108c84d45; $0783021dea42787b$export$b32929182cc4fefe = [ "USJ", "table" ]; $0783021dea42787b$export$75b2f422ff60acaf = [ "char", "note", "figure", "ref" ]; $0783021dea42787b$export$aa24f570494ce8d0 = [ "type", "marker", "content", "number", "sid", "code", "caller", "align", "version", "altnumber", "pubnumber", "category" ]; $0783021dea42787b$export$1790a88fa433c8d6 = [ "style", "number", "sid", "code", "caller", "align", "version", "altnumber", "pubnumber", "category" ]; $0783021dea42787b$export$c63c0b6e358f0774 = [ "char", "note", "verse", "table:cell" ]; $0783021dea42787b$export$1187115108c84d45 = [ "char", "note", "verse", "cell" ]; var $b37353ce824c37f3$require$NO_USFM_USJ_TYPES = $0783021dea42787b$export$b32929182cc4fefe; var $b37353ce824c37f3$require$CLOSING_USJ_TYPES = $0783021dea42787b$export$75b2f422ff60acaf; var $b37353ce824c37f3$require$NON_ATTRIB_USJ_KEYS = $0783021dea42787b$export$aa24f570494ce8d0; var $b37353ce824c37f3$require$NO_NEWLINE_USJ_TYPES = $0783021dea42787b$export$c63c0b6e358f0774; var $b37353ce824c37f3$require$NON_ATTRIB_USX_KEYS = $0783021dea42787b$export$1790a88fa433c8d6; var $b37353ce824c37f3$require$NO_NEWLINE_USX_TYPES = $0783021dea42787b$export$1187115108c84d45; var $b37353ce824c37f3$require$DOMParser = $a9A1a$xmldom.DOMParser; class $b37353ce824c37f3$var$USFMGenerator { constructor(){ this.usfmString = ""; } usjToUsfm(usjObj, nested = false) { if (usjObj.type === "ref") usjObj.marker = "ref"; if (!$b37353ce824c37f3$require$NO_USFM_USJ_TYPES.includes(usjObj.type)) { this.usfmString += "\\"; if (nested && usjObj.type === "char") this.usfmString += "+"; this.usfmString += `${usjObj.marker} `; } [ "code", "number", "caller" ].forEach((key)=>{ if (usjObj[key]) this.usfmString += `${usjObj[key]} `; }); if (usjObj.category) this.usfmString += `\\cat ${usjObj.category}\\cat*\n`; if (usjObj.altnumber) { if (usjObj.marker === "c") this.usfmString += `\\ca ${usjObj.altnumber} \\ca*\n`; else if (usjObj.marker === "v") this.usfmString += `\\va ${usjObj.altnumber} \\va* `; } if (usjObj.pubnumber) { if (usjObj.marker === "c") this.usfmString += `\\cp ${usjObj.pubnumber}\n`; else if (usjObj.marker === "v") this.usfmString += `\\vp ${usjObj.pubnumber} \\vp* `; } if (Array.isArray(usjObj.content)) usjObj.content.forEach((item)=>{ if (typeof item === "string") this.usfmString += item; else this.usjToUsfm(item, usjObj.type === "char" && item.marker !== "fv"); }); let attributes = []; Object.keys(usjObj).forEach((key)=>{ if (!$b37353ce824c37f3$require$NON_ATTRIB_USJ_KEYS.includes(key)) attributes.push(`${key}="${usjObj[key]}"`); }); if (attributes.length > 0) this.usfmString += `|${attributes.join(" ")}`; if ($b37353ce824c37f3$require$CLOSING_USJ_TYPES.includes(usjObj.type)) { this.usfmString += `\\`; if (nested && usjObj.type === "char") this.usfmString += "+"; this.usfmString += `${usjObj.marker}* `; } if (!$b37353ce824c37f3$require$NO_NEWLINE_USJ_TYPES.includes(usjObj.type) && this.usfmString[this.usfmString.length - 1] !== "\n") this.usfmString += "\n"; return this.usfmString; } usxToUsfm(xmlObj, nested = false) { // Check if xmlObj is a string // if (typeof xmlObj === 'string') { // // this.usfmString += xmlObj; // return; // } const objType = xmlObj.tagName; let marker = null; let usfmAttributes = []; if ([ 'verse', 'chapter' ].includes(objType) && xmlObj.hasAttribute('eid')) return; if (!$b37353ce824c37f3$require$NO_NEWLINE_USX_TYPES.includes(objType)) this.usfmString += '\n'; if (objType === 'optbreak') { if (this.usfmString !== '' && ![ '\n', '\r', ' ', '\t' ].includes(this.usfmString.slice(-1))) this.usfmString += ' '; this.usfmString += '// '; } if (xmlObj.hasAttribute('style')) { marker = xmlObj.getAttribute('style'); if (nested && objType === 'char' && ![ 'xt', 'fv', 'ref' ].includes(marker)) marker = `+${marker}`; this.usfmString += `\\${marker} `; } else if (objType === 'ref') { marker = 'ref'; this.usfmString += `\\${marker} `; } if (xmlObj.hasAttribute('code')) this.usfmString += xmlObj.getAttribute('code'); if (xmlObj.hasAttribute('number')) this.usfmString += `${xmlObj.getAttribute('number')} `; if (xmlObj.hasAttribute('caller')) this.usfmString += `${xmlObj.getAttribute('caller')} `; if (xmlObj.hasAttribute('altnumber')) { if (objType === 'verse') this.usfmString += `\\va ${xmlObj.getAttribute('altnumber')}\\va*`; else if (objType === 'chapter') this.usfmString += `\n\\ca ${xmlObj.getAttribute('altnumber')}\\ca*`; } if (xmlObj.hasAttribute('pubnumber')) { if (objType === 'verse') this.usfmString += `\\vp ${xmlObj.getAttribute('pubnumber')}\\vp*`; else if (objType === 'chapter') this.usfmString += `\n\\cp ${xmlObj.getAttribute('pubnumber')}`; } if (xmlObj.hasAttribute('category')) this.usfmString += `\n\\cat ${xmlObj.getAttribute('category')} \\cat*`; const children = Array.from(xmlObj.childNodes); for (const child of children){ if (child.nodeType === 1) { if (objType === 'char') this.usxToUsfm(child, true); else this.usxToUsfm(child, false); } if (child.nodeType === 3 && child.nodeValue.trim()) { if (this.usfmString !== '' && ![ '\n', '\r', ' ', '\t' ].includes(this.usfmString.slice(-1))) this.usfmString += ' '; this.usfmString += child.nodeValue.trim(); } } const attributes = Array.from(xmlObj.attributes); for (const attrNode of attributes){ let key = attrNode.name; let val = attrNode.value.replace(/"/g, ''); if (key === 'file' && objType === 'figure') usfmAttributes.push(`src="${val}"`); else if (!$b37353ce824c37f3$require$NON_ATTRIB_USX_KEYS.includes(key)) usfmAttributes.push(`${key}="${val}"`); if ([ 'sid', 'eid' ].includes(key) && objType === 'ms') usfmAttributes.push(`${key}="${val}"`); } if (usfmAttributes.length > 0) { this.usfmString += '|'; this.usfmString += usfmAttributes.join(' '); } if (xmlObj.hasAttribute('closed') && xmlObj.getAttribute('closed') === 'true' || $b37353ce824c37f3$require$CLOSING_USJ_TYPES.includes(objType) || usfmAttributes.length > 0) { if (objType === 'ms') this.usfmString += '\\*'; else this.usfmString += `\\${marker}*`; } if (objType === 'sidebar') this.usfmString += '\n\\esbe\n'; } } $b37353ce824c37f3$export$69486ebd11f334d1 = $b37353ce824c37f3$var$USFMGenerator; var $be3194b3d68e926d$require$USFMGenerator = $b37353ce824c37f3$export$69486ebd11f334d1; //Logics for syntax-tree to dict(USJ) conversions var $bc15495701a08748$export$da1572eff96010ef; const { Query: $bc15495701a08748$var$Query } = $a9A1a$treesitter; var $48a7bc78362df58a$export$3ea3efefd6f5792b; var $48a7bc78362df58a$export$bfe3d604e5046dbb; var $48a7bc78362df58a$export$32d1909bfb943eb0; var $48a7bc78362df58a$export$ec3044778745fabd; var $48a7bc78362df58a$export$38bc6f52843beb2a; var $48a7bc78362df58a$export$af42bd8f70df8555; var $48a7bc78362df58a$export$c4d2f24f22330b2a; const $48a7bc78362df58a$var$CHAR_STYLE_MARKERS = [ "add", "bk", "dc", "ior", "iqt", "k", "litl", "nd", "ord", "pn", "png", "qac", "qs", "qt", "rq", "sig", "sls", "tl", "wj", "em", "bd", "bdit", "it", "no", "sc", "sup", "rb", "pro", "w", "wh", "wa", "wg", "lik", "liv", "jmp", "fr", "ft", "fk", "fq", "fqa", "fl", "fw", "fp", "fv", "fdc", "xo", "xop", "xt", "xta", "xk", "xq", "xot", "xnt", "xdc" ]; $48a7bc78362df58a$export$3ea3efefd6f5792b = [ "ide", "usfm", "h", "toc", "toca", "imt", "is", "ip", "ipi", "im", "imi", "ipq", "imq", "ipr", "iq", "ib", "ili", "iot", "io", "iex", "imte", "ie", "mt", "mte", "cl", "cd", "ms", "mr", "s", "sr", "r", "d", "sp", "sd", "q", "qr", "qc", "qa", "qm", "qd", "lh", "li", "lf", "lim", "litl", "sts", "rem", "lit", "restore" ]; $48a7bc78362df58a$export$bfe3d604e5046dbb = [ "f", "fe", "ef", "efe", "x", "ex" ]; $48a7bc78362df58a$export$32d1909bfb943eb0 = $48a7bc78362df58a$var$CHAR_STYLE_MARKERS; $48a7bc78362df58a$export$ec3044778745fabd = $48a7bc78362df58a$var$CHAR_STYLE_MARKERS.map((item)=>item + "Nested"); $48a7bc78362df58a$export$38bc6f52843beb2a = { w: "lemma", rb: "gloss", xt: "href", fig: "alt", xt_standalone: "href", xtNested: "href", ref: "loc", "milestone": "who", "k": "key" }; $48a7bc78362df58a$export$af42bd8f70df8555 = [ "tc", "th", "tcr", "thr" ]; $48a7bc78362df58a$export$c4d2f24f22330b2a = [ "fig", "cat", "esb", "b", "ph", "pi" ]; var $bc15495701a08748$require$PARA_STYLE_MARKERS = $48a7bc78362df58a$export$3ea3efefd6f5792b; var $bc15495701a08748$require$NOTE_MARKERS = $48a7bc78362df58a$export$bfe3d604e5046dbb; var $bc15495701a08748$require$CHAR_STYLE_MARKERS = $48a7bc78362df58a$export$32d1909bfb943eb0; var $bc15495701a08748$require$NESTED_CHAR_STYLE_MARKERS = $48a7bc78362df58a$export$ec3044778745fabd; var $bc15495701a08748$require$DEFAULT_ATTRIB_MAP = $48a7bc78362df58a$export$38bc6f52843beb2a; var $bc15495701a08748$require$TABLE_CELL_MARKERS = $48a7bc78362df58a$export$af42bd8f70df8555; var $bc15495701a08748$require$MISC_MARKERS = $48a7bc78362df58a$export$c4d2f24f22330b2a; class $bc15495701a08748$var$USJGenerator { constructor(treeSitterLanguageObj, usfmString, usjRootObj = null){ this.usfmLanguage = treeSitterLanguageObj; this.usfm = usfmString; this.jsonRootObj = usjRootObj || { type: "USJ", version: "3.1", content: [] }; } findLastFromJson(jsonObj, typeValue) { let output = null; if (typeValue === jsonObj.type || jsonObj.marker && typeValue === jsonObj.marker) output = jsonObj; if (jsonObj.content) jsonObj.content.forEach((child)=>{ if (typeof child === "string") return; const childOutput = this.findLastFromJson(child, typeValue); if (childOutput !== null) output = childOutput; }); return output; } nodeToUSJId(node, parentJsonObj) { const idCaptures = new $bc15495701a08748$var$Query(this.usfmLanguage, "(id (bookcode) @book-code (description)? @desc)").captures(node); let code = null; let desc = null; idCaptures.forEach((capture)=>{ if (capture.name === "book-code") code = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); else if (capture.name === "desc") desc = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); }); const bookJsonObj = { type: "book", marker: "id", code: code, content: [] }; if (desc && desc.trim() !== "") bookJsonObj.content.push(desc.trim()); parentJsonObj.content.push(bookJsonObj); } // Similar conversion methods for other node types nodeToUSJC(node, parentJsonObj) { // Build c, the chapter milestone node in usj const chapCap = new $bc15495701a08748$var$Query(this.usfmLanguage, `(c (chapterNumber) @chap-num (ca (chapterNumber) @alt-num)? (cp (text) @pub-num)?)`).captures(node); const chapNum = this.usfm.slice(chapCap[0].node.startIndex, chapCap[0].node.endIndex); let chapRef = null; this.jsonRootObj.content.forEach((child)=>{ if (child.type === "book") { chapRef = `${child.code} ${chapNum}`; return; } }); const chapJsonObj = { type: "chapter", marker: "c", number: chapNum, sid: chapRef }; chapCap.forEach((cap)=>{ if (cap.name === "alt-num") chapJsonObj.altnumber = this.usfm.substring(cap.node.startIndex, cap.node.endIndex).trim(); if (cap.name === "pub-num") chapJsonObj.pubnumber = this.usfm.substring(cap.node.startIndex, cap.node.endIndex).trim(); }); parentJsonObj.content.push(chapJsonObj); node.children.forEach((child)=>{ if ([ "cl", "cd" ].includes(child.type)) this.nodeToUSJ(child, parentJsonObj); }); } nodeToUSJChapter(node, parentJsonObj) { // Build chapter node in USJ node.children.forEach((child)=>{ if (child.type === "c") this.nodeToUSJC(child, parentJsonObj); else this.nodeToUSJ(child, parentJsonObj); }); } nodeToUSJVerse(node, parentJsonObj) { // Build verse node in USJ const verseNumCap = new $bc15495701a08748$var$Query(this.usfmLanguage, ` (v (verseNumber) @vnum (va (verseNumber) @alt)? (vp (text) @vp)? )`).captures(node); const verseNum = this.usfm.substring(verseNumCap[0].node.startIndex, verseNumCap[0].node.endIndex); const vJsonObj = { type: "verse", marker: "v", number: verseNum.trim() }; verseNumCap.forEach((capture)=>{ if (capture.name === "alt") { const altNum = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); vJsonObj.altnumber = altNum; } else if (capture.name === "vp") { const vpText = this.usfm.substring(capture.node.startIndex, capture.node.endIndex); vJsonObj.pubnumber = vpText; } }); const ref = `${this.findLastFromJson(this.jsonRootObj, "chapter").sid}:${verseNum}`; vJsonObj.sid = ref.trim(); parentJsonObj.content.push(vJsonObj); } nodeToUSJCaVa(node, parentJsonObj) { // Build elements for independent ca and va away from c and v const style = node.type; const charJsonObj = { type: "char", marker: style }; const altNumMatch = new $bc15495701a08748$var$Query(this.usfmLanguage, `([ (chapterNumber) (verseNumber) ] @alt-num)`).captures(node); const altNum = this.usfm.slice(altNumMatch[0].node.startIndex, altNumMatch[0].node.endIndex).trim(); charJsonObj.altnumber = altNum; parentJsonObj.content.push(charJsonObj); } nodeToUSJPara(node, parentJsonObj) { // Build paragraph nodes in USJ if (node.children[0].type.endsWith("Block")) node.children[0].children.forEach((child)=>{ this.nodeToUSJPara(child, parentJsonObj); }); else if (node.type === "paragraph") { const paraTagCap = new $bc15495701a08748$var$Query(this.usfmLanguage, "(paragraph (_) @para-marker)").captures(node)[0]; const paraMarker = paraTagCap.node.type; let paraJsonObj = null; if (paraMarker === "b") parentJsonObj.content.push({ type: "para", marker: paraMarker }); else if (!paraMarker.endsWith("Block")) { let paraJsonObj = { type: "para", marker: paraMarker, content: [] }; paraTagCap.node.children.forEach((child)=>{ this.nodeToUSJ(child, paraJsonObj); }); parentJsonObj.content.push(paraJsonObj); } } else if ([ "pi", "ph" ].includes(node.type)) { const paraMarker = this.usfm.substring(node.children[0].startIndex, node.children[0].endIndex).replace("\\", "").trim(); let paraJsonObj = { type: "para", marker: paraMarker, content: [] }; node.children.slice(1).forEach((child)=>{ this.nodeToUSJ(child, paraJsonObj); }); parentJsonObj.content.push(paraJsonObj); } } nodeToUSJNotes(node, parentJsonObj) { // Build USJ nodes for footnotes and cross-references const tagNode = node.children[0]; const callerNode = node.children[1]; const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").trim(); const noteJsonObj = { type: "note", marker: style, content: [] }; noteJsonObj.caller = this.usfm.substring(callerNode.startIndex, callerNode.endIndex).trim(); for(let i = 2; i < node.children.length - 1; i++)this.nodeToUSJ(node.children[i], noteJsonObj); parentJsonObj.content.push(noteJsonObj); } nodeToUSJChar(node, parentJsonObj) { // Build USJ nodes for character markups, both regular and nested const tagNode = node.children[0]; let childrenRange = node.children.length; if (node.children[node.children.length - 1].type.startsWith("\\")) childrenRange -= 1; // Exclude the last node if it starts with '\', treating it as a closing node const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").replace("+", "").trim(); const charJsonObj = { type: "char", marker: style, content: [] }; // Assume a flag for closed markup, toggle this if your conditions and data structure require // charJsonObj.closed = node.children[node.children.length - 1].type.startsWith('\\'); for(let i = 1; i < childrenRange; i++)this.nodeToUSJ(node.children[i], charJsonObj); parentJsonObj.content.push(charJsonObj); } nodeToUSJTable(node, parentJsonObj) { // Handle table related components and convert to USJ if (node.type === "table") { const tableJsonObj = { type: "table", content: [] }; node.children.forEach((child)=>{ this.nodeToUSJ(child, tableJsonObj); }); parentJsonObj.content.push(tableJsonObj); } else if (node.type === "tr") { const rowJsonObj = { type: "table:row", marker: "tr", content: [] }; node.children.slice(1).forEach((child)=>{ this.nodeToUSJ(child, rowJsonObj); }); parentJsonObj.content.push(rowJsonObj); } else if ($bc15495701a08748$require$TABLE_CELL_MARKERS.includes(node.type)) { const tagNode = node.children[0]; const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").trim(); const cellJsonObj = { type: "table:cell", marker: style, content: [], align: style.includes("r") ? "end" : "start" }; node.children.slice(1).forEach((child)=>{ this.nodeToUSJ(child, cellJsonObj); }); parentJsonObj.content.push(cellJsonObj); } } nodeToUSJAttrib(node, parentJsonObj) { // Add attribute values to USJ elements const attribNameNode = node.children[0]; let attribName = this.usfm.slice(attribNameNode.startIndex, attribNameNode.endIndex).trim(); // Handling special cases for attribute names if (attribName === "|") attribName = $bc15495701a08748$require$DEFAULT_ATTRIB_MAP[node.parent.type]; if (attribName === "src") // for \fig attribName = "file"; const attribValCap = new $bc15495701a08748$var$Query(this.usfmLanguage, "((attributeValue) @attrib-val)").captures(node); let attribValue = ""; if (attribValCap.length > 0) attribValue = this.usfm.substring(attribValCap[0].node.startIndex, attribValCap[0].node.endIndex).trim(); parentJsonObj[attribName] = attribValue; } nodeToUSJMilestone(node, parentJsonObj) { // Create ms node in USJ const msNameCap = new $bc15495701a08748$var$Query(this.usfmLanguage, `( [(milestoneTag) (milestoneStartTag) (milestoneEndTag) (zSpaceTag) ] @ms-name)`).captures(node)[0]; const style = this.usfm.slice(msNameCap.node.startIndex, msNameCap.node.endIndex).replace("\\", "").trim(); const msJsonObj = { type: "ms", marker: style, content: [] }; node.children.forEach((child)=>{ if (child.type.endsWith("Attribute")) this.nodeToUSJ(child, msJsonObj); }); // Though normally milestones don't have contents, custom z-namespaces could have them if (!msJsonObj.content.length) delete msJsonObj.content; // Remove empty content array if not used parentJsonObj.content.push(msJsonObj); } nodeToUSJSpecial(node, parentJsonObj) { // Build nodes for esb, cat, fig, optbreak in USJ if (node.type === "esb") { const sidebarJsonObj = { type: "sidebar", marker: "esb", content: [] }; node.children.slice(1, -1).forEach((child)=>{ this.nodeToUSJ(child, sidebarJsonObj); }); parentJsonObj.content.push(sidebarJsonObj); } else if (node.type === "cat") { const catCap = new $bc15495701a08748$var$Query(this.usfmLanguage, "((category) @category)").captures(node)[0]; const category = this.usfm.substring(catCap.node.startIndex, catCap.node.endIndex).trim(); parentJsonObj.category = category; } else if (node.type === "fig") { const figJsonObj = { type: "figure", marker: "fig", content: [] }; node.children.slice(1, -1).forEach((child)=>{ this.nodeToUSJ(child, figJsonObj); }); parentJsonObj.content.push(figJsonObj); } else if (node.type === "ref") { const refJsonObj = { type: "ref", content: [] }; node.children.slice(1, -1).forEach((child)=>{ this.nodeToUSJ(child, refJsonObj); }); parentJsonObj.content.push(refJsonObj); } } nodeToUSJGeneric(node, parentJsonObj) { // Build nodes for para style markers in USJ const tagNode = node.children[0]; let style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex); if (style.startsWith("\\")) style = style.replace("\\", "").trim(); // console.log(node.children.length, node.children[0].type, node.children[1].type) let childrenRangeStart = 1; // if ( // node.children.length > 1 && // node.children[1].type.startsWith("numbered") // ) { // const numNode = node.children[1]; // const num = this.usfm.substring(numNode.startIndex, numNode.endIndex); // style += num; // childrenRangeStart = 2; // } const paraJsonObj = { type: "para", marker: style, content: [] }; parentJsonObj.content.push(paraJsonObj); for(let i = childrenRangeStart; i < node.children.length; i++){ const child = node.children[i]; if ($bc15495701a08748$require$CHAR_STYLE_MARKERS.includes(child.type) || $bc15495701a08748$require$NESTED_CHAR_STYLE_MARKERS.includes(child.type) || [ "text", "footnote", "crossref", "verseText", "v", "b", "milestone", "zNameSpace" ].includes(child.type)) // Only nest these types inside the upper para style node this.nodeToUSJ(child, paraJsonObj); else this.nodeToUSJ(child, parentJsonObj); } } nodeToUSJ(node, parentJsonObj) { // Check each node and based on the type convert to corresponding XML element switch(node.type){ case "id": this.nodeToUSJId(node, parentJsonObj); break; case "chapter": this.nodeToUSJChapter(node, parentJsonObj); break; case "cl": case "cp": case "cd": case "vp": this.nodeToUSJGeneric(node, parentJsonObj); break; case "ca": case "va": this.nodeToUSJCaVa(node, parentJsonObj); break; case "v": this.nodeToUSJVerse(node, parentJsonObj); break; case "verseText": node.children.forEach((child)=>this.nodeToUSJ(child, parentJsonObj)); break; case "paragraph": case "pi": case "ph": this.nodeToUSJPara(node, parentJsonObj); break; case "text": let textVal = this.usfm.substring(node.startIndex, node.endIndex); textVal = textVal.replace("~", " "); if (textVal !== "") parentJsonObj.content.push(textVal); break; case "table": case "tr": this.nodeToUSJTable(node, parentJsonObj); break; case "milestone": case "zNameSpace": this.nodeToUSJMilestone(node, parentJsonObj); break; case "esb": case "cat": case "fig": case "ref": this.nodeToUSJSpecial(node, parentJsonObj); break; case "usfm": break; default: if ($bc15495701a08748$require$NOTE_MARKERS.includes(node.type)) this.nodeToUSJNotes(node, parentJsonObj); else if ($bc15495701a08748$require$CHAR_STYLE_MARKERS.includes(node.type) || $bc15495701a08748$require$NESTED_CHAR_STYLE_MARKERS.includes(node.type) || [ "xt_standalone" ].includes(node.type)) this.nodeToUSJChar(node, parentJsonObj); else if ($bc15495701a08748$require$TABLE_CELL_MARKERS.includes(node.type)) this.nodeToUSJTable(node, parentJsonObj); else if (node.type.endsWith("Attribute")) this.nodeToUSJAttrib(node, parentJsonObj); else if ($bc15495701a08748$require$PARA_STYLE_MARKERS.includes(node.type) || $bc15495701a08748$require$PARA_STYLE_MARKERS.includes(node.type.replace("\\", "").trim())) this.nodeToUSJGeneric(node, parentJsonObj); else if ([ "", "|" ].includes(node.type.trim())) break; else if (node.children.length > 0) node.children.forEach((child)=>this.nodeToUSJ(child, parentJsonObj)); break; } } } $bc15495701a08748$export$da1572eff96010ef = $bc15495701a08748$var$USJGenerator; var $be3194b3d68e926d$require$USJGenerator = $bc15495701a08748$export$da1572eff96010ef; var $0ed9cb36901d4d14$export$24715706bc524307; class $0ed9cb36901d4d14$var$ListGenerator { /* Combines the methods used for List generation from USJ */ constructor(){ /* Variables shared by functions */ this.book = ""; this.currentChapter = ""; this.currentVerse = ""; this.list = [ [ "Book", "Chapter", "Verse", "Text", "Type", "Marker" ] ]; } usjToListId(obj) { /* Update book code */ this.book = obj.code; } usjToListC(obj) { /* Update current chapter */ this.currentChapter = obj.number; } usjToListV(obj) { /* Update current verse */ this.currentVerse = obj.number; } usjToList(obj) { /* Traverse the USJ dict and build the table in this.list */ if (obj.type === "book") this.usjToListId(obj); else if (obj.type === "chapter") this.usjToListC(obj); else if (obj.type === "verse") this.usjToListV(obj); let markerType = obj.type; let markerName = obj.marker ? obj.marker : ''; if (markerType === "USJ") // This would occur if the JSON got flattened after removing paragraph markers markerType = ""; if (obj.content) { for (let item of obj.content)if (typeof item === "string") this.list.push([ this.book, this.currentChapter, this.currentVerse, item, markerType, markerName ]); else this.usjToList(item); } } } $0ed9cb36901d4d14$export$24715706bc524307 = $0ed9cb36901d4d14$var$ListGenerator; var $be3194b3d68e926d$require$ListGenerator = $0ed9cb36901d4d14$export$24715706bc524307; //Logics for syntax-tree to xml(USX) conversions var $27f438441a7f3c46$export$69d2127c7776f273; var $27f438441a7f3c46$require$DOMImplementation = $a9A1a$xmldom.DOMImplementation; var $27f438441a7f3c46$require$XMLSerializer = $a9A1a$xmldom.XMLSerializer; const { Query: $27f438441a7f3c46$var$Query } = $a9A1a$treesitter; var $27f438441a7f3c46$require$PARA_STYLE_MARKERS = $48a7bc78362df58a$export$3ea3efefd6f5792b; var $27f438441a7f3c46$require$NOTE_MARKERS = $48a7bc78362df58a$export$bfe3d604e5046dbb; var $27f438441a7f3c46$require$CHAR_STYLE_MARKERS = $48a7bc78362df58a$export$32d1909bfb943eb0; var $27f438441a7f3c46$require$NESTED_CHAR_STYLE_MARKERS = $48a7bc78362df58a$export$ec3044778745fabd; var $27f438441a7f3c46$require$DEFAULT_ATTRIB_MAP = $48a7bc78362df58a$export$38bc6f52843beb2a; var $27f438441a7f3c46$require$TABLE_CELL_MARKERS = $48a7bc78362df58a$export$af42bd8f70df8555; var $27f438441a7f3c46$require$MISC_MARKERS = $48a7bc78362df58a$export$c4d2f24f22330b2a; class $27f438441a7f3c46$var$USXGenerator { /** * A binding for all methods used in generating USX from Syntax tree * @param {object} treeSitterLanguageObj - The Tree-sitter language object * @param {Buffer} usfmString - The USFM byte data * @param {Element} [usxRootElement] - The root element of the USX (optional) */ constructor(treeSitterLanguageObj, usfmString, usxRootElement = null){ this.usfmLanguage = treeSitterLanguageObj; this.usfm = usfmString; const domImpl = new $27f438441a7f3c46$require$DOMImplementation(); const doc = domImpl.createDocument(null, 'usx', null); if (usxRootElement === null) { this.xmlRootNode = doc.documentElement; this.xmlRootNode.setAttribute('version', '3.1'); } else this.xmlRootNode = usxRootElement; } /** * Builds the ID node in USX * @param {SyntaxNode} node - The syntax node * @param {Element} parentXmlNode - The parent XML node to append the ID to */ node2UsxId(node, parentXmlNode) { const idCaptures = new $27f438441a7f3c46$var$Query(this.usfmLanguage, "(id (bookcode) @book-code (description)? @desc)").captures(node); let code = null; let desc = null; idCaptures.forEach((capture)=>{ if (capture.name === 'book-code') code = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); else if (capture.name === 'desc') desc = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); }); const bookXmlNode = parentXmlNode.ownerDocument.createElement('book'); bookXmlNode.setAttribute('code', code); bookXmlNode.setAttribute('style', 'id'); if (desc && desc.trim() !== '') { const textNode = parentXmlNode.ownerDocument.createTextNode(desc.trim()); bookXmlNode.appendChild(textNode); } parentXmlNode.appendChild(bookXmlNode); } node2UsxC(node, parentXmlNode) { // Build c, the chapter milestone node in usj const chapCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, `(c (chapterNumber) @chap-num (ca (chapterNumber) @alt-num)? (cp (text) @pub-num)?)`).captures(node); const chapNum = this.usfm.slice(chapCap[0].node.startIndex, chapCap[0].node.endIndex); const bookNode = $a9A1a$xpath.select1("book", parentXmlNode); const bookCode = bookNode.getAttribute("code"); const chapRef = `${bookCode} ${chapNum}`; // Create the 'chapter' element const chapXmlNode = parentXmlNode.ownerDocument.createElement('chapter'); chapXmlNode.setAttribute("number", chapNum); chapXmlNode.setAttribute("style", "c"); chapXmlNode.setAttribute("sid", chapRef); chapCap.forEach((cap)=>{ if (cap.name === "alt-num") { const altNum = this.usfm.substring(cap.node.startIndex, cap.node.endIndex).trim(); chapXmlNode.setAttribute('altnumber', altNum); } if (cap.name === "pub-num") { const pubNum = this.usfm.substring(cap.node.startIndex, cap.node.endIndex).trim(); chapXmlNode.setAttribute('pubnumber', pubNum); } }); parentXmlNode.appendChild(chapXmlNode); node.children.forEach((child)=>{ if ([ "cl", "cd" ].includes(child.type)) this.node2Usx(child, parentXmlNode); }); } node2UsxChapter(node, parentXmlNode) { // Build chapter node in USJ node.children.forEach((child)=>{ if (child.type === "c") this.node2UsxC(child, parentXmlNode); else this.node2Usx(child, parentXmlNode); }); const prevVerses = $a9A1a$xpath.select("//verse", this.xmlRootNode); if (prevVerses.length > 0 && prevVerses[prevVerses.length - 1].hasAttribute('sid')) { const vEndXmlNode = parentXmlNode.ownerDocument.createElement('verse'); vEndXmlNode.setAttribute('eid', prevVerses[prevVerses.length - 1].getAttribute('sid')); const sibblingCount = parentXmlNode.childNodes.length; const lastSibbling = parentXmlNode.childNodes[sibblingCount - 1]; if (lastSibbling.tagName === "para") lastSibbling.appendChild(vEndXmlNode); else if (lastSibbling.tagName === "table") { const rows = lastSibbling.getElementsByTagName('row'); rows[rows.length - 1].appendChild(vEndXmlNode); } else parentXmlNode.appendChild(vEndXmlNode); } } findPrevUncle(parentXmlNode) { // Get the grandparent node const grandParent = parentXmlNode.parentNode; let uncleIndex = grandParent.childNodes.length - 2; // Start from the previous sibling while(uncleIndex >= 0){ const uncle = grandParent.childNodes[uncleIndex]; // Skip 'sidebar' and 'ms' elements if (uncle.tagName === "sidebar" || uncle.tagName === "ms") uncleIndex--; else if (uncle.getAttribute('style') === 'ca' || uncle.getAttribute('style') === 'cp') uncleIndex--; else return uncle; } return null; // No suitable uncle found } node2UsxVerse(node, parentXmlNode) { // Find all previous 'verse' elements const prevVerses = $a9A1a$xpath.select("//verse", this.xmlRootNode); // Check if there are previous verses and if the last one has a 'sid' attribute if (prevVerses.length > 0 && prevVerses[prevVerses.length - 1].hasAttribute('sid')) { let vEndXmlNode; if (parentXmlNode.textContent.trim() !== "") { // If there is verse text in the current parent vEndXmlNode = parentXmlNode.ownerDocument.createElement('verse'); parentXmlNode.appendChild(vEndXmlNode); } else { // If no text, find the previous uncle and attach the end verse const prevUncle = this.findPrevUncle(parentXmlNode); if (prevUncle.tagName === "para") { vEndXmlNode = prevUncle.ownerDocument.createElement('verse'); prevUncle.appendChild(vEndXmlNode); } else if (prevUncle.tagName === "table") { const rows = prevUncle.getElementsByTagName('row'); vEndXmlNode = prevUncle.ownerDocument.createElement('verse'); rows[rows.length - 1].appendChild(vEndXmlNode); } else throw new Error(`prev_uncle is ${String(prevUncle)}`); } vEndXmlNode.setAttribute('eid', prevVerses[prevVerses.length - 1].getAttribute('sid')); } // Query to capture verse-related elements const verseNumCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, ` (v (verseNumber) @vnum (va (verseNumber) @alt)? (vp (text) @vp)? )`).captures(node); const verseNum = this.usfm.substring(verseNumCap[0].node.startIndex, verseNumCap[0].node.endIndex); const vXmlNode = parentXmlNode.ownerDocument.createElement('verse'); parentXmlNode.appendChild(vXmlNode); // Loop through the captured elements and set the attributes verseNumCap.forEach((capture)=>{ if (capture.name === 'alt') { const altNum = this.usfm.slice(capture.node.startIndex, capture.node.endIndex); vXmlNode.setAttribute('altnumber', altNum); } else if (capture.name === 'vp') { const vpText = this.usfm.slice(capture.node.startIndex, capture.node.endIndex).trim(); vXmlNode.setAttribute('pubnumber', vpText); } }); // Get the last chapter's 'sid' attribute to form the verse reference const chapterSid = $a9A1a$xpath.select("//chapter", this.xmlRootNode).pop().getAttribute('sid'); const ref = `${chapterSid}:${verseNum}`; // Set attributes on the newly created 'verse' element vXmlNode.setAttribute('number', verseNum.trim()); vXmlNode.setAttribute('style', 'v'); vXmlNode.setAttribute('sid', ref.trim()); } node2UsxCaVa(node, parentXmlNode) { // Build elements for independent ca and va away from c and v const style = node.type; // Create a new 'char' element under the parent XML node const charXmlNode = parentXmlNode.ownerDocument.createElement('char'); charXmlNode.setAttribute('style', style); // Query to capture chapterNumber or verseNumber const altNumMatch = new $27f438441a7f3c46$var$Query(this.usfmLanguage, `([ (chapterNumber) (verseNumber) ] @alt-num)`).captures(node); // Extract the alternate number from the captured range const altNum = this.usfm.slice(altNumMatch[0].node.startIndex, altNumMatch[0].node.endIndex).trim(); // Set the attributes on the 'char' element charXmlNode.setAttribute('altnumber', altNum); charXmlNode.setAttribute('closed', 'true'); // Append the 'char' element to the parent XML node parentXmlNode.appendChild(charXmlNode); } node2UsxPara(node, parentXmlNode) { // Build paragraph nodes in USX if (node.children[0].type.endsWith('Block')) for (const child of node.children[0].children)this.node2UsxPara(child, parentXmlNode); else if (node.type === 'paragraph') { const paraTagCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, "(paragraph (_) @para-marker)").captures(node)[0]; const paraMarker = paraTagCap.node.type; if (!paraMarker.endsWith("Block")) { const paraXmlNode = parentXmlNode.ownerDocument.createElement("para"); paraXmlNode.setAttribute("style", paraMarker); parentXmlNode.appendChild(paraXmlNode); for (const child of paraTagCap.node.children.slice(1))this.node2Usx(child, paraXmlNode); } } else if ([ 'pi', 'ph' ].includes(node.type)) { const paraMarker = this.usfm.slice(node.children[0].startIndex, node.children[0].endIndex).replace("\\", "").trim(); const paraXmlNode = parentXmlNode.ownerDocument.createElement("para"); paraXmlNode.setAttribute("style", paraMarker); parentXmlNode.appendChild(paraXmlNode); for (const child of node.children.slice(1))this.node2Usx(child, paraXmlNode); } } node2UsxNotes(node, parentXmlNode) { // Build USJ nodes for footnotes and cross-references const tagNode = node.children[0]; const callerNode = node.children[1]; const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").trim(); const noteXmlNode = parentXmlNode.ownerDocument.createElement('note'); noteXmlNode.setAttribute('style', style); const caller = this.usfm.substring(callerNode.startIndex, callerNode.endIndex).trim(); noteXmlNode.setAttribute('caller', caller); parentXmlNode.appendChild(noteXmlNode); for(let i = 2; i < node.children.length - 1; i++)this.node2Usx(node.children[i], noteXmlNode); } node2UsxChar(node, parentXmlNode) { // Build USJ nodes for character markups, both regular and nested const tagNode = node.children[0]; let childrenRange = node.children.length; if (node.children[node.children.length - 1].type.startsWith("\\")) childrenRange -= 1; // Exclude the last node if it starts with '\', treating it as a closing node const charXmlNode = parentXmlNode.ownerDocument.createElement('char'); const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").replace("+", "").trim(); charXmlNode.setAttribute('style', style); parentXmlNode.appendChild(charXmlNode); for(let i = 1; i < childrenRange; i++)this.node2Usx(node.children[i], charXmlNode); } node2UsxAttrib(node, parentXmlNode) { // Add attribute values to USJ elements const attribNameNode = node.children[0]; let attribName = this.usfm.slice(attribNameNode.startIndex, attribNameNode.endIndex).trim(); // Handling special cases for attribute names if (attribName === "|") attribName = $27f438441a7f3c46$require$DEFAULT_ATTRIB_MAP[node.parent.type]; if (attribName === "src") // for \fig attribName = "file"; const attribValCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, "((attributeValue) @attrib-val)").captures(node); let attribValue = ""; if (attribValCap.length > 0) attribValue = this.usfm.substring(attribValCap[0].node.startIndex, attribValCap[0].node.endIndex).trim(); parentXmlNode.setAttribute(attribName, attribValue); } node2UsxTable(node, parentXmlNode) { // Handle table related components and convert to USJ if (node.type === "table") { const tableXmlNode = parentXmlNode.ownerDocument.createElement('table'); parentXmlNode.appendChild(tableXmlNode); node.children.forEach((child)=>{ this.node2Usx(child, tableXmlNode); }); } else if (node.type === "tr") { const rowXmlNode = parentXmlNode.ownerDocument.createElement('row'); rowXmlNode.setAttribute("style", "tr"); parentXmlNode.appendChild(rowXmlNode); node.children.slice(1).forEach((child)=>{ this.node2Usx(child, rowXmlNode); }); } else if ($27f438441a7f3c46$require$TABLE_CELL_MARKERS.includes(node.type)) { const tagNode = node.children[0]; const style = this.usfm.substring(tagNode.startIndex, tagNode.endIndex).replace("\\", "").trim(); const cellXmlNode = parentXmlNode.ownerDocument.createElement("cell"); cellXmlNode.setAttribute("style", style); cellXmlNode.setAttribute("align", style.includes("r") ? "end" : "start"); parentXmlNode.appendChild(cellXmlNode); node.children.slice(1).forEach((child)=>{ this.node2Usx(child, cellXmlNode); }); } } node2UsxMilestone(node, parentXmlNode) { // Create ms node in USJ const msNameCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, `( [(milestoneTag) (milestoneStartTag) (milestoneEndTag) (zSpaceTag) ] @ms-name)`).captures(node)[0]; const style = this.usfm.slice(msNameCap.node.startIndex, msNameCap.node.endIndex).replace("\\", "").trim(); const msXmlNode = parentXmlNode.ownerDocument.createElement("ms"); msXmlNode.setAttribute("style", style); parentXmlNode.appendChild(msXmlNode); node.children.forEach((child)=>{ if (child.type.endsWith("Attribute")) this.node2Usx(child, msXmlNode); }); } node2UsxSpecial(node, parentXmlNode) { // Build nodes for esb, cat, fig, optbreak in USJ if (node.type === "esb") { const sidebarXmlNode = parentXmlNode.ownerDocument.createElement('sidebar'); sidebarXmlNode.setAttribute('style', "esb"); parentXmlNode.appendChild(sidebarXmlNode); node.children.slice(1, -1).forEach((child)=>{ this.node2Usx(child, sidebarXmlNode); }); } else if (node.type === "cat") { const catCap = new $27f438441a7f3c46$var$Query(this.usfmLanguage, "((category) @category)").captures(node)[0]; const category = this.usfm.substring(catCap.node.startIndex, catCap.node.endIndex).trim(); parentXmlNode.setAttribute("category", category); } else if (node.type === "fig") { const figXmlNode = parentXmlNode.ownerDocument.createElement('figure'); figXmlNode.setAttribute("style", "fig"); parentXmlNode.appendChild(figXmlNode); node.children.slice(1, -1).forEach((child)=>{ this.node2Usx(child, figXmlNode); }); } else if (node.type === "ref") { const refXmlNode = parentXmlNode.ownerDocument.createElement('ref'); parentXmlNode.appendChild(refXmlNode); node.children.slice(1, -1).forEach((child)=>{ this.node2Usx(child, refXmlNode); }); } } node2UsxGeneric(node, parentXmlNode) { const tagNode = node.children[0]; let style = this.usfm.slice(tagNode.startIndex, tagNode.endIndex).trim(); // Strip leading backslashes from the style or use node type if (style.startsWith('\\')) style = style.replace('\\', ''); if (style === "usfm") return; let childrenRangeStart = 1; // Create a 'para' element and set its style attribute const paraXmlNode = parentXmlNode.ownerDocument.createElement('para'); paraXmlNode.setAttribute('style', style); parentXmlNode.appendChild(paraXmlNode); // Loop through the child nodes and recursively process them for(let i = childrenRangeStart; i < node.children.length; i++){ const child = node.children[i]; if ($27f438441a7f3c46$require$CHAR_STYLE_MARKERS.includes(child.type) || $27f438441a7f3c46$require$NESTED_CHAR_STYLE_MARKERS.includes(child.type) || [ "text", "footnote", "crossref", "verseText", "v", "b", "milestone", "zNameSpace" ].includes(child.type)) // If the child is of one of the allowed types, nest it inside the para node this.node2Usx(child, paraXmlNode); else // Otherwise, append the child to the parent XML node this.node2Usx(child, parentXmlNode); } // Append the created para node to the parent XML node } node2Usx(node, parentXmlNode) { // Handling node types with respective functions if (node.type === "id") this.node2UsxId(node, parentXmlNode); else if (node.type === "chapter") this.node2UsxChapter(node, parentXmlNode); else if ([ "cl", "cp", "cd", "vp" ].includes(node.type)) this.node2UsxGeneric(node, parentXmlNode); else if ([ "ca", "va" ].includes(node.type)) this.node2UsxCaVa(node, parentXmlNode); else if (node.type === "v") this.node2UsxVerse(node, parentXmlNode); else if (node.type === "verseText") node.children.forEach((child)=>{ this.node2Usx(child, parentXmlNode); }); else if ([ "paragraph", "pi", "ph" ].includes(node.type)) this.node2UsxPara(node, parentXmlNode); else if ($27f438441a7f3c46$require$NOTE_MARKERS.includes(node.type)) this.node2UsxNotes(node, parentXmlNode); else if ($27f438441a7f3c46$require$CHAR_STYLE_MARKERS.concat($27f438441a7f3c46$require$NESTED_CHAR_STYLE_MARKERS, [ "xt_standalone" ]).includes(node.type)) this.node2UsxChar(node, parentXmlNode); else if (node.type.endsWith("Attribute")) this.node2UsxAttrib(node, parentXmlNode); else if (node.type === "text") { let textVal = this.usfm.slice(node.startIndex, node.endIndex); textVal = textVal.replace("~", " "); if (textVal !== "") { const textNode = parentXmlNode.ownerDocument.createTextNode(textVal); parentXmlNode.appendChild(textNode); } } else if ([ "table", "tr" ].concat($27f438441a7f3c46$require$TABLE_CELL_MARKERS).includes(node.type)) this.node2UsxTable(node, parentXmlNode); else if (node.type === "milestone" || node.type === "zNameSpace") this.node2UsxMilestone(node, parentXmlNode); else if ([ "esb", "cat", "fig", "ref" ].includes(node.type)) this.node2UsxSpecial(node, parentXmlNode); else if ($27f438441a7f3c46$require$PARA_STYLE_MARKERS.includes(node.type) || $27f438441a7f3c46$require$PARA_STYLE_MARKERS.includes(node.type.replace("\\", "").trim())) this.node2UsxGeneric(node, parentXmlNode); else if ([ "", "|" ].includes(node.type.trim())) ; else if (node.children.length > 0) node.children.forEach((child)=>{ this.node2Usx(child, parentXmlNode); }); // else { // throw new Error(`Encountered unknown element: ${node}`); // } } } $27f438441a7f3c46$export$69d2127c7776f273 = $27f438441a7f3c46$var$USXGenerator; var $be3194b3d68e926d$require$USXGenerator = $27f438441a7f3c46$export$69d2127c7776f273; var $c05a2421aa3e322c$export$9539ba3a89be1c40; var $c05a2421aa3e322c$export$88c58c54200c5b2; var $c05a2421aa3e322c$export$ec91da630f36d5ea; class $c05a2421aa3e322c$var$Filter { // Defines the values of filter options static BOOK_HEADERS = [ "ide", "usfm", "h", "toc", "toca", "imt", "is", "ip", "ipi", "im", "imi", "ipq", "imq", "ipr", "iq", "ib", "ili", "iot", "io", "iex", "imte", "ie" // intro ]; static TITLES = [ "mt", "mte", "cl", "cd", "ms", "mr", "s", "sr", "r", "d", "sp", "sd" // headings ]; static COMMENTS = [ "sts", "rem", "lit", "restore" ]; static PARAGRAPHS = [ "p", "m", "po", "pr", "cls", "pmo", "pm", "pmc", "pmr", "pi", "mi", "nb", "pc", "ph", "q", "qr", "qc", "qa", "qm", "qd", "lh", "li", "lf", "lim", "litl", 'tr', "tc", "th", "tcr", "thr", 'table', "b" ]; static CHARACTERS = [ "add", "bk", "dc", "ior", "iqt", "k", "litl", "nd", "ord", "pn", "png", "qac", "qs", "qt", "rq", "sig", "sls", "tl", "wj", "em", "bd", "bdit", "it", "no", "sc", "sup", "rb", "pro", "w", "wh", "wa", "wg", "lik", "liv", "jmp" ]; static NOTES = [ "f", "fe", "ef", "efe", "x", "ex", "fr", "ft", "fk", "fq", "fqa", "fl", "fw", "fp", "fv", "fdc", "xo", "xop", "xt", "xta", "xk", "xq", "xot", "xnt", "xdc" ]; static STUDY_BIBLE = [ 'esb', 'cat' ]; static BCV = [ 'id', 'c', 'v' ]; static TEXT = [ 'text-in-excluded-parent' ]; static keepOnly(inputUsj, includeMarkers, combineTexts = true) { // let flattenedList = [].concat(...includeMarkers); let cleanedMarkers = includeMarkers.map((marker)=>marker.replace($c05a2421aa3e322c$var$trailingNumPattern, '')); let filteredUSJ = $c05a2421aa3e322c$var$includeMarkersInUsj(inputUsj, cleanedMarkers, combineTexts); return filteredUSJ; } static remove(inputUsj, excludeMarkers, combineTexts = true) { // let flattenedList = [].concat(...excludeMarkers); let cleanedMarkers = excludeMarkers.map((marker)=>marker.replace($c05a2421aa3e322c$var$trailingNumPattern, '')); let filteredUSJ = $c05a2421aa3e322c$var$excludeMarkersInUsj(inputUsj, cleanedMarkers, combineTexts); return filteredUSJ; } } const $c05a2421aa3e322c$var$MARKERS_WITH_DISCARDABLE_CONTENTS = [ "ide", "usfm", "h", "toc", "toca", "imt", "is", "ip", "ipi", "im", "imi", "ipq", "imq", "ipr", "iq", "ib", "ili", "iot", "io", "iex", "imte", "ie", "mt", "mte", "cl", "cd", "ms", "mr", "s", "sr", "r", "d", "sp", "sd", "sts", "rem", "lit", "restore", "f", "fe", "ef", "efe", "x", "ex", "fr", "ft", "fk", "fq", "fqa", "fl", "fw", "fp", "fv", "fdc", "xo", "xop", "xt", "xta", "xk", "xq", "xot", "xnt", "xdc", "jmp", "fig", "cat", "esb", "b" ]; const $c05a2421aa3e322c$var$trailingNumPattern = /\d+$/; const $c05a2421aa3e322c$var$punctPatternNoSpaceBefore = /^[,.\-—/;:!?@$%^)}\]>”»]/; const $c05a2421aa3e322c$var$punctPatternNoSpaceAfter = /[\-—/`@^&({[<“«]$/; function $c05a2421aa3e322c$var$combineConsecutiveTextContents(contentsList) { let textCombinedContents = []; let textContents = ''; contentsList.forEach((item)=>{ if (typeof item === 'string') { if (!(textContents.endsWith(" ") || item.startsWith(" ") || textContents === '' || $c05a2421aa3e322c$var$punctPatternNoSpaceBefore.test(item) || $c05a2421aa3e322c$var$punctPatternNoSpaceAfter.test(textContents))) textContents += " "; textContents += item; } else { if (textContents !== "") { textCombinedContents.push(textContents); textContents = ""; } textCombinedContents.push(item); } }); if (textContents !== "") textCombinedContents.push(textContents); return textCombinedContents; } function $c05a2421aa3e322c$var$excludeMarkersInUsj(inputUsj, excludeMarkers, combineTexts = true, excludedParent = false) { let cleanedKids = []; if (typeof inputUsj === 'string') { if (excludedParent || excludeMarkers.includes('text-in-excluded-parent')) return []; return [ inputUsj ]; } let thisMarker = ''; if ('marker' in inputUsj) thisMarker = inputUsj.marker.replace($c05a2421aa3e322c$var$trailingNumPattern, ''); else if (inputUsj.type === 'ref') thisMarker = "ref"; let thisMarkerNeeded = true; let innerContentNeeded = true; excludedParent = false; if (excludeMarkers.includes(thisMarker)) { thisMarkerNeeded = false; excludedParent = true; if ($c05a2421aa3e322c$var$MARKERS_WITH_DISCARDABLE_CONTENTS.includes(thisMarker)) innerContentNeeded = false; } if ((thisMarkerNeeded || innerContentNeeded) && "content" in inputUsj) { inputUsj.content.forEach((item)=>{ let cleaned = $c05a2421aa3e322c$var$excludeMarkersInUsj(item, excludeMarkers, combineTexts, excludedParent); if (Array.isArray(cleaned)) cleanedKids.push(...cleaned); else cleanedKids.push(cleaned); }); if (combineTexts) cleanedKids = $c05a2421aa3e322c$var$combineConsecutiveTextContents(cleanedKids); } if (thisMarkerNeeded) { inputUsj.content = cleanedKids; return inputUsj; } return cleanedKids; } function $c05a2421aa3e322c$var$includeMarkersInUsj(inputUsj, includeMarkers, combineTexts = true, excludedParent = false) { let cleanedKids = []; if (typeof inputUsj === 'string') { if (includeMarkers.includes($c05a2421aa3e322c$var$Filter.TEXT[0])) return [ inputUsj ]; return []; } let thisMarker = ''; if ('marker' in inputUsj) thisMarker = inputUsj.marker.replace($c05a2421aa3e322c$var$trailingNumPattern, ''); else if (inputUsj.type === 'ref') thisMarker = "ref"; let thisMarkerNeeded = includeMarkers.includes(thisMarker) || thisMarker === ''; let innerContentNeeded = thisMarkerNeeded || !$c05a2421aa3e322c$var$MARKERS_WITH_DISCARDABLE_CONTENTS.includes(thisMarker); if (innerContentNeeded && "content" in inputUsj) { inputUsj.content.forEach((item)=>{ let cleaned = $c05a2421aa3e322c$var$includeMarkersInUsj(item, includeMarkers, combineTexts, !thisMarkerNeeded); if (Array.isArray(cleaned)) cleanedKids.push(...cleaned); else cleanedKids.push(cleaned); }); if (combineTexts) cleanedKids = $c05a2421aa3e322c$var$combineConsecutiveTextContents(cleanedKids); } if (thisMarker === 'c') { if (!includeMarkers.includes('ca')) delete inputUsj.altnumber; if (!includeMarkers.includes('cp')) delete inputUsj.pubnumber; } else if (thisMarker === 'v') { if (!includeMarkers.includes('va')) delete inputUsj.altnumber; if (!includeMarkers.includes('vp')) delete inputUsj.pubnumber; } if (thisMarkerNeeded) { inputUsj.content = cleanedKids; return inputUsj; } return cleanedKids; } $c05a2421aa3e322c$export$9539ba3a89be1c40 = $c05a2421aa3e322c$var$excludeMarkersInUsj; $c05a2421aa3e322c$export$88c58c54200c5b2 = $c05a2421aa3e322c$var$includeMarkersInUsj; $c05a2421aa3e322c$export$ec91da630f36d5ea = $c05a2421aa3e322c$var$Filter; var $be3194b3d68e926d$require$includeMarkersInUsj = $c05a2421aa3e322c$export$88c58c54200c5b2; var $be3194b3d68e926d$require$excludeMarkersInUsj = $c05a2421aa3e322c$export$9539ba3a89be1c40; var $be3194b3d68e926d$require$Filter = $c05a2421aa3e322c$export$ec91da630f36d5ea; const { Query: $be3194b3d68e926d$var$Query } = $a9A1a$treesitter; class $be3194b3d68e926d$var$USFMParser { constructor(usfmString = null, fromUsj = null, fromUsx = null){ let inputsGiven = 0; if (usfmString !== null) inputsGiven += 1; if (fromUsj !== null) inputsGiven += 1; if (fromUsx !== null) inputsGiven += 1; if (inputsGiven > 1) throw new Error(`Found more than one input! Only one of USFM, USJ or USX is supported in one object.`); if (inputsGiven === 0) throw Error("Missing input! Either USFM, USJ or USX is to be provided."); if (usfmString !== null) { if (typeof usfmString !== "string" || usfmString === null) throw new Error("Invalid input for USFM. Expected a string."); this.usfm = usfmString; } else if (fromUsj !== null) { this.usj = fromUsj; this.usfm = this.convertUSJToUSFM(); } else if (fromUsx !== null) { this.usx = fromUsx; this.usfm = this.convertUSXToUSFM(); } this.parser = null; this.initializeParser(); this.syntaxTree = null; this.errors = []; this.warnings = []; this.parseUSFM(); } initializeParser() { this.parser = new $a9A1a$treesitter(); this.parser.setLanguage($a9A1a$treesitterusfm3); this.parserOptions = $a9A1a$treesitter.Options = { bufferSize: 1048576 }; } toSyntaxTree() { return this.syntaxTree.toString(); } toUSJ(excludeMarkers = null, includeMarkers = null, ignoreErrors = false, combineTexts = true) { this.usj = this.convertUSFMToUSJ(excludeMarkers, includeMarkers, ignoreErrors, combineTexts); return this.usj; } usjToUsfm(usjObject) { if (typeof usjObject !== "object" || usjObject === null || !usjObject.hasOwnProperty('type')) throw new Error("Invalid input for USJ. Expected USJ json object."); if (!this.parser) this.initializeParser(); this.usj = usjObject; this.usfm = this.convertUSJToUSFM(); return this.usfm; } parseUSFM() { let tree = null; try { if (this.usfm.length > 25000) tree = this.parser.parse(this.usfm, null, this.parserOptions); else tree = this.parser.parse(this.usfm); } catch (err) { throw err; // console.log("Error in parser.parse()"); // console.log(err.toString()); // console.log(this.usfm); } this.checkForErrors(tree); this.checkforMissing(tree.rootNode); // if (error) throw error; this.syntaxTree = tree.rootNode; } checkForErrors(tree) { const errorQuery = new $be3194b3d68e926d$var$Query($a9A1a$treesitterusfm3, "(ERROR) @errors"); const errors = errorQuery.captures(tree.rootNode); if (errors.length > 0) { this.errors = errors.map((error)=>`At ${error.node.startPosition.row}:${error.node.startPosition.column}, Error: ${this.usfm.substring(error.node.startIndex, error.node.endIndex)}`); return new Error(`Errors found in USFM: ${this.errors.join(", ")}`); } } checkforMissing(node) { for (let n of node.children){ if (n.isMissing) this.errors.push(`At ${n.startPosition.row + 1}:${n.startPosition.column}, Error: Missing ${n.type}`); this.checkforMissing(n); } } convertUSJToUSFM() { const outputUSFM = new $be3194b3d68e926d$require$USFMGenerator().usjToUsfm(this.usj); // Simulated conversion return outputUSFM; } convertUSXToUSFM() { try { $a9A1a$assert(1 <= this.usx.nodeType && this.usx.nodeType <= 12, 'Input must be an instance of xmldom Document or Element'); if (this.usx.tagName !== "usx") { $a9A1a$assert(this.usx.getElementsByTagName('usx').length === 1, 'Expects a node. Refer docs: https://docs.usfm.bible/usfm/3.1/syntax.html#_usx_usfm_xml'); this.usx = this.usx.getElementsByTagName('usx')[0]; } // assert(this.usx.childNodes[0].tagName === 'book', " expected as first element in ") } catch (err) { throw new Error("USX not in expected format. " + err.message); } try { const usfmGen = new $be3194b3d68e926d$require$USFMGenerator(); usfmGen.usxToUsfm(this.usx); // console.log(usfmGen.usfmString) return usfmGen.usfmString; } catch (err) { let message = "Unable to do the conversion from USX to USFM. "; throw new Error(message, { cause: err }); } } convertUSFMToUSJ(excludeMarkers = null, includeMarkers = null, ignoreErrors = false, combineTexts = true) { if (!ignoreErrors && this.errors.length > 0) { let errorString = this.errors.join("\n\t"); throw new Error(`Errors present:\n\t${errorString}\nUse ignoreErrors = true, as third parameter of toUSJ(), to generate output despite errors.`); } let outputUSJ; try { let usjGenerator = new $be3194b3d68e926d$require$USJGenerator($a9A1a$treesitterusfm3, this.usfm); usjGenerator.nodeToUSJ(this.syntaxTree, usjGenerator.jsonRootObj); outputUSJ = usjGenerator.jsonRootObj; } catch (err) { let message = "Unable to do the conversion. "; if (this.errors) { let errorString = this.errors.join("\n\t"); message += `Could be due to an error in the USFM\n\t${errorString}`; } else message = err.message; return { error: message }; } if (includeMarkers) outputUSJ = $be3194b3d68e926d$require$Filter.keepOnly(outputUSJ, [ ...includeMarkers, 'USJ' ], combineTexts); if (excludeMarkers) outputUSJ = $be3194b3d68e926d$require$Filter.remove(outputUSJ, excludeMarkers, combineTexts); return outputUSJ; } toList(excludeMarkers = null, includeMarkers = null, ignoreErrors = false, combineTexts = true) { /* Uses the toJSON function and converts JSON to CSV To be re-implemented to work with the flat JSON schema */ if (!ignoreErrors && this.errors.length > 0) { let errorString = this.errors.join("\n\t"); throw new Error(`Errors present:\n\t${errorString}\nUse ignoreErrors=true to generate output despite errors`); } try { const usjDict = this.toUSJ(excludeMarkers, includeMarkers, ignoreErrors, combineTexts); const listGenerator = new $be3194b3d68e926d$require$ListGenerator(); listGenerator.usjToList(usjDict); return listGenerator.list; } catch (exe) { let message = "Unable to do the conversion. "; if (this.errors.length > 0) { let errorString = this.errors.join("\n\t"); message += `Could be due to an error in the USFM\n\t${errorString}`; } throw new Error(message, { cause: exe }); } } toUSX(ignoreErrors = false) { /* Convert the syntax_tree to the XML format (USX) */ if (!ignoreErrors && this.errors.length > 0) { let errorString = this.errors.join("\n\t"); throw new Error(`Errors present:\n\t${errorString}\nUse ignoreErrors=true to generate output despite errors`); } let xmlContent = null; try { // Initialize the USX generator (assuming the constructor is already implemented in JS) const usxGenerator = new $be3194b3d68e926d$require$USXGenerator($a9A1a$treesitterusfm3, this.usfm); // Process the syntax tree and convert to USX format usxGenerator.node2Usx(this.syntaxTree, usxGenerator.xmlRootNode); // xmlContent = usxSerializer.serializeToString(usxGenerator.xmlRootNode); xmlContent = usxGenerator.xmlRootNode; } catch (exe) { let message = "Unable to do the conversion. "; if (this.errors.length > 0) { let errorString = this.errors.join("\n\t"); message += `Could be due to an error in the USFM\n\t${errorString}`; } throw new Error(message, { cause: exe }); } // Return the generated XML structure (in JSON format) return xmlContent; } } $be3194b3d68e926d$export$db89aa78daab09ca = $be3194b3d68e926d$var$USFMParser; $be3194b3d68e926d$export$ec91da630f36d5ea = $be3194b3d68e926d$require$Filter; // exports.Format = Format; var $4fa36e821943b400$require$USFMParser = $be3194b3d68e926d$export$db89aa78daab09ca; var $4fa36e821943b400$require$Filter = $be3194b3d68e926d$export$ec91da630f36d5ea; var $4fa36e821943b400$require$Format = $be3194b3d68e926d$exports.Format; var $53823d6b08729493$export$9eeb22c0bba4ed5e; var $56ae84b86d9e5f3e$export$1bffd857d9f16e91; $56ae84b86d9e5f3e$export$1bffd857d9f16e91 = { "$schema": "http://json-schema.org/draft-07/schema", "$id": "https://github.com/usfm-bible/tcdocs/blob/main/grammar/usj.js", "title": "Unified Scripture JSON", "description": "The JSON varient of USFM and USX data models", "type": "object", "$defs": { "markerObject": { "type": "object", "properties": { "type": { "description": "The kind/category of node or element this is, corresponding the USFM marker and USX node", "type": "string" }, "marker": { "description": "The corresponding marker in USFM or style in USX", "type": "string" }, "content": { "type": "array", "items": { "anyOf": [ { "type": "string" }, { "$ref": "#/$defs/markerObject" } ] } }, "sid": { "description": "Indicates the Book-chapter-verse value in the paragraph based structure", "type": "string" }, "number": { "description": "Chapter number or verse number", "type": "string" }, "code": { "description": "The 3-letter book code in id element", "pattern": "^[0-9A-Z]{3}$", "type": "string" }, "altnumber": { "description": "Alternate chapter number or verse number", "type": "string" }, "pubnumber": { "description": "Published character of chapter or verse", "type": "string" }, "caller": { "description": "Caller character for footnotes and cross-refs", "type": "string" }, "align": { "description": "Alignment of table cells", "type": "string" }, "category": { "description": "Category of extended study bible sections", "type": "string" } }, "required": [ "type" ] } }, "properties": { "type": { "description": "The kind of node/element/marker this is", "type": "string" }, "version": { "description": "The USJ spec version", "type": "string" }, "content": { "description": "The JSON representation of scripture contents from USFM/USX", "type": "array", "items": { "anyOf": [ { "type": "string" }, { "$ref": "#/$defs/markerObject" } ] } } }, "required": [ "type", "version", "content" ] }; var $53823d6b08729493$require$USJ_SCHEMA = $56ae84b86d9e5f3e$export$1bffd857d9f16e91; const { Query: $53823d6b08729493$var$Query } = $a9A1a$treesitter; class $53823d6b08729493$var$Validator { constructor(usjSchemaPath = null){ this.USFMParser = new $a9A1a$treesitter(); this.USFMParser.setLanguage($a9A1a$treesitterusfm3); this.parserOptions = $a9A1a$treesitter.Options = { bufferSize: 1048576 }; this.USFMErrors = []; // Load the schema for validation this.USJValidator = null; try { const ajv = new $a9A1a$ajv(); if (usjSchemaPath === null) this.USJValidator = ajv.compile($53823d6b08729493$require$USJ_SCHEMA); else { const schemaStr = $a9A1a$nodefs.readFileSync(usjSchemaPath, 'utf8'); const schema = JSON.parse(schemaStr); this.USJValidator = ajv.compile(schema); } } catch (error) { console.error("Error loading schema:", error); } this.message = ""; this.modifiedUSFM = ""; this.usfm = ""; } isValidUSJ(usj) { this.message = ""; if (this.USJValidator(usj) === true) return true; else { for (let err of this.USJValidator.errors)this.message += `Error at ${err.instancePath}: ${err.message}\n`; return false; } } isValidUSFM(usfm) { this.usfm = usfm; this.USFMErrors = []; let tree = null; if (usfm.length > 25000) tree = this.USFMParser.parse(usfm, null, this.parserOptions); else tree = this.USFMParser.parse(usfm); const errorQuery = new $53823d6b08729493$var$Query($a9A1a$treesitterusfm3, "(ERROR) @errors"); const errors = errorQuery.captures(tree.rootNode); for (let error of errors)// console.log(getAllProperties(error.node)); this.USFMErrors.push(error.node); this.checkForMissing(tree.rootNode); if (this.USFMErrors.length > 0) { this.message = this.formatErrors(); return false; } return true; } checkForMissing(node) { for (let n of node.children)if (n.isMissing) this.USFMErrors.push(n); else this.checkForMissing(n); } formatErrors() { const errLines = this.USFMErrors.map((err)=>{ if (err.isMissing) { const start = Math.max(0, err.startIndex - 3); const end = Math.min(this.usfm.length, err.startIndex + 10); return `At ${err.startIndex}:Missing something here:${this.usfm.slice(start, end)}`; } else return `At ${err.startPosition.row}:${err.startPosition.column}, Error: ${this.usfm.substring(err.startIndex, err.endIndex)}`; }); return `Errors present:\n\t${errLines.join('\n\t')}`; } autoFixUSFM(usfm, fixed = false) { if (this.isValidUSFM(usfm)) { if (fixed) this.message = "Fixed Errors in USFM"; else this.message = "No Errors in USFM"; return usfm; } let modifiedUSFM = usfm; let changed = false; for (let error of this.USFMErrors){ const errorText = usfm.substring(error.startIndex, error.endIndex); // No \P after \s5 if (error.isError && errorText.startsWith("\\s5") && !error.children.some((ch)=>ch.type === "paragraph")) { // console.log("Match 1"); modifiedUSFM = modifiedUSFM.replace(/\\s5[\s\n\r]*/g, '\\s5 \n\\p\n'); changed = true; } else if (error.isMissing && error.parent.type === "sTag" && error.toString() === '(MISSING " ")') { // console.log("Match 2"); modifiedUSFM = modifiedUSFM.replace(/\\s5\n/g, '\\s5 \n'); changed = true; } else if ($53823d6b08729493$var$bookCodeMissingPattern.test(modifiedUSFM)) { // console.log("Match 3"); modifiedUSFM = modifiedUSFM.replace(/\\id[\s\n\r]*\\/g, '\\id XXX xxx\n\\'); changed = true; } else if (error.isError && errorText.startsWith("\\v") && error.parent.type === "s" && !error.children.some((ch)=>ch.type === "paragraph")) { // console.log("Match 4"); const start = error.parent.startIndex; const end = error.startIndex; const toReplace = modifiedUSFM.slice(start, end); modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`); changed = true; } else if ($53823d6b08729493$var$vWithoutSpacePattern.test(errorText)) { // console.log("Match 5"); modifiedUSFM = modifiedUSFM.replace($53823d6b08729493$var$vWithoutSpacePattern, "$1 $2"); changed = true; } else if ($53823d6b08729493$var$cWithoutSpacePattern.test(errorText)) { // console.log("Match 6"); modifiedUSFM = modifiedUSFM.replace($53823d6b08729493$var$cWithoutSpacePattern, "$1 $2"); changed = true; } else if (error.isError && errorText.startsWith("\\v") && error.previousSibling.type === "chapter" && !error.children.some((ch)=>ch.type === "paragraph")) { // console.log("Match 7"); const start = error.previousSibling.startIndex; const end = error.startIndex; const toReplace = modifiedUSFM.slice(start, end); modifiedUSFM = modifiedUSFM.replace(toReplace, `${toReplace}\\p\n`); changed = true; } else if (errorText.startsWith("\\") && !$53823d6b08729493$var$validMarkersPattern.test(errorText)) { // console.log("Match 8"); modifiedUSFM = modifiedUSFM.replace(errorText, errorText.slice(1)); changed = true; } else if (errorText.startsWith("\\") && $53823d6b08729493$var$validMarkersPattern.test(errorText)) { // console.log("Match 9"); const start = Math.max(0, error.startIndex - 5); const end = Math.min(modifiedUSFM.length, error.endIndex + 5); const toReplace = modifiedUSFM.slice(start, end); const replacement = toReplace.replace(errorText, ""); modifiedUSFM = modifiedUSFM.replace(toReplace, replacement); changed = true; } else if (errorText.trim() === "|") { // console.log("Match 10"); // console.log(errorText); const start = Math.max(0, error.startIndex - 5); const end = Math.min(modifiedUSFM.length, error.endIndex + 5); const toReplace = modifiedUSFM.slice(start, end); const replacement = toReplace.replace(errorText, ""); modifiedUSFM = modifiedUSFM.replace(toReplace, replacement); changed = true; } else if (error.parent.type === "chapter" && error.previousSibling.type === "c" && !errorText.includes("\\")) { // console.log("Match 11"); modifiedUSFM = modifiedUSFM.replace(errorText, ""); changed = true; } } if (!changed || modifiedUSFM === usfm) { const errStr = this.formatErrors(); this.message = `Cannot fix these errors:\n\t${errStr}`; return modifiedUSFM; } // return modifiedUSFM return this.autoFixUSFM(modifiedUSFM, true); } } const $53823d6b08729493$var$bookCodeMissingPattern = /\\id[\s\n\r]*\\/; const $53823d6b08729493$var$vWithoutSpacePattern = /(\\v)(\d+)/; const $53823d6b08729493$var$cWithoutSpacePattern = /(\\c)(\d+)/; const $53823d6b08729493$var$validMarkersPattern = /(\\id|\\usfm|\\ide|\\ref|\\h|\\toc|\\toca|\\sts|\\rem|\\restore|\\lit|\\iqt|\\imt|\\imte|\\is|\\io|\\ior|\\iot|\\ip|\\im|\\ipi|\\imi|\\ili|\\ipq|\\imq|\\ipr|\\ib|\\iq|\\ie|\\iex|\\v|\\va|\\vp|\\c|\\cl|\\ca|\\cp|\\cd|\\mt|\\mte|\\ms|\\mr|\\s|\\sr|\\r|\\sp|\\d|\\sd|\\p|\\m|\\po|\\pr|\\cls|\\pmo|\\pm|\\pmc|\\pmr|\\pi|\\mi|\\nb|\\pc|\\ph|\\phi|\\b|\\q|\\qr|\\qc|\\qs|\\qa|\\qac|\\qm|\\qd|\\lh|\\lf|\\li|\\lim|\\liv|\\lik|\\litl|\\tr|\\th|\\thr|\\tc|\\tcr|\\f|\\fe|\\ef|\\fr|\\fq|\\fqa|\\fk|\\fl|\\fw|\\fp|\\ft|\\fdc|\\fv|\\fm|\\x|\\xo|\\xk|\\xq|\\xt|\\xta|\\xop|\\xot|\\xnt|\\xdc|\\rq|\\add|\\bk|\\dc|\\k|\\nd|\\ord|\\pn|\\png|\\addpn|\\qt|\\sig|\\sls|\\tl|\\wj|\\em|\\bd|\\it|\\bdit|\\no|\\sc|\\sup|\\ndx|\\pro|\\rb|\\w|\\wg|\\wh|\\wa|\\fig|\\jmp|\\pb|\\z|\\esb|\\esbe|\\cat)(\d|\s|\n|\r|$)/; $53823d6b08729493$export$9eeb22c0bba4ed5e = $53823d6b08729493$var$Validator; var $4fa36e821943b400$require$Validator = $53823d6b08729493$export$9eeb22c0bba4ed5e; $4fa36e821943b400$export$db89aa78daab09ca = $4fa36e821943b400$require$USFMParser; $4fa36e821943b400$export$ec91da630f36d5ea = $4fa36e821943b400$require$Filter; $4fa36e821943b400$export$93514d28bd18d75a = $4fa36e821943b400$require$Format; $4fa36e821943b400$export$9eeb22c0bba4ed5e = $4fa36e821943b400$require$Validator; //# sourceMappingURL=index.cjs.map