@helloao/tools 0.2.0 → 0.3.0
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/dist/cjs/generation/api.cjs +856 -36
- package/dist/cjs/generation/api.cjs.map +3 -3
- package/dist/cjs/generation/audio.cjs +5 -5
- package/dist/cjs/generation/audio.cjs.map +1 -1
- package/dist/cjs/generation/book-order.cjs.map +1 -1
- package/dist/cjs/generation/common-types.cjs +359 -14
- package/dist/cjs/generation/common-types.cjs.map +2 -2
- package/dist/cjs/generation/dataset.cjs +13 -9
- package/dist/cjs/generation/dataset.cjs.map +2 -2
- package/dist/cjs/generation/index.cjs +8 -5
- package/dist/cjs/generation/index.cjs.map +2 -2
- package/dist/cjs/generation/simple.cjs +294 -0
- package/dist/cjs/generation/simple.cjs.map +7 -0
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/log.cjs.map +1 -1
- package/dist/cjs/parser/codex-parser.cjs +3 -3
- package/dist/cjs/parser/codex-parser.cjs.map +3 -3
- package/dist/cjs/parser/commentary-csv-parser.cjs +14 -3
- package/dist/cjs/parser/commentary-csv-parser.cjs.map +3 -3
- package/dist/cjs/parser/index.cjs +1 -1
- package/dist/cjs/parser/iterators.cjs.map +1 -1
- package/dist/cjs/parser/lockman-parser.cjs +1 -1
- package/dist/cjs/parser/lockman-parser.cjs.map +1 -1
- package/dist/cjs/parser/tyndale-xml-parser.cjs +1 -1
- package/dist/cjs/parser/tyndale-xml-parser.cjs.map +1 -1
- package/dist/cjs/parser/types.cjs.map +1 -1
- package/dist/cjs/parser/usfm-parser.cjs +2 -2
- package/dist/cjs/parser/usfm-parser.cjs.map +1 -1
- package/dist/cjs/parser/usx-parser.cjs +122 -26
- package/dist/cjs/parser/usx-parser.cjs.map +2 -2
- package/dist/cjs/parser/words.cjs +187 -0
- package/dist/cjs/parser/words.cjs.map +7 -0
- package/dist/cjs/utils.cjs +1 -1
- package/dist/esm/generation/api.js +835 -37
- package/dist/esm/generation/api.js.map +3 -3
- package/dist/esm/generation/audio.js +1 -1
- package/dist/esm/generation/audio.js.map +1 -1
- package/dist/esm/generation/book-order.js.map +1 -1
- package/dist/esm/generation/common-types.js +327 -14
- package/dist/esm/generation/common-types.js.map +2 -2
- package/dist/esm/generation/dataset.js +6 -2
- package/dist/esm/generation/dataset.js.map +2 -2
- package/dist/esm/generation/index.js +2 -1
- package/dist/esm/generation/index.js.map +2 -2
- package/dist/esm/generation/simple.js +260 -0
- package/dist/esm/generation/simple.js.map +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/log.js.map +1 -1
- package/dist/esm/parser/codex-parser.js +3 -3
- package/dist/esm/parser/codex-parser.js.map +3 -3
- package/dist/esm/parser/commentary-csv-parser.js +3 -2
- package/dist/esm/parser/commentary-csv-parser.js.map +2 -2
- package/dist/esm/parser/iterators.js.map +1 -1
- package/dist/esm/parser/lockman-parser.js +1 -1
- package/dist/esm/parser/lockman-parser.js.map +1 -1
- package/dist/esm/parser/tyndale-xml-parser.js +1 -1
- package/dist/esm/parser/tyndale-xml-parser.js.map +1 -1
- package/dist/esm/parser/usfm-parser.js +1 -1
- package/dist/esm/parser/usfm-parser.js.map +1 -1
- package/dist/esm/parser/usx-parser.js +130 -26
- package/dist/esm/parser/usx-parser.js.map +2 -2
- package/dist/esm/parser/words.js +149 -0
- package/dist/esm/parser/words.js.map +7 -0
- package/dist/types/generation/api.d.ts +6879 -918
- package/dist/types/generation/common-types.d.ts +432 -2
- package/dist/types/generation/index.d.ts +2 -1
- package/dist/types/generation/simple.d.ts +110 -0
- package/dist/types/parser/commentary-csv-parser.d.ts +1 -1
- package/dist/types/parser/lockman-parser.d.ts +1 -1
- package/dist/types/parser/tyndale-xml-parser.d.ts +1 -1
- package/dist/types/parser/types.d.ts +63 -0
- package/dist/types/parser/usx-parser.d.ts +6 -5
- package/dist/types/parser/words.d.ts +104 -0
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/iterators.ts"],
|
|
4
|
-
"sourcesContent": ["import { getLogger } from '../log.js';\
|
|
4
|
+
"sourcesContent": ["import { getLogger } from '../log.js';\n\n/**\n * Defines an interface that represents an iterator that can be rewound.\n */\nexport interface RewindableIterator<T> extends IterableIterator<T> {\n /**\n * Rewinds the iterator by the specified number of elements.\n * @param number The number of elements to rewind.\n */\n rewind(number: number): void;\n}\n\n/**\n * Defines a class that implements an iterator that can be rewound.\n */\nexport class Rewindable<T> implements RewindableIterator<T> {\n buffer: T[] = [];\n\n private _bufferSize: number = 0;\n private _position: number = -1;\n private _iterator: IterableIterator<T>;\n\n constructor(iterator: IterableIterator<T>, bufferSize: number = 2) {\n this._iterator = iterator;\n this._bufferSize = bufferSize;\n\n if (this._iterator.return) {\n this.return = (value?: any) => {\n return this._iterator.return!(value);\n };\n }\n if (this._iterator.throw) {\n this.throw = (value?: any) => {\n return this._iterator.throw!(value);\n };\n }\n }\n\n rewind(number: number): void {\n this._position += number;\n }\n\n [Symbol.iterator](): IterableIterator<T> {\n return this;\n }\n\n next(...args: [] | [undefined]): IteratorResult<T, any> {\n if (this._position >= 0) {\n let item = this.buffer[this._position];\n this._position--;\n return {\n value: item,\n done: false,\n };\n }\n\n let result = this._iterator.next(...args);\n this.buffer.unshift(result.value);\n if (this.buffer.length > this._bufferSize) {\n this.buffer.splice(\n this._bufferSize,\n this.buffer.length - this._bufferSize\n );\n }\n return result;\n }\n\n return?(value?: any): IteratorResult<T, any>;\n throw?(e?: any): IteratorResult<T, any>;\n}\n\nexport function* debug(label: string, iterator: IterableIterator<any>) {\n const logger = getLogger();\n for (let value of uncompletable(iterator)) {\n if (value instanceof Element) {\n logger.log(label, value.outerHTML);\n } else if (value instanceof Node) {\n logger.log(label, value.textContent);\n } else {\n logger.log(label, value);\n }\n yield value;\n }\n}\n\n/**\n * Creates a new rewindable iterator from the given iterator.\n * @param iterator The iterator.\n * @param bufferSize The size of the buffer.\n */\nexport function rewindable<T>(\n iterator: IterableIterator<T>,\n bufferSize: number = 2\n): Rewindable<T> {\n return new Rewindable(iterator, bufferSize);\n}\n\nfunction* iterateNodes(node: Node) {\n for (let i = 0; i < node.childNodes.length; i++) {\n yield node.childNodes[i];\n }\n}\n\n/**\n * Gets the char element that is the parent of the given node.\n * @param node The node.\n */\nexport function parentChar(node: Node): Element | null {\n return matchingParent(\n node,\n (n) => n instanceof Element && n.nodeName === 'char'\n ) as Element | null;\n}\n\n/**\n * Gets the note element that is the parent of the given node.\n * @param node The node.\n */\nexport function parentNote(node: Node): Element | null {\n return matchingParent(\n node,\n (n) => n instanceof Element && n.nodeName === 'note'\n ) as Element | null;\n}\n\n/**\n * Gets the parent node that matches the given filter.\n * @param node The node to start the search from.\n * @param filter The filter that should be used.\n */\nexport function matchingParent(\n node: Node,\n filter: (node: Node) => boolean\n): Node | null {\n let parent = node.parentNode;\n while (parent) {\n if (filter(parent)) {\n return parent;\n }\n parent = parent.parentNode;\n }\n return null;\n}\n\n/**\n * Determines if the given node is a child of the parent node.\n * @param node The node to test.\n * @param parent The parent.\n * @returns\n */\nexport function isParent(node: Node, parent: Node): boolean {\n let parentNode = node.parentNode;\n while (parentNode) {\n if (parentNode === parent) {\n return true;\n }\n parentNode = parentNode.parentNode;\n }\n return false;\n}\n\n/**\n * Iterates through all of the nodes in the tree in a depth-first traversal.\n * @param node The node to start the traversal from.\n */\nexport function iterateAll(node: Node): RewindableIterator<Node> {\n return rewindable(_iterateAll(node));\n}\n\nexport function* iterateUntil<T>(\n iterator: IterableIterator<T>,\n predicate: (value: T) => boolean\n): IterableIterator<T> {\n for (let value of iterator) {\n if (predicate(value)) {\n return;\n }\n yield value;\n }\n}\n\nfunction* _iterateAll(node: Node): IterableIterator<Node> {\n for (let child of node.childNodes) {\n yield child;\n yield* iterateAll(child);\n }\n}\n\n/**\n * Iterates only the elements in the iterator.\n * @param iterator The iterator that should be used.\n */\nexport function* elements(\n iterator: IterableIterator<Node>\n): IterableIterator<Element> {\n for (let node of uncompletable(iterator)) {\n if (node instanceof Element) {\n yield node;\n }\n }\n}\n\n/**\n * Iterates only the children of the given node in the iterator.\n * @param iterator The iterator that should be used.\n * @param parent The parent node.\n */\nexport function* children(\n iterator: RewindableIterator<Node>,\n parent: Node\n): IterableIterator<Node> {\n for (let node of uncompletable(iterator)) {\n if (!isParent(node, parent)) {\n iterator.rewind(1);\n return;\n }\n\n yield node;\n }\n}\n\n/**\n * Wraps the given iterable in a generator that will prevent consumers from calling return() on the iterator.\n * @param iterable The iterable.\n */\nexport function* uncompletable<T>(\n iterable: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { done, value } = iterable.next();\n if (done) {\n return;\n }\n yield value;\n }\n}\n\n/**\n * Converts the given iterable into an async iterable.\n * @param input The input iterable.\n */\nexport async function* toAsyncIterable<T>(\n input: Iterable<T>\n): AsyncIterable<T> {\n for (let item of input) {\n yield item;\n }\n}\n\n/**\n * Batches items from the given iterator.\n * @param input The input iterator.\n * @param batchSize The size of each batch.\n */\nexport function* batch<T>(\n input: Iterable<T>,\n batchSize: number\n): Iterable<T[]> {\n while (true) {\n let batch = [] as T[];\n for (let item of input) {\n batch.push(item);\n if (batch.length >= batchSize) {\n break;\n }\n }\n\n if (batch.length === 0) {\n return;\n }\n\n yield batch;\n }\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA0B;AAgBnB,MAAM,WAA+C;AAAA,EACxD,SAAc,CAAC;AAAA,EAEP,cAAsB;AAAA,EACtB,YAAoB;AAAA,EACpB;AAAA,EAER,YAAY,UAA+B,aAAqB,GAAG;AAC/D,SAAK,YAAY;AACjB,SAAK,cAAc;AAEnB,QAAI,KAAK,UAAU,QAAQ;AACvB,WAAK,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O,UAAU,cACb,UACmB;AACnB,SAAO,MAAM;AACT,UAAM,EAAE,MAAM,MAAM,IAAI,SAAS,KAAK;AACtC,QAAI,MAAM;AACN;AAAA,IACJ;AACA,UAAM;AAAA,EACV;AACJ;AAMA,gBAAuB,gBACnB,OACgB;AAChB,WAAS,QAAQ,OAAO;AACpB,UAAM;AAAA,EACV;AACJ;AAOO,UAAU,MACb,OACA,WACa;AACb,SAAO,MAAM;AACT,QAAIA,SAAQ,CAAC;AACb,aAAS,QAAQ,OAAO;AACpB,MAAAA,OAAM,KAAK,IAAI;AACf,UAAIA,OAAM,UAAU,WAAW;AAC3B;AAAA,MACJ;AAAA,IACJ;AAEA,QAAIA,OAAM,WAAW,GAAG;AACpB;AAAA,IACJ;AAEA,UAAMA;AAAA,EACV;AACJ;",
|
|
6
6
|
"names": ["batch"]
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(lockman_parser_exports, {
|
|
|
22
22
|
LockmanParser: () => LockmanParser
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(lockman_parser_exports);
|
|
25
|
-
var import_book_order = require("../generation/book-order");
|
|
25
|
+
var import_book_order = require("../generation/book-order.js");
|
|
26
26
|
const LOCKMAN_PARSER_VERSION = 3;
|
|
27
27
|
const bookNumberIdMap = /* @__PURE__ */ new Map();
|
|
28
28
|
for (const [id, order] of import_book_order.bookOrderMap) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/lockman-parser.ts"],
|
|
4
|
-
"sourcesContent": ["import {\r\n ParseTree,\r\n Chapter,\r\n Verse,\r\n Heading,\r\n Footnote,\r\n Text,\r\n FootnoteReference,\r\n HebrewSubtitle,\r\n} from './types';\r\nimport { bookOrderMap } from '../generation/book-order';\r\n\r\nexport const LOCKMAN_PARSER_VERSION = 3;\r\n\r\nconst bookNumberIdMap = new Map<number, string>();\r\nfor (const [id, order] of bookOrderMap) {\r\n if (!bookNumberIdMap.has(order)) {\r\n bookNumberIdMap.set(order, id);\r\n }\r\n}\r\n\r\nexport class LockmanParser {\r\n parse(text: string): ParseTree[] {\r\n const roots: ParseTree[] = [];\r\n let currentRoot: ParseTree | null = null;\r\n let currentChapter: Chapter | null = null;\r\n let currentVerse: Verse | null = null;\r\n\r\n // Splits text into tokens based on structural tags\r\n // Identify major blocks: BN, CN, SH, and Verse Starters (V, C, PM, A, PO)\r\n // Note: SH and CN content is strictly inside the tag.\r\n // Verse content follows the tag.\r\n // We use a regex that captures the tag AND its \"attributes\" like {{..}}Num<T> for verses.\r\n\r\n // Regex for structural separators\r\n // Captures:\r\n // 1. Title: <BN>...</BN>\r\n // 2. Chapter Heading: <CN>...</CN> or <SN>...</SN>\r\n // 3. Section Heading: <SH>...</SH> or <SS>...</SS>\r\n // 4. Verse Start: (<V>|<C>|<CC>|<CP>|<PM>|<A>|<PO>|<P>|<PN>){{...}}Number<T>\r\n\r\n const structureRegex =\r\n /(<BN>.*?<\\/BN>)|((?:<CN>.*?<\\/CN>)|(?:<SN>.*?<\\/SN>))|((?:<SH>.*?<\\/SH>)|(?:<SS>.*?<\\/SS>))|((?:<V>|<C>|<CC>|<CP>|<PM>|<A>|<PO>|<P>|<PN>)\\{\\{.*?\\}\\}\\d+(?:<T>|\\^)(?:\\{.*?\\})?)/g;\r\n\r\n let lastIndex = 0;\r\n let match;\r\n let isPoem = false;\r\n\r\n while ((match = structureRegex.exec(text)) !== null) {\r\n const fullMatch = match[0];\r\n const startIndex = match.index;\r\n\r\n // Content belonging to the PREVIOUS structural element\r\n if (startIndex > lastIndex) {\r\n const content = text.substring(lastIndex, startIndex);\r\n if (currentVerse && currentChapter) {\r\n this.parseVerseContent(\r\n content,\r\n currentVerse,\r\n currentChapter,\r\n isPoem\r\n );\r\n }\r\n }\r\n\r\n lastIndex = startIndex + fullMatch.length;\r\n\r\n if (match[1]) {\r\n // <BN>Title</BN>\r\n // Start of a NEW Book\r\n const title = match[1].replace(/<\\/?BN>/g, '').trim();\r\n\r\n currentRoot = {\r\n type: 'root',\r\n title: title,\r\n content: [],\r\n };\r\n roots.push(currentRoot);\r\n\r\n // Reset context for new book\r\n currentChapter = null;\r\n currentVerse = null;\r\n } else if (match[2]) {\r\n // <CN>CHAPTER 1</CN> or <SN>PSALM 1</SN>\r\n // Start new Chapter\r\n // Ensure we have a root (handle case where no <BN> provided, implicitly create one? Or just attach to last root)\r\n if (!currentRoot) {\r\n // Fallback if no <BN> was found first\r\n currentRoot = {\r\n type: 'root',\r\n content: [],\r\n };\r\n roots.push(currentRoot);\r\n }\r\n\r\n // Remove tags: <CN>, </CN>, <SN>, </SN>\r\n const inner = match[2].replace(/<\\/?(CN|SN)>/g, '').trim();\r\n const numMatch = inner.match(/\\d+/);\r\n const num = numMatch ? parseInt(numMatch[0], 10) : 0;\r\n\r\n currentChapter = {\r\n type: 'chapter',\r\n number: num,\r\n content: [],\r\n footnotes: [],\r\n };\r\n currentRoot.content.push(currentChapter);\r\n currentVerse = null;\r\n } else if (match[3]) {\r\n // <SH>Heading</SH> or <SS>Subtitle</SS>\r\n if (!currentRoot) {\r\n currentRoot = { type: 'root', content: [] };\r\n roots.push(currentRoot);\r\n }\r\n\r\n const raw = match[3];\r\n if (raw.startsWith('<SS>')) {\r\n // Hebrew subtitle in Psalms\r\n const inner = raw.replace(/<\\/?SS>/g, '').trim();\r\n const subtitle: HebrewSubtitle = {\r\n type: 'hebrew_subtitle',\r\n content: [],\r\n };\r\n\r\n if (currentChapter) {\r\n this.parseHebrewSubtitleContent(\r\n inner,\r\n subtitle,\r\n currentChapter\r\n );\r\n currentChapter.content.push(subtitle);\r\n }\r\n } else {\r\n // Section heading\r\n const inner = raw.replace(/<\\/?SH>/g, '').trim();\r\n const normalized = inner.replace(/<\\\\>|<\\/?>|[{}]/g, '');\r\n const heading: Heading = {\r\n type: 'heading',\r\n content: [normalized],\r\n };\r\n if (currentChapter) {\r\n currentChapter.content.push(heading);\r\n } else {\r\n // Start of book heading? Not typical in this structure but possible\r\n currentRoot.content.push(heading);\r\n }\r\n }\r\n } else if (match[4]) {\r\n // Verse Start: <Tag>{{Ref}}Number<T>\r\n // Extract Verse Number\r\n const tagContent = match[4];\r\n if (currentRoot && !currentRoot.id) {\r\n const bookId = this.getBookIdFromVerseTag(tagContent);\r\n if (bookId) {\r\n currentRoot.id = bookId;\r\n }\r\n }\r\n // Regex to extract digits before <T>\r\n const vNumMatch = tagContent.match(/(\\d+)(?:<T>|\\^)/);\r\n const vNum = vNumMatch ? parseInt(vNumMatch[1], 10) : 0;\r\n\r\n if (currentChapter) {\r\n // Check for Paragraph Marker\r\n if (tagContent.startsWith('<PM>')) {\r\n currentChapter.content.push({ type: 'line_break' });\r\n }\r\n\r\n // Update global isPoem flag\r\n isPoem = /<(?:P|PO|PN|CC|CP)>/.test(tagContent);\r\n\r\n currentVerse = {\r\n type: 'verse',\r\n number: vNum,\r\n content: [],\r\n };\r\n currentChapter.content.push(currentVerse);\r\n }\r\n }\r\n }\r\n\r\n // Process remaining text after the last match\r\n if (lastIndex < text.length) {\r\n const content = text.substring(lastIndex);\r\n if (currentVerse && currentChapter) {\r\n this.parseVerseContent(\r\n content,\r\n currentVerse,\r\n currentChapter,\r\n isPoem\r\n );\r\n }\r\n }\r\n\r\n return roots;\r\n }\r\n\r\n private getBookIdFromVerseTag(tagContent: string): string | null {\r\n const match = tagContent.match(/\\{\\{(\\d+)::/);\r\n if (!match) {\r\n return null;\r\n }\r\n\r\n const bookNumber = parseInt(match[1], 10);\r\n if (isNaN(bookNumber)) {\r\n return null;\r\n }\r\n\r\n return bookNumberIdMap.get(bookNumber) ?? null;\r\n }\r\n\r\n private parseVerseContent(\r\n text: string,\r\n verse: Verse,\r\n chapter: Chapter,\r\n isPoem: boolean\r\n ) {\r\n // Remove line breaks that are just formatting in the source file\r\n // But keep spaces.\r\n // The source has newlines. We should arguably treat them as spaces.\r\n let cleanText = text.replace(/\\s+/g, ' ').trim();\r\n cleanText = cleanText.replace(/[\\+\\-][\u201C\u2018\"]/g, '');\r\n cleanText = cleanText.replace(/\\+\\[/g, '[').replace(/\\+\\]/g, ']');\r\n cleanText = cleanText.replace(/@\\[.*?@\\]/g, '');\r\n\r\n // Regex to separate text from special inline blocks:\r\n // 1. Footnotes: <$F ... $E>\r\n // 2. Cross References: <$R ... $RE> (To be removed)\r\n // 3. Formatting Tags: <RA>, <N1>, etc. (To be removed?)\r\n // 4. Italics in curly braces: {text}\r\n\r\n // Note: Curly braces are nested inside footnotes sometimes, but stripped there.\r\n // At the verse level, they denote italics.\r\n\r\n const segmentRegex =\r\n /(<\\$F.*?\\$E>)|(<\\$R.*?\\$RE>)|(<[^>]*>)|(\\{.*?\\})/g;\r\n\r\n let lastIdx = 0;\r\n let m;\r\n let wordsOfJesus = false;\r\n\r\n while ((m = segmentRegex.exec(cleanText)) !== null) {\r\n const snippet = cleanText.substring(lastIdx, m.index);\r\n if (snippet) {\r\n // Add plain text\r\n this.addText(verse, snippet, isPoem, wordsOfJesus);\r\n }\r\n\r\n if (m[1]) {\r\n // Footnote <$F ... $E>\r\n this.processFootnote(m[1], verse, chapter);\r\n } else if (m[2]) {\r\n // Cross Ref -> Ignore\r\n } else if (m[3]) {\r\n if (m[3] === '<PO>') {\r\n verse.content.push({ lineBreak: true });\r\n lastIdx = segmentRegex.lastIndex;\r\n continue;\r\n }\r\n // Handle words of Jesus markers\r\n if (m[3] === '<RS>') {\r\n wordsOfJesus = true;\r\n } else if (m[3] === '</RS>') {\r\n wordsOfJesus = false;\r\n }\r\n // Other tag -> Ignore (e.g. <RA>, <N1>, <FA>)\r\n // These are often just markers or anchors.\r\n } else if (m[4]) {\r\n // Italics {text}\r\n const content = m[4].substring(1, m[4].length - 1);\r\n // We push a Text object with italics: true\r\n // Check if we need to decode inside? Usually just text.\r\n if (content) {\r\n let text: Text = {\r\n text: content,\r\n italics: true,\r\n };\r\n\r\n if (isPoem) {\r\n text.poem = 1;\r\n }\r\n\r\n if (wordsOfJesus) {\r\n text.wordsOfJesus = true;\r\n }\r\n\r\n verse.content.push(text);\r\n }\r\n }\r\n\r\n lastIdx = segmentRegex.lastIndex;\r\n }\r\n\r\n const remaining = cleanText.substring(lastIdx);\r\n if (remaining) {\r\n this.addText(verse, remaining, isPoem, wordsOfJesus);\r\n }\r\n }\r\n\r\n private addText(\r\n verse: Verse,\r\n text: string,\r\n isPoem: boolean,\r\n wordsOfJesus: boolean\r\n ) {\r\n if (!text) return;\r\n\r\n if (isPoem || wordsOfJesus) {\r\n // When poem=1 or wordsOfJesus is true, use Text objects to carry attributes.\r\n const lastItem = verse.content[verse.content.length - 1];\r\n\r\n if (\r\n lastItem &&\r\n typeof lastItem !== 'string' &&\r\n !('noteId' in lastItem) &&\r\n (lastItem as Text).poem === (isPoem ? 1 : undefined) &&\r\n (lastItem as Text).wordsOfJesus ===\r\n (wordsOfJesus ? true : undefined) &&\r\n !(lastItem as Text).italics\r\n ) {\r\n (lastItem as Text).text += text;\r\n } else {\r\n const formatted: Text = {\r\n text: text,\r\n };\r\n if (isPoem) {\r\n formatted.poem = 1;\r\n }\r\n if (wordsOfJesus) {\r\n formatted.wordsOfJesus = true;\r\n }\r\n verse.content.push(formatted);\r\n }\r\n } else {\r\n // Merge with previous string if possible\r\n const lastItem = verse.content[verse.content.length - 1];\r\n if (typeof lastItem === 'string') {\r\n verse.content[verse.content.length - 1] = lastItem + text;\r\n } else {\r\n verse.content.push(text);\r\n }\r\n }\r\n }\r\n\r\n private parseHebrewSubtitleContent(\r\n text: string,\r\n subtitle: HebrewSubtitle,\r\n chapter: Chapter\r\n ) {\r\n let cleanText = text.replace(/\\s+/g, ' ').trim();\r\n cleanText = cleanText.replace(/[{}]/g, '');\r\n cleanText = cleanText.replace(/@\\[.*?@\\]/g, '');\r\n\r\n const segmentRegex =\r\n /(<\\$F.*?\\$E>)|(<\\$R.*?\\$RE>)|(<[^>]+>)|(\\{.*?\\})/g;\r\n\r\n let lastIdx = 0;\r\n let m;\r\n\r\n while ((m = segmentRegex.exec(cleanText)) !== null) {\r\n const snippet = cleanText.substring(lastIdx, m.index);\r\n if (snippet) {\r\n this.addSubtitleText(subtitle, snippet);\r\n }\r\n\r\n if (m[1]) {\r\n const ref = this.processFootnoteForSubtitle(m[1], chapter);\r\n if (ref) {\r\n subtitle.content.push(ref);\r\n }\r\n } else if (m[2]) {\r\n // Cross Ref -> Ignore\r\n } else if (m[3]) {\r\n // Other tag -> Ignore\r\n } else if (m[4]) {\r\n const content = m[4].substring(1, m[4].length - 1);\r\n if (content) {\r\n this.addSubtitleText(subtitle, content);\r\n }\r\n }\r\n\r\n lastIdx = segmentRegex.lastIndex;\r\n }\r\n\r\n const remaining = cleanText.substring(lastIdx);\r\n if (remaining) {\r\n this.addSubtitleText(subtitle, remaining);\r\n }\r\n }\r\n\r\n private addSubtitleText(subtitle: HebrewSubtitle, text: string) {\r\n if (!text) return;\r\n\r\n const lastItem = subtitle.content[subtitle.content.length - 1];\r\n if (typeof lastItem === 'string') {\r\n subtitle.content[subtitle.content.length - 1] = lastItem + text;\r\n } else {\r\n subtitle.content.push(text);\r\n }\r\n }\r\n\r\n private processFootnote(block: string, verse: Verse, chapter: Chapter) {\r\n // block is <$F...$E>\r\n // Inner content has tags like <FN>, <FNC>, <N1>...\r\n // We want the readable text.\r\n // Remove known technical tags.\r\n\r\n const text = this.extractFootnoteText(block);\r\n\r\n if (!text) return;\r\n\r\n const noteId = chapter.footnotes.length + 1;\r\n\r\n const fn: Footnote = {\r\n noteId: noteId,\r\n text: text,\r\n caller: '+',\r\n reference: {\r\n chapter: chapter.number,\r\n verse: verse.number,\r\n },\r\n };\r\n chapter.footnotes.push(fn);\r\n\r\n verse.content.push({\r\n noteId: noteId,\r\n } as FootnoteReference);\r\n }\r\n\r\n private processFootnoteForSubtitle(\r\n block: string,\r\n chapter: Chapter\r\n ): FootnoteReference | null {\r\n const text = this.extractFootnoteText(block);\r\n\r\n if (!text) return null;\r\n\r\n const noteId = chapter.footnotes.length + 1;\r\n\r\n const fn: Footnote = {\r\n noteId: noteId,\r\n text: text,\r\n caller: '+',\r\n reference: {\r\n chapter: chapter.number,\r\n verse: 0,\r\n },\r\n };\r\n chapter.footnotes.push(fn);\r\n\r\n return {\r\n noteId: noteId,\r\n } as FootnoteReference;\r\n }\r\n\r\n private extractFootnoteText(block: string): string {\r\n // Remove outer $F...$E\r\n let inner = block.replace(/^<\\$F/, '').replace(/\\$E>$/, '');\r\n\r\n // Remove internal technical tags\r\n // Remove <FN>...</FN> completely\r\n inner = inner.replace(/<FN>.*?<\\/FN>/g, '');\r\n\r\n // Remove other tags <N1>, <FA> but keep content\r\n // Also remove italics curly braces (keep content inside)\r\n return inner\r\n .replace(/<[^>]+>/g, '')\r\n .replace(/[\\{\\}]/g, '')\r\n .trim();\r\n }\r\n}\r\n"],
|
|
4
|
+
"sourcesContent": ["import {\r\n ParseTree,\r\n Chapter,\r\n Verse,\r\n Heading,\r\n Footnote,\r\n Text,\r\n FootnoteReference,\r\n HebrewSubtitle,\r\n} from './types.js';\r\nimport { bookOrderMap } from '../generation/book-order.js';\r\n\r\nexport const LOCKMAN_PARSER_VERSION = 3;\r\n\r\nconst bookNumberIdMap = new Map<number, string>();\r\nfor (const [id, order] of bookOrderMap) {\r\n if (!bookNumberIdMap.has(order)) {\r\n bookNumberIdMap.set(order, id);\r\n }\r\n}\r\n\r\nexport class LockmanParser {\r\n parse(text: string): ParseTree[] {\r\n const roots: ParseTree[] = [];\r\n let currentRoot: ParseTree | null = null;\r\n let currentChapter: Chapter | null = null;\r\n let currentVerse: Verse | null = null;\r\n\r\n // Splits text into tokens based on structural tags\r\n // Identify major blocks: BN, CN, SH, and Verse Starters (V, C, PM, A, PO)\r\n // Note: SH and CN content is strictly inside the tag.\r\n // Verse content follows the tag.\r\n // We use a regex that captures the tag AND its \"attributes\" like {{..}}Num<T> for verses.\r\n\r\n // Regex for structural separators\r\n // Captures:\r\n // 1. Title: <BN>...</BN>\r\n // 2. Chapter Heading: <CN>...</CN> or <SN>...</SN>\r\n // 3. Section Heading: <SH>...</SH> or <SS>...</SS>\r\n // 4. Verse Start: (<V>|<C>|<CC>|<CP>|<PM>|<A>|<PO>|<P>|<PN>){{...}}Number<T>\r\n\r\n const structureRegex =\r\n /(<BN>.*?<\\/BN>)|((?:<CN>.*?<\\/CN>)|(?:<SN>.*?<\\/SN>))|((?:<SH>.*?<\\/SH>)|(?:<SS>.*?<\\/SS>))|((?:<V>|<C>|<CC>|<CP>|<PM>|<A>|<PO>|<P>|<PN>)\\{\\{.*?\\}\\}\\d+(?:<T>|\\^)(?:\\{.*?\\})?)/g;\r\n\r\n let lastIndex = 0;\r\n let match;\r\n let isPoem = false;\r\n\r\n while ((match = structureRegex.exec(text)) !== null) {\r\n const fullMatch = match[0];\r\n const startIndex = match.index;\r\n\r\n // Content belonging to the PREVIOUS structural element\r\n if (startIndex > lastIndex) {\r\n const content = text.substring(lastIndex, startIndex);\r\n if (currentVerse && currentChapter) {\r\n this.parseVerseContent(\r\n content,\r\n currentVerse,\r\n currentChapter,\r\n isPoem\r\n );\r\n }\r\n }\r\n\r\n lastIndex = startIndex + fullMatch.length;\r\n\r\n if (match[1]) {\r\n // <BN>Title</BN>\r\n // Start of a NEW Book\r\n const title = match[1].replace(/<\\/?BN>/g, '').trim();\r\n\r\n currentRoot = {\r\n type: 'root',\r\n title: title,\r\n content: [],\r\n };\r\n roots.push(currentRoot);\r\n\r\n // Reset context for new book\r\n currentChapter = null;\r\n currentVerse = null;\r\n } else if (match[2]) {\r\n // <CN>CHAPTER 1</CN> or <SN>PSALM 1</SN>\r\n // Start new Chapter\r\n // Ensure we have a root (handle case where no <BN> provided, implicitly create one? Or just attach to last root)\r\n if (!currentRoot) {\r\n // Fallback if no <BN> was found first\r\n currentRoot = {\r\n type: 'root',\r\n content: [],\r\n };\r\n roots.push(currentRoot);\r\n }\r\n\r\n // Remove tags: <CN>, </CN>, <SN>, </SN>\r\n const inner = match[2].replace(/<\\/?(CN|SN)>/g, '').trim();\r\n const numMatch = inner.match(/\\d+/);\r\n const num = numMatch ? parseInt(numMatch[0], 10) : 0;\r\n\r\n currentChapter = {\r\n type: 'chapter',\r\n number: num,\r\n content: [],\r\n footnotes: [],\r\n };\r\n currentRoot.content.push(currentChapter);\r\n currentVerse = null;\r\n } else if (match[3]) {\r\n // <SH>Heading</SH> or <SS>Subtitle</SS>\r\n if (!currentRoot) {\r\n currentRoot = { type: 'root', content: [] };\r\n roots.push(currentRoot);\r\n }\r\n\r\n const raw = match[3];\r\n if (raw.startsWith('<SS>')) {\r\n // Hebrew subtitle in Psalms\r\n const inner = raw.replace(/<\\/?SS>/g, '').trim();\r\n const subtitle: HebrewSubtitle = {\r\n type: 'hebrew_subtitle',\r\n content: [],\r\n };\r\n\r\n if (currentChapter) {\r\n this.parseHebrewSubtitleContent(\r\n inner,\r\n subtitle,\r\n currentChapter\r\n );\r\n currentChapter.content.push(subtitle);\r\n }\r\n } else {\r\n // Section heading\r\n const inner = raw.replace(/<\\/?SH>/g, '').trim();\r\n const normalized = inner.replace(/<\\\\>|<\\/?>|[{}]/g, '');\r\n const heading: Heading = {\r\n type: 'heading',\r\n content: [normalized],\r\n };\r\n if (currentChapter) {\r\n currentChapter.content.push(heading);\r\n } else {\r\n // Start of book heading? Not typical in this structure but possible\r\n currentRoot.content.push(heading);\r\n }\r\n }\r\n } else if (match[4]) {\r\n // Verse Start: <Tag>{{Ref}}Number<T>\r\n // Extract Verse Number\r\n const tagContent = match[4];\r\n if (currentRoot && !currentRoot.id) {\r\n const bookId = this.getBookIdFromVerseTag(tagContent);\r\n if (bookId) {\r\n currentRoot.id = bookId;\r\n }\r\n }\r\n // Regex to extract digits before <T>\r\n const vNumMatch = tagContent.match(/(\\d+)(?:<T>|\\^)/);\r\n const vNum = vNumMatch ? parseInt(vNumMatch[1], 10) : 0;\r\n\r\n if (currentChapter) {\r\n // Check for Paragraph Marker\r\n if (tagContent.startsWith('<PM>')) {\r\n currentChapter.content.push({ type: 'line_break' });\r\n }\r\n\r\n // Update global isPoem flag\r\n isPoem = /<(?:P|PO|PN|CC|CP)>/.test(tagContent);\r\n\r\n currentVerse = {\r\n type: 'verse',\r\n number: vNum,\r\n content: [],\r\n };\r\n currentChapter.content.push(currentVerse);\r\n }\r\n }\r\n }\r\n\r\n // Process remaining text after the last match\r\n if (lastIndex < text.length) {\r\n const content = text.substring(lastIndex);\r\n if (currentVerse && currentChapter) {\r\n this.parseVerseContent(\r\n content,\r\n currentVerse,\r\n currentChapter,\r\n isPoem\r\n );\r\n }\r\n }\r\n\r\n return roots;\r\n }\r\n\r\n private getBookIdFromVerseTag(tagContent: string): string | null {\r\n const match = tagContent.match(/\\{\\{(\\d+)::/);\r\n if (!match) {\r\n return null;\r\n }\r\n\r\n const bookNumber = parseInt(match[1], 10);\r\n if (isNaN(bookNumber)) {\r\n return null;\r\n }\r\n\r\n return bookNumberIdMap.get(bookNumber) ?? null;\r\n }\r\n\r\n private parseVerseContent(\r\n text: string,\r\n verse: Verse,\r\n chapter: Chapter,\r\n isPoem: boolean\r\n ) {\r\n // Remove line breaks that are just formatting in the source file\r\n // But keep spaces.\r\n // The source has newlines. We should arguably treat them as spaces.\r\n let cleanText = text.replace(/\\s+/g, ' ').trim();\r\n cleanText = cleanText.replace(/[\\+\\-][\u201C\u2018\"]/g, '');\r\n cleanText = cleanText.replace(/\\+\\[/g, '[').replace(/\\+\\]/g, ']');\r\n cleanText = cleanText.replace(/@\\[.*?@\\]/g, '');\r\n\r\n // Regex to separate text from special inline blocks:\r\n // 1. Footnotes: <$F ... $E>\r\n // 2. Cross References: <$R ... $RE> (To be removed)\r\n // 3. Formatting Tags: <RA>, <N1>, etc. (To be removed?)\r\n // 4. Italics in curly braces: {text}\r\n\r\n // Note: Curly braces are nested inside footnotes sometimes, but stripped there.\r\n // At the verse level, they denote italics.\r\n\r\n const segmentRegex =\r\n /(<\\$F.*?\\$E>)|(<\\$R.*?\\$RE>)|(<[^>]*>)|(\\{.*?\\})/g;\r\n\r\n let lastIdx = 0;\r\n let m;\r\n let wordsOfJesus = false;\r\n\r\n while ((m = segmentRegex.exec(cleanText)) !== null) {\r\n const snippet = cleanText.substring(lastIdx, m.index);\r\n if (snippet) {\r\n // Add plain text\r\n this.addText(verse, snippet, isPoem, wordsOfJesus);\r\n }\r\n\r\n if (m[1]) {\r\n // Footnote <$F ... $E>\r\n this.processFootnote(m[1], verse, chapter);\r\n } else if (m[2]) {\r\n // Cross Ref -> Ignore\r\n } else if (m[3]) {\r\n if (m[3] === '<PO>') {\r\n verse.content.push({ lineBreak: true });\r\n lastIdx = segmentRegex.lastIndex;\r\n continue;\r\n }\r\n // Handle words of Jesus markers\r\n if (m[3] === '<RS>') {\r\n wordsOfJesus = true;\r\n } else if (m[3] === '</RS>') {\r\n wordsOfJesus = false;\r\n }\r\n // Other tag -> Ignore (e.g. <RA>, <N1>, <FA>)\r\n // These are often just markers or anchors.\r\n } else if (m[4]) {\r\n // Italics {text}\r\n const content = m[4].substring(1, m[4].length - 1);\r\n // We push a Text object with italics: true\r\n // Check if we need to decode inside? Usually just text.\r\n if (content) {\r\n let text: Text = {\r\n text: content,\r\n italics: true,\r\n };\r\n\r\n if (isPoem) {\r\n text.poem = 1;\r\n }\r\n\r\n if (wordsOfJesus) {\r\n text.wordsOfJesus = true;\r\n }\r\n\r\n verse.content.push(text);\r\n }\r\n }\r\n\r\n lastIdx = segmentRegex.lastIndex;\r\n }\r\n\r\n const remaining = cleanText.substring(lastIdx);\r\n if (remaining) {\r\n this.addText(verse, remaining, isPoem, wordsOfJesus);\r\n }\r\n }\r\n\r\n private addText(\r\n verse: Verse,\r\n text: string,\r\n isPoem: boolean,\r\n wordsOfJesus: boolean\r\n ) {\r\n if (!text) return;\r\n\r\n if (isPoem || wordsOfJesus) {\r\n // When poem=1 or wordsOfJesus is true, use Text objects to carry attributes.\r\n const lastItem = verse.content[verse.content.length - 1];\r\n\r\n if (\r\n lastItem &&\r\n typeof lastItem !== 'string' &&\r\n !('noteId' in lastItem) &&\r\n (lastItem as Text).poem === (isPoem ? 1 : undefined) &&\r\n (lastItem as Text).wordsOfJesus ===\r\n (wordsOfJesus ? true : undefined) &&\r\n !(lastItem as Text).italics\r\n ) {\r\n (lastItem as Text).text += text;\r\n } else {\r\n const formatted: Text = {\r\n text: text,\r\n };\r\n if (isPoem) {\r\n formatted.poem = 1;\r\n }\r\n if (wordsOfJesus) {\r\n formatted.wordsOfJesus = true;\r\n }\r\n verse.content.push(formatted);\r\n }\r\n } else {\r\n // Merge with previous string if possible\r\n const lastItem = verse.content[verse.content.length - 1];\r\n if (typeof lastItem === 'string') {\r\n verse.content[verse.content.length - 1] = lastItem + text;\r\n } else {\r\n verse.content.push(text);\r\n }\r\n }\r\n }\r\n\r\n private parseHebrewSubtitleContent(\r\n text: string,\r\n subtitle: HebrewSubtitle,\r\n chapter: Chapter\r\n ) {\r\n let cleanText = text.replace(/\\s+/g, ' ').trim();\r\n cleanText = cleanText.replace(/[{}]/g, '');\r\n cleanText = cleanText.replace(/@\\[.*?@\\]/g, '');\r\n\r\n const segmentRegex =\r\n /(<\\$F.*?\\$E>)|(<\\$R.*?\\$RE>)|(<[^>]+>)|(\\{.*?\\})/g;\r\n\r\n let lastIdx = 0;\r\n let m;\r\n\r\n while ((m = segmentRegex.exec(cleanText)) !== null) {\r\n const snippet = cleanText.substring(lastIdx, m.index);\r\n if (snippet) {\r\n this.addSubtitleText(subtitle, snippet);\r\n }\r\n\r\n if (m[1]) {\r\n const ref = this.processFootnoteForSubtitle(m[1], chapter);\r\n if (ref) {\r\n subtitle.content.push(ref);\r\n }\r\n } else if (m[2]) {\r\n // Cross Ref -> Ignore\r\n } else if (m[3]) {\r\n // Other tag -> Ignore\r\n } else if (m[4]) {\r\n const content = m[4].substring(1, m[4].length - 1);\r\n if (content) {\r\n this.addSubtitleText(subtitle, content);\r\n }\r\n }\r\n\r\n lastIdx = segmentRegex.lastIndex;\r\n }\r\n\r\n const remaining = cleanText.substring(lastIdx);\r\n if (remaining) {\r\n this.addSubtitleText(subtitle, remaining);\r\n }\r\n }\r\n\r\n private addSubtitleText(subtitle: HebrewSubtitle, text: string) {\r\n if (!text) return;\r\n\r\n const lastItem = subtitle.content[subtitle.content.length - 1];\r\n if (typeof lastItem === 'string') {\r\n subtitle.content[subtitle.content.length - 1] = lastItem + text;\r\n } else {\r\n subtitle.content.push(text);\r\n }\r\n }\r\n\r\n private processFootnote(block: string, verse: Verse, chapter: Chapter) {\r\n // block is <$F...$E>\r\n // Inner content has tags like <FN>, <FNC>, <N1>...\r\n // We want the readable text.\r\n // Remove known technical tags.\r\n\r\n const text = this.extractFootnoteText(block);\r\n\r\n if (!text) return;\r\n\r\n const noteId = chapter.footnotes.length + 1;\r\n\r\n const fn: Footnote = {\r\n noteId: noteId,\r\n text: text,\r\n caller: '+',\r\n reference: {\r\n chapter: chapter.number,\r\n verse: verse.number,\r\n },\r\n };\r\n chapter.footnotes.push(fn);\r\n\r\n verse.content.push({\r\n noteId: noteId,\r\n } as FootnoteReference);\r\n }\r\n\r\n private processFootnoteForSubtitle(\r\n block: string,\r\n chapter: Chapter\r\n ): FootnoteReference | null {\r\n const text = this.extractFootnoteText(block);\r\n\r\n if (!text) return null;\r\n\r\n const noteId = chapter.footnotes.length + 1;\r\n\r\n const fn: Footnote = {\r\n noteId: noteId,\r\n text: text,\r\n caller: '+',\r\n reference: {\r\n chapter: chapter.number,\r\n verse: 0,\r\n },\r\n };\r\n chapter.footnotes.push(fn);\r\n\r\n return {\r\n noteId: noteId,\r\n } as FootnoteReference;\r\n }\r\n\r\n private extractFootnoteText(block: string): string {\r\n // Remove outer $F...$E\r\n let inner = block.replace(/^<\\$F/, '').replace(/\\$E>$/, '');\r\n\r\n // Remove internal technical tags\r\n // Remove <FN>...</FN> completely\r\n inner = inner.replace(/<FN>.*?<\\/FN>/g, '');\r\n\r\n // Remove other tags <N1>, <FA> but keep content\r\n // Also remove italics curly braces (keep content inside)\r\n return inner\r\n .replace(/<[^>]+>/g, '')\r\n .replace(/[\\{\\}]/g,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,MACR,WAAW;AAAA,QACP,SAAS,QAAQ;AAAA,QACjB,OAAO;AAAA,MACX;AAAA,IACJ;AACA,YAAQ,UAAU,KAAK,EAAE;AAEzB,WAAO;AAAA,MACH;AAAA,IACJ;AAAA,EACJ;AAAA,EAEQ,oBAAoB,OAAuB;AAE/C,QAAI,QAAQ,MAAM,QAAQ,SAAS,EAAE,EAAE,QAAQ,SAAS,EAAE;AAI1D,YAAQ,MAAM,QAAQ,kBAAkB,EAAE;AAI1C,WAAO,MACF,QAAQ,YAAY,EAAE,EACtB,QAAQ,WAAW,EAAE,EACrB,KAAK;AAAA,EACd;AACJ;",
|
|
6
6
|
"names": ["text"]
|
|
7
7
|
}
|
|
@@ -23,7 +23,7 @@ __export(tyndale_xml_parser_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(tyndale_xml_parser_exports);
|
|
25
25
|
var import_log = require("../log.js");
|
|
26
|
-
var import_utils = require("../utils");
|
|
26
|
+
var import_utils = require("../utils.js");
|
|
27
27
|
var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
28
28
|
NodeType2[NodeType2["Element"] = 1] = "Element";
|
|
29
29
|
NodeType2[NodeType2["Attribute"] = 2] = "Attribute";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/tyndale-xml-parser.ts"],
|
|
4
|
-
"sourcesContent": ["import { getLogger } from '../log.js';\r\nimport { parseVerseReference } from '../utils';\r\nimport {\r\n CommentaryBookNode,\r\n CommentaryChapterNode,\r\n CommentaryParseTree,\r\n CommentaryVerseNode,\r\n} from './types';\r\n\r\nenum NodeType {\r\n Element = 1,\r\n Attribute = 2,\r\n Text = 3,\r\n}\r\n\r\nexport class TyndaleXmlParser {\r\n private _domParser: DOMParser;\r\n\r\n constructor(domParser: DOMParser) {\r\n this._domParser = domParser;\r\n }\r\n\r\n parse(xml: string): CommentaryParseTree {\r\n const logger = getLogger();\r\n const parser = this._domParser;\r\n const doc = parser.parseFromString(xml, 'application/xml');\r\n const rootElement = doc.documentElement;\r\n\r\n let tree: CommentaryParseTree = {\r\n type: 'commentary/root',\r\n books: [],\r\n };\r\n\r\n let books: Map<string, CommentaryBookNode> = new Map();\r\n\r\n function getBook(id: string): CommentaryBookNode {\r\n let bookNode = books.get(id);\r\n\r\n if (!bookNode) {\r\n bookNode = {\r\n type: 'book',\r\n book: id,\r\n introduction: null,\r\n chapters: [],\r\n };\r\n\r\n books.set(id, bookNode);\r\n tree.books.push(bookNode);\r\n }\r\n return bookNode;\r\n }\r\n\r\n function getChapter(\r\n book: CommentaryBookNode,\r\n number: number\r\n ): CommentaryChapterNode {\r\n let chapterNode = book.chapters.find(\r\n (chapter) => chapter.number === number\r\n );\r\n\r\n if (!chapterNode) {\r\n chapterNode = {\r\n type: 'chapter',\r\n number: number,\r\n introduction: null,\r\n verses: [],\r\n };\r\n\r\n book.chapters.push(chapterNode);\r\n }\r\n\r\n return chapterNode;\r\n }\r\n\r\n function getVerse(\r\n chapter: CommentaryChapterNode,\r\n number: number\r\n ): CommentaryVerseNode {\r\n let verseNode = chapter.verses.find(\r\n (verse) => verse.number === number\r\n );\r\n\r\n if (!verseNode) {\r\n verseNode = {\r\n type: 'verse',\r\n number: number,\r\n content: [],\r\n };\r\n\r\n chapter.verses.push(verseNode);\r\n }\r\n\r\n return verseNode;\r\n }\r\n\r\n function formatContent(node: Node, trim: boolean = true): string {\r\n let text: string;\r\n if (node.nodeName === 'p') {\r\n text = (node.textContent || '') + '\\n';\r\n } else if (node.nodeName === '#text') {\r\n text = node.textContent || '';\r\n } else if (node.nodeName === 'br') {\r\n text = '\\n';\r\n } else if (node.nodeType === NodeType.Element) {\r\n text = '';\r\n for (let child of node.childNodes) {\r\n text += formatContent(child, false);\r\n }\r\n } else {\r\n text = node.textContent || '';\r\n }\r\n\r\n if (trim) {\r\n const lines = text.split('\\n');\r\n for (let i = 0; i < lines.length; i++) {\r\n // Trim extra whitespace and replace multiple spaces with a single space\r\n lines[i] = lines[i].replace(/\\s+/g, ' ').trim();\r\n }\r\n text = lines.join('\\n').trim();\r\n }\r\n\r\n return text;\r\n }\r\n\r\n const items = rootElement.querySelectorAll('item');\r\n\r\n for (let item of items) {\r\n const typename = item.getAttribute('typename');\r\n\r\n if (typename === 'StudyNote') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping study note item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n const chapterNode = getChapter(bookNode, ref.chapter);\r\n const verseNode = getVerse(chapterNode, ref.verse);\r\n verseNode.content.push(formatContent(body));\r\n } else if (typename === 'BookIntro') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping book item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n\r\n bookNode.introduction = formatContent(body);\r\n } else if (typename === 'BookIntroSummary') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping book item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n\r\n bookNode.introductionSummary = formatContent(body);\r\n } else if (typename === 'Profile') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n const title = item.querySelector('title')?.textContent;\r\n const name = item.getAttribute('name');\r\n\r\n if (!refs || !body || !title || !name) {\r\n logger.warn(\r\n 'Skipping profile item without refs, body, or title:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n if (!tree.profiles) {\r\n tree.profiles = [];\r\n }\r\n\r\n // convert camelCase to kebab-case\r\n const id = toKebabCase(name);\r\n tree.profiles.push({\r\n id,\r\n subject: title,\r\n content: [formatContent(body)],\r\n reference: ref,\r\n });\r\n }\r\n }\r\n\r\n return tree;\r\n }\r\n}\r\n\r\nexport function toKebabCase(camelCase: string): string {\r\n return camelCase.replace(/([a-z])\\s*([A-Z])/g, '$1-$2').toLowerCase();\r\n}\r\n"],
|
|
4
|
+
"sourcesContent": ["import { getLogger } from '../log.js';\r\nimport { parseVerseReference } from '../utils.js';\r\nimport {\r\n CommentaryBookNode,\r\n CommentaryChapterNode,\r\n CommentaryParseTree,\r\n CommentaryVerseNode,\r\n} from './types.js';\r\n\r\nenum NodeType {\r\n Element = 1,\r\n Attribute = 2,\r\n Text = 3,\r\n}\r\n\r\nexport class TyndaleXmlParser {\r\n private _domParser: DOMParser;\r\n\r\n constructor(domParser: DOMParser) {\r\n this._domParser = domParser;\r\n }\r\n\r\n parse(xml: string): CommentaryParseTree {\r\n const logger = getLogger();\r\n const parser = this._domParser;\r\n const doc = parser.parseFromString(xml, 'application/xml');\r\n const rootElement = doc.documentElement;\r\n\r\n let tree: CommentaryParseTree = {\r\n type: 'commentary/root',\r\n books: [],\r\n };\r\n\r\n let books: Map<string, CommentaryBookNode> = new Map();\r\n\r\n function getBook(id: string): CommentaryBookNode {\r\n let bookNode = books.get(id);\r\n\r\n if (!bookNode) {\r\n bookNode = {\r\n type: 'book',\r\n book: id,\r\n introduction: null,\r\n chapters: [],\r\n };\r\n\r\n books.set(id, bookNode);\r\n tree.books.push(bookNode);\r\n }\r\n return bookNode;\r\n }\r\n\r\n function getChapter(\r\n book: CommentaryBookNode,\r\n number: number\r\n ): CommentaryChapterNode {\r\n let chapterNode = book.chapters.find(\r\n (chapter) => chapter.number === number\r\n );\r\n\r\n if (!chapterNode) {\r\n chapterNode = {\r\n type: 'chapter',\r\n number: number,\r\n introduction: null,\r\n verses: [],\r\n };\r\n\r\n book.chapters.push(chapterNode);\r\n }\r\n\r\n return chapterNode;\r\n }\r\n\r\n function getVerse(\r\n chapter: CommentaryChapterNode,\r\n number: number\r\n ): CommentaryVerseNode {\r\n let verseNode = chapter.verses.find(\r\n (verse) => verse.number === number\r\n );\r\n\r\n if (!verseNode) {\r\n verseNode = {\r\n type: 'verse',\r\n number: number,\r\n content: [],\r\n };\r\n\r\n chapter.verses.push(verseNode);\r\n }\r\n\r\n return verseNode;\r\n }\r\n\r\n function formatContent(node: Node, trim: boolean = true): string {\r\n let text: string;\r\n if (node.nodeName === 'p') {\r\n text = (node.textContent || '') + '\\n';\r\n } else if (node.nodeName === '#text') {\r\n text = node.textContent || '';\r\n } else if (node.nodeName === 'br') {\r\n text = '\\n';\r\n } else if (node.nodeType === NodeType.Element) {\r\n text = '';\r\n for (let child of node.childNodes) {\r\n text += formatContent(child, false);\r\n }\r\n } else {\r\n text = node.textContent || '';\r\n }\r\n\r\n if (trim) {\r\n const lines = text.split('\\n');\r\n for (let i = 0; i < lines.length; i++) {\r\n // Trim extra whitespace and replace multiple spaces with a single space\r\n lines[i] = lines[i].replace(/\\s+/g, ' ').trim();\r\n }\r\n text = lines.join('\\n').trim();\r\n }\r\n\r\n return text;\r\n }\r\n\r\n const items = rootElement.querySelectorAll('item');\r\n\r\n for (let item of items) {\r\n const typename = item.getAttribute('typename');\r\n\r\n if (typename === 'StudyNote') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping study note item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n const chapterNode = getChapter(bookNode, ref.chapter);\r\n const verseNode = getVerse(chapterNode, ref.verse);\r\n verseNode.content.push(formatContent(body));\r\n } else if (typename === 'BookIntro') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping book item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n\r\n bookNode.introduction = formatContent(body);\r\n } else if (typename === 'BookIntroSummary') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n\r\n if (!refs || !body) {\r\n logger.warn(\r\n 'Skipping book item without refs or body:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n const bookNode = getBook(ref.book);\r\n\r\n bookNode.introductionSummary = formatContent(body);\r\n } else if (typename === 'Profile') {\r\n const refs = item.querySelector('refs')?.textContent;\r\n const body = item.querySelector('body');\r\n const title = item.querySelector('title')?.textContent;\r\n const name = item.getAttribute('name');\r\n\r\n if (!refs || !body || !title || !name) {\r\n logger.warn(\r\n 'Skipping profile item without refs, body, or title:',\r\n item\r\n );\r\n continue;\r\n }\r\n\r\n const ref = parseVerseReference(refs);\r\n\r\n if (!ref) {\r\n logger.warn('Failed to parse verse reference:', refs);\r\n continue;\r\n }\r\n\r\n if (!tree.profiles) {\r\n tree.profiles = [];\r\n }\r\n\r\n // convert camelCase to kebab-case\r\n const id = toKebabCase(name);\r\n tree.profiles.push({\r\n id,\r\n subject: title,\r\n content: [formatContent(body)],\r\n reference: ref,\r\n });\r\n }\r\n }\r\n\r\n return tree;\r\n }\r\n}\r\n\r\nexport function toKebabCase(camelCase: string): string {\r\n return camelCase.replace(/([a-z])\\s*([A-Z])/g, '$1-$2').toLowerCase();\r\n}\r\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA0B;AAC1B,mBAAoC;AAQpC,IAAK,WAAL,kBAAKA,cAAL;AACI,EAAAA,oBAAA,aAAU,KAAV;AACA,EAAAA,oBAAA,eAAY,KAAZ;AACA,EAAAA,oBAAA,UAAO,KAAP;AAHC,SAAAA;AAAA,GAAA;AAME,MAAM,iBAAiB;AAAA,EAClB;AAAA,EAER,YAAY,WAAsB;AAC9B,SAAK,aAAa;AAAA,EACtB;AAAA,EAEA,MAAM,KAAkC;AACpC,UAAM,aAAS,sBAAU;AACzB,UAAM,SAAS,KAAK;AACpB,UAAM,MAAM,OAAO,gBAAgB,KAAK,iBAAiB;AACzD,UAAM,cAAc,IAAI;AAExB,QAAI,OAA4B;AAAA,MAC5B,MAAM;AAAA,MACN,OAAO,CAAC;AAAA,IACZ;AAEA,QAAI,QAAyC,oBAAI,IAAI;AAErD,aAAS,QAAQ,IAAgC;AAC7C,UAAI,WAAW,MAAM,IAAI,EAAE;AAE3B,UAAI,CAAC,UAAU;AACX,mBAAW;AAAA,UACP,MAAM;AAAA,UACN,MAAM;AAAA,UACN,cAAc;AAAA,UACd,UAAU,CAAC;AAAA,QACf;AAEA,cAAM,IAAI,IAAI,QAAQ;AACtB,aAAK,MAAM,KAAK,QAAQ;AAAA,MAC5B;AACA,aAAO;AAAA,IACX;AAEA,aAAS,WACL,MACA,QACqB;AACrB,UAAI,cAAc,KAAK,SAAS;AAAA,QAC5B,CAAC,YAAY,QAAQ,WAAW;AAAA,MACpC;AAEA,UAAI,CAAC,aAAa;AACd,sBAAc;AAAA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ACrD,WAAW,aAAa,WAAW;AAC/B,cAAM,OAAO,KAAK,cAAc,MAAM,GAAG;AACzC,cAAM,OAAO,KAAK,cAAc,MAAM;AACtC,cAAM,QAAQ,KAAK,cAAc,OAAO,GAAG;AAC3C,cAAM,OAAO,KAAK,aAAa,MAAM;AAErC,YAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM;AACnC,iBAAO;AAAA,YACH;AAAA,YACA;AAAA,UACJ;AACA;AAAA,QACJ;AAEA,cAAM,UAAM,kCAAoB,IAAI;AAEpC,YAAI,CAAC,KAAK;AACN,iBAAO,KAAK,oCAAoC,IAAI;AACpD;AAAA,QACJ;AAEA,YAAI,CAAC,KAAK,UAAU;AAChB,eAAK,WAAW,CAAC;AAAA,QACrB;AAGA,cAAM,KAAK,YAAY,IAAI;AAC3B,aAAK,SAAS,KAAK;AAAA,UACf;AAAA,UACA,SAAS;AAAA,UACT,SAAS,CAAC,cAAc,IAAI,CAAC;AAAA,UAC7B,WAAW;AAAA,QACf,CAAC;AAAA,MACL;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,YAAY,WAA2B;AACnD,SAAO,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACxE;",
|
|
6
6
|
"names": ["NodeType"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { VerseRef } from '../utils.js';\r\n\r\n/**\r\n * The parse tree that is gathered.\r\n */\r\nexport interface ParseTree {\r\n type: 'root';\r\n\r\n /**\r\n * The ID of the parse tree.\r\n */\r\n id?: string;\r\n\r\n /**\r\n * The header that was associated with the tree.\r\n */\r\n header?: string;\r\n\r\n /**\r\n * The major title that was associated with the tree.\r\n */\r\n title?: string;\r\n\r\n /**\r\n * The list of chapters for the tree.\r\n */\r\n content: (Heading | Chapter)[];\r\n\r\n /**\r\n * The list of messages that were generated during parsing.\r\n */\r\n parseMessages?: ParseMessage[];\r\n}\r\n\r\nexport interface ParseMessage {\r\n type: 'warning' | 'error';\r\n message: string;\r\n}\r\n\r\nexport interface Heading {\r\n type: 'heading';\r\n content: string[];\r\n}\r\n\r\nexport type ChapterContent = Heading | Verse | HebrewSubtitle | LineBreak;\r\n\r\nexport type VerseContent = string | FootnoteReference | Text;\r\n\r\n/**\r\n * Defines an interface that represents a chapter.\r\n */\r\nexport interface Chapter {\r\n type: 'chapter';\r\n number: number;\r\n\r\n /**\r\n * The contents of the chapter.\r\n */\r\n content: ChapterContent[];\r\n\r\n /**\r\n * The list of footnotes for the chapter.\r\n */\r\n footnotes: Footnote[];\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a hebrew subtitle.\r\n */\r\nexport interface HebrewSubtitle {\r\n type: 'hebrew_subtitle';\r\n\r\n /**\r\n * The contents of the subtitle.\r\n */\r\n content: (string | Text | FootnoteReference)[];\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a verse.\r\n */\r\nexport interface Verse {\r\n type: 'verse';\r\n\r\n number: number;\r\n\r\n /**\r\n * The contents of the verse.\r\n */\r\n content: (\r\n | string\r\n | Text\r\n | InlineHeading\r\n | InlineLineBreak\r\n | FootnoteReference\r\n )[];\r\n}\r\n\r\n/**\r\n * Defines an interface that represents text that has some markup attributes applied to it.\r\n */\r\nexport interface Text {\r\n /**\r\n * The text that is contained.\r\n */\r\n text: string;\r\n\r\n /**\r\n * Whether the text represents a poem.\r\n * The number indicates the level of indent.\r\n */\r\n poem?: number;\r\n\r\n /**\r\n * Whether the text contains the words of Jesus.\r\n */\r\n wordsOfJesus?: boolean;\r\n\r\n /**\r\n * Whether the text is descriptive.\r\n *\r\n * This is only used for \"hebrew subtitles\" that are included inside the verse markers.\r\n */\r\n descriptive?: boolean;\r\n\r\n /**\r\n * Whether the text should be displayed in italics.\r\n */\r\n italics?: boolean;\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a heading that is embedded in a verse.\r\n */\r\nexport interface InlineHeading {\r\n /**\r\n * The text of the heading.\r\n */\r\n heading: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a line break that is embedded in a verse.\r\n */\r\nexport interface InlineLineBreak {\r\n lineBreak: true;\r\n}\r\n\r\nexport interface FootnoteReference {\r\n /**\r\n * The ID of the note that is referenced.\r\n */\r\n noteId: number;\r\n}\r\n\r\nexport interface Footnote {\r\n noteId: number;\r\n\r\n /**\r\n * The text of the footnote.\r\n */\r\n text: string;\r\n\r\n /**\r\n * The caller that should be used for the footnote.\r\n * For footnotes, a \"caller\" is the character that is used in the text to reference to footnote.\r\n *\r\n * For example, in the text:\r\n * Hello (a) World\r\n *\r\n * ----\r\n * (a) This is a footnote.\r\n *\r\n * The \"(a)\" is the caller.\r\n *\r\n * If \"+\", then the caller should be autogenerated.\r\n * If null, then the caller should be empty.\r\n * If a string, then the caller should be that string.\r\n */\r\n caller: '+' | string | null;\r\n\r\n /**\r\n * The verse reference for the footnote.\r\n */\r\n reference?: {\r\n chapter: number;\r\n verse: number;\r\n };\r\n}\r\n\r\nexport interface LineBreak {\r\n type: 'line_break';\r\n}\r\n\r\n/**\r\n * The parse tree that is gathered.\r\n */\r\nexport interface CommentaryParseTree {\r\n type: 'commentary/root';\r\n\r\n /**\r\n * The books that are contained in the commentary.\r\n */\r\n books: CommentaryBookNode[];\r\n\r\n /**\r\n * The profiles that are contained in the commentary.\r\n */\r\n profiles?: CommentaryProfileNode[];\r\n}\r\n\r\nexport interface CommentaryBookNode {\r\n type: 'book';\r\n book: string;\r\n introduction: string | null;\r\n introductionSummary?: string | null;\r\n chapters: CommentaryChapterNode[];\r\n}\r\n\r\nexport interface CommentaryProfileNode {\r\n /**\r\n * The ID of the profile.\r\n * Used to identify the profile within a commentary.\r\n */\r\n id: string;\r\n\r\n /**\r\n * The subject(s) of the profile.\r\n */\r\n subject: string;\r\n\r\n /**\r\n * The Bible reference that the profile is associated with.\r\n */\r\n reference: VerseRef | null;\r\n\r\n /**\r\n * The content of the profile.\r\n */\r\n content: string[];\r\n}\r\n\r\nexport interface CommentaryChapterNode {\r\n type: 'chapter';\r\n number: number;\r\n introduction: string | null;\r\n verses: CommentaryVerseNode[];\r\n}\r\n\r\nexport interface CommentaryVerseNode {\r\n type: 'verse';\r\n number: number;\r\n content: string[];\r\n}\r\n"],
|
|
4
|
+
"sourcesContent": ["import { VerseRef } from '../utils.js';\r\n\r\n/**\r\n * The parse tree that is gathered.\r\n */\r\nexport interface ParseTree {\r\n type: 'root';\r\n\r\n /**\r\n * The ID of the parse tree.\r\n */\r\n id?: string;\r\n\r\n /**\r\n * The header that was associated with the tree.\r\n */\r\n header?: string;\r\n\r\n /**\r\n * The major title that was associated with the tree.\r\n */\r\n title?: string;\r\n\r\n /**\r\n * The list of chapters for the tree.\r\n */\r\n content: (Heading | Chapter)[];\r\n\r\n /**\r\n * The list of messages that were generated during parsing.\r\n */\r\n parseMessages?: ParseMessage[];\r\n}\r\n\r\nexport interface ParseMessage {\r\n type: 'warning' | 'error';\r\n message: string;\r\n}\r\n\r\nexport interface Heading {\r\n type: 'heading';\r\n content: string[];\r\n}\r\n\r\nexport type ChapterContent = Heading | Verse | HebrewSubtitle | LineBreak;\r\n\r\nexport type VerseContent = string | FootnoteReference | Text;\r\n\r\n/**\r\n * Defines an interface that represents a chapter.\r\n */\r\nexport interface Chapter {\r\n type: 'chapter';\r\n number: number;\r\n\r\n /**\r\n * The contents of the chapter.\r\n */\r\n content: ChapterContent[];\r\n\r\n /**\r\n * The list of footnotes for the chapter.\r\n */\r\n footnotes: Footnote[];\r\n\r\n /**\r\n * The word-level annotations for the chapter's verses.\r\n * Undefined if the source didn't contain any word-level annotations.\r\n */\r\n words?: ChapterWords;\r\n}\r\n\r\n/**\r\n * Defines the word-level annotations for a chapter, keyed by verse number.\r\n */\r\nexport type ChapterWords = {\r\n [verseNumber: string]: ChapterWord[];\r\n};\r\n\r\n/**\r\n * Defines an interface that represents the annotations that a source associated\r\n * with a specific range of characters in a verse.\r\n *\r\n * The range is anchored to a single item of the verse's content array, so that\r\n * consumers can highlight the exact characters that an annotation applies to.\r\n */\r\nexport interface ChapterWord {\r\n /**\r\n * The index of the item in the verse's content array that the annotation applies to.\r\n */\r\n contentIndex: number;\r\n\r\n /**\r\n * The index of the first character of the annotated word in the content item's text.\r\n */\r\n start: number;\r\n\r\n /**\r\n * The index after the last character of the annotated word in the content item's text.\r\n * That is, `text.slice(start, end)` is the annotated word.\r\n */\r\n end: number;\r\n\r\n /**\r\n * The Strong's number(s) for the word.\r\n * Undefined if the source only provided other annotations for the word.\r\n */\r\n strongs?: string[];\r\n\r\n /**\r\n * The dictionary (citation) form of the word.\r\n * Taken from the `lemma` attribute.\r\n */\r\n lemma?: string;\r\n\r\n /**\r\n * The morphology parse code for the word.\r\n * Taken from the `x-morph` attribute.\r\n */\r\n morph?: string;\r\n\r\n /**\r\n * The pointer to the word in the source text, in the `<sourceName>:<location>` format.\r\n * Taken from the `srcloc` attribute.\r\n */\r\n srcloc?: string;\r\n\r\n /**\r\n * Which occurrence of the source word this word is. 1-based.\r\n * Taken from the `x-occurrence` attribute.\r\n */\r\n occurrence?: number;\r\n\r\n /**\r\n * The total number of times that the source word occurs.\r\n * Taken from the `x-occurrences` attribute.\r\n */\r\n occurrences?: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a hebrew subtitle.\r\n */\r\nexport interface HebrewSubtitle {\r\n type: 'hebrew_subtitle';\r\n\r\n /**\r\n * The contents of the subtitle.\r\n */\r\n content: (string | Text | FootnoteReference)[];\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a verse.\r\n */\r\nexport interface Verse {\r\n type: 'verse';\r\n\r\n number: number;\r\n\r\n /**\r\n * The contents of the verse.\r\n */\r\n content: (\r\n | string\r\n | Text\r\n | InlineHeading\r\n | InlineLineBreak\r\n | FootnoteReference\r\n )[];\r\n}\r\n\r\n/**\r\n * Defines an interface that represents text that has some markup attributes applied to it.\r\n */\r\nexport interface Text {\r\n /**\r\n * The text that is contained.\r\n */\r\n text: string;\r\n\r\n /**\r\n * Whether the text represents a poem.\r\n * The number indicates the level of indent.\r\n */\r\n poem?: number;\r\n\r\n /**\r\n * Whether the text contains the words of Jesus.\r\n */\r\n wordsOfJesus?: boolean;\r\n\r\n /**\r\n * Whether the text is descriptive.\r\n *\r\n * This is only used for \"hebrew subtitles\" that are included inside the verse markers.\r\n */\r\n descriptive?: boolean;\r\n\r\n /**\r\n * Whether the text should be displayed in italics.\r\n */\r\n italics?: boolean;\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a heading that is embedded in a verse.\r\n */\r\nexport interface InlineHeading {\r\n /**\r\n * The text of the heading.\r\n */\r\n heading: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that represents a line break that is embedded in a verse.\r\n */\r\nexport interface InlineLineBreak {\r\n lineBreak: true;\r\n}\r\n\r\nexport interface FootnoteReference {\r\n /**\r\n * The ID of the note that is referenced.\r\n */\r\n noteId: number;\r\n}\r\n\r\nexport interface Footnote {\r\n noteId: number;\r\n\r\n /**\r\n * The text of the footnote.\r\n */\r\n text: string;\r\n\r\n /**\r\n * The caller that should be used for the footnote.\r\n * For footnotes, a \"caller\" is the character that is used in the text to reference to footnote.\r\n *\r\n * For example, in the text:\r\n * Hello (a) World\r\n *\r\n * ----\r\n * (a) This is a footnote.\r\n *\r\n * The \"(a)\" is the caller.\r\n *\r\n * If \"+\", then the caller should be autogenerated.\r\n * If null, then the caller should be empty.\r\n * If a string, then the caller should be that string.\r\n */\r\n caller: '+' | string | null;\r\n\r\n /**\r\n * The verse reference for the footnote.\r\n */\r\n reference?: {\r\n chapter: number;\r\n verse: number;\r\n };\r\n}\r\n\r\nexport interface LineBreak {\r\n type: 'line_break';\r\n}\r\n\r\n/**\r\n * The parse tree that is gathered.\r\n */\r\nexport interface CommentaryParseTree {\r\n type: 'commentary/root';\r\n\r\n /**\r\n * The books that are contained in the commentary.\r\n */\r\n books: CommentaryBookNode[];\r\n\r\n /**\r\n * The profiles that are contained in the commentary.\r\n */\r\n profiles?: CommentaryProfileNode[];\r\n}\r\n\r\nexport interface CommentaryBookNode {\r\n type: 'book';\r\n book: string;\r\n introduction: string | null;\r\n introductionSummary?: string | null;\r\n chapters: CommentaryChapterNode[];\r\n}\r\n\r\nexport interface CommentaryProfileNode {\r\n /**\r\n * The ID of the profile.\r\n * Used to identify the profile within a commentary.\r\n */\r\n id: string;\r\n\r\n /**\r\n * The subject(s) of the profile.\r\n */\r\n subject: string;\r\n\r\n /**\r\n * The Bible reference that the profile is associated with.\r\n */\r\n reference: VerseRef | null;\r\n\r\n /**\r\n * The content of the profile.\r\n */\r\n content: string[];\r\n}\r\n\r\nexport interface CommentaryChapterNode {\r\n type: 'chapter';\r\n number: number;\r\n introduction: string | null;\r\n verses: CommentaryVerseNode[];\r\n}\r\n\r\nexport interface CommentaryVerseNode {\r\n type: 'verse';\r\n number: number;\r\n content: string[];\r\n}\r\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ __export(usfm_parser_exports, {
|
|
|
29
29
|
word: () => word
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(usfm_parser_exports);
|
|
32
|
-
var
|
|
32
|
+
var import_compat = require("es-toolkit/compat");
|
|
33
33
|
var import_log = require("../log.js");
|
|
34
34
|
class UsfmTokenizer {
|
|
35
35
|
_input = "";
|
|
@@ -161,7 +161,7 @@ class UsfmParser {
|
|
|
161
161
|
}
|
|
162
162
|
if (source.length === 1) {
|
|
163
163
|
if (isEnd) {
|
|
164
|
-
const startMarker = (0,
|
|
164
|
+
const startMarker = (0, import_compat.findLast)(
|
|
165
165
|
tokens,
|
|
166
166
|
(t3) => t3.kind === "marker" && t3.type === "start"
|
|
167
167
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/usfm-parser.ts"],
|
|
4
|
-
"sourcesContent": ["import { findLast } from 'lodash';\r\nimport {\r\n ParseTree,\r\n Chapter,\r\n Verse,\r\n HebrewSubtitle,\r\n FootnoteReference,\r\n Footnote,\r\n Text,\r\n} from './types.js';\r\nimport { getLogger } from '../log.js';\r\n\r\n/**\r\n * Defines a class that can tokenize a stream of characters into tokens.\r\n */\r\nexport class UsfmTokenizer {\r\n private _input: string = '';\r\n private _index: number = 0;\r\n private _start: number = 0;\r\n\r\n private get _tokenLength() {\r\n return this._index - this._start;\r\n }\r\n\r\n /**\r\n * Converts the given input into a list of tokens.\r\n * @param input The input that should be tokenized.\r\n */\r\n tokenize(input: string): SimpleToken[] {\r\n this._input = input;\r\n this._index = 0;\r\n\r\n return this._parseTokens();\r\n }\r\n\r\n private _parseTokens() {\r\n let tokens: SimpleToken[] = [];\r\n let token = this._parseToken();\r\n while (token) {\r\n tokens.push(token);\r\n token = this._parseToken();\r\n }\r\n\r\n return tokens;\r\n }\r\n\r\n private _parseToken(): SimpleToken | null {\r\n let state:\r\n | 'none'\r\n | 'marker_start'\r\n | 'marker_number'\r\n | 'whitespace'\r\n | 'word' = 'none';\r\n let kind: T | null = null;\r\n this._start = this._index;\r\n\r\n while (this._index < this._input.length) {\r\n const codePointNumber = this._input.codePointAt(this._index);\r\n\r\n if (typeof codePointNumber === 'undefined') {\r\n throw new Error('Unable to get code point!');\r\n }\r\n\r\n const codePoint = String.fromCodePoint(codePointNumber);\r\n\r\n if (state === 'none') {\r\n if (codePoint === '\\\\') {\r\n state = 'marker_start';\r\n } else if (isWhitespace(codePoint)) {\r\n state = 'whitespace';\r\n } else {\r\n state = 'word';\r\n }\r\n } else if (state === 'marker_start') {\r\n if (isDigit(codePoint)) {\r\n if (this._tokenLength === 0) {\r\n throw new Error(\r\n 'Invalid Marker: Markers must not contain only digits.'\r\n );\r\n }\r\n state = 'marker_number';\r\n } else if (codePoint === '*') {\r\n this._index += codePoint.length;\r\n kind = 'marker';\r\n break;\r\n } else if (isWhitespace(codePoint)) {\r\n kind = 'marker';\r\n break;\r\n }\r\n } else if (state === 'marker_number') {\r\n if (codePoint === '*') {\r\n this._index += codePoint.length;\r\n kind = 'marker';\r\n break;\r\n } else if (!isDigit(codePoint)) {\r\n kind = 'marker';\r\n break;\r\n }\r\n } else if (state === 'whitespace') {\r\n if (!isWhitespace(codePoint)) {\r\n kind = 'whitespace';\r\n break;\r\n }\r\n } else if (state === 'word') {\r\n if (isWhitespace(codePoint) || codePoint === '\\\\') {\r\n kind = 'word';\r\n break;\r\n }\r\n }\r\n\r\n this._index += codePoint.length;\r\n }\r\n\r\n if (!kind) {\r\n if (this._index >= this._input.length) {\r\n if (state == 'marker_start' || state === 'marker_number') {\r\n kind = 'marker';\r\n } else if (state === 'word') {\r\n kind = 'word';\r\n } else if (state === 'whitespace') {\r\n kind = 'whitespace';\r\n }\r\n }\r\n }\r\n\r\n if (kind) {\r\n return t(loc(this._start, this._index), kind);\r\n }\r\n\r\n return null;\r\n }\r\n}\r\n\r\nexport interface UsfmParseOptions {\r\n paragraphs: Set<string>;\r\n}\r\n\r\n/**\r\n * Defines a USFM Parser.\r\n */\r\nexport class UsfmParser {\r\n private _poem: number | null = null;\r\n private _wordsOfJesus: boolean = false;\r\n\r\n tokenize(input: string): Token[] {\r\n const simpleTokens = new UsfmTokenizer().tokenize(input);\r\n let tokens: Token[] = [];\r\n\r\n for (let t of simpleTokens) {\r\n if (t.kind === 'marker') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n const isEnd = source.endsWith('*');\r\n\r\n if (isEnd) {\r\n source = source.substring(0, source.length - 1);\r\n }\r\n\r\n let numberIndex = -1;\r\n for (let i = 0; i < source.length; i++) {\r\n if (isDigit(source[i])) {\r\n numberIndex = i;\r\n break;\r\n }\r\n }\r\n\r\n let number: number | null = null;\r\n if (numberIndex === 1) {\r\n throw new Error(\r\n 'Markers must not be made only of numbers!'\r\n );\r\n }\r\n if (numberIndex > 0) {\r\n number = parseInt(source.substring(numberIndex));\r\n source = source.substring(0, numberIndex);\r\n }\r\n\r\n if (source.length === 1) {\r\n if (isEnd) {\r\n // Ending marker does not have a command.\r\n // We should look for a matching start marker.\r\n const startMarker = findLast(\r\n tokens,\r\n (t) => t.kind === 'marker' && t.type === 'start'\r\n ) as MarkerToken;\r\n if (startMarker) {\r\n source = startMarker.command;\r\n }\r\n }\r\n\r\n if (source.length === 1) {\r\n throw new Error(\r\n `Markers must have a command! Token: ${t.loc.start}-${t.loc.end}`\r\n );\r\n }\r\n }\r\n\r\n tokens.push(\r\n marker(t.loc, source, number, isEnd ? 'end' : 'start')\r\n );\r\n } else if (t.kind === 'whitespace') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n tokens.push(whitespace(t.loc, source));\r\n } else if (t.kind === 'word') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n tokens.push(word(t.loc, source));\r\n }\r\n }\r\n\r\n return tokens;\r\n }\r\n\r\n parse(input: string): ParseTree {\r\n let root: ParseTree = {\r\n type: 'root',\r\n content: [],\r\n };\r\n\r\n const tokens = this.tokenize(input);\r\n\r\n let expectingId = 0;\r\n let expectingName = 0;\r\n let expectingTitle = 0;\r\n let expectingSectionHeading = 0;\r\n let expectingFootnote = 0;\r\n let expectingFootnoteReference = 0;\r\n let expectingFootnoteText = 0;\r\n let expectingReferenceText = 0;\r\n let expectingWordAttribute = 0;\r\n let expectingNestedWordAttribute = 0;\r\n let expectingWordsOfJesus = 0;\r\n let expectingIntroParagraph = 0;\r\n let expectingCrossReference = 0;\r\n let expectingUnknownCommand = 0;\r\n\r\n let canParseFootnotes = true;\r\n let chapter: Chapter | null = null;\r\n let lastVerse: Verse | null = null;\r\n let verse: Verse | null = null;\r\n let subtitle: HebrewSubtitle | null = null;\r\n let words: string[] = [];\r\n let verseContent: (Text | FootnoteReference | string)[] = [];\r\n let sectionContent: string = '';\r\n let currentFootnoteId = 0;\r\n let footnote: Footnote | null = null;\r\n\r\n this._poem = null;\r\n\r\n const addWordsToVerseOrSubtitle = () => {\r\n if (words.length > 0) {\r\n const text = this._text(words.join('').trimEnd());\r\n if (verse) {\r\n verse.content.push(text);\r\n } else if (subtitle) {\r\n subtitle.content.push(text);\r\n } else {\r\n verseContent.push(text);\r\n }\r\n words = [];\r\n }\r\n };\r\n\r\n const addVerseContentToChapter = (token: Token | null) => {\r\n if (!chapter) {\r\n return;\r\n }\r\n if (verseContent.length > 0) {\r\n if (chapter.content.some((c) => c.type === 'verse')) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot infer first verse after other verses have been added to the chapter!'\r\n );\r\n }\r\n // Implicit first verse\r\n verse = {\r\n type: 'verse',\r\n number: 1,\r\n content: verseContent,\r\n };\r\n chapter.content.push(verse);\r\n verseContent = [];\r\n }\r\n };\r\n\r\n const cleanupVerse = () => {\r\n if (!verse || !chapter) {\r\n return;\r\n }\r\n let chapterContent: Chapter['content'] = [];\r\n for (let i = verse.content.length - 1; i >= 0; i--) {\r\n let content = verse.content[i];\r\n if (typeof content === 'object' && 'heading' in content) {\r\n // move headings that occur at the end of a verse to the chapter\r\n chapterContent.unshift({\r\n type: 'heading',\r\n content: [content.heading],\r\n });\r\n verse.content.splice(i, 1);\r\n } else if (\r\n typeof content === 'object' &&\r\n 'lineBreak' in content &&\r\n content.lineBreak\r\n ) {\r\n // move line breaks that occur at the end of a verse to the chapter\r\n chapterContent.unshift({\r\n type: 'line_break',\r\n });\r\n verse.content.splice(i, 1);\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n for (let content of chapterContent) {\r\n chapter.content.push(content);\r\n }\r\n };\r\n\r\n const completeVerseOrSubtitle = (token: Token | null) => {\r\n if (verse && isNaN(verse.number)) {\r\n // Verse is invalid for some reason.\r\n const index = chapter!.content.indexOf(verse);\r\n if (index >= 0) {\r\n chapter!.content.splice(index, 1);\r\n }\r\n verse = null;\r\n }\r\n if (verse || subtitle) {\r\n addWordsToVerseOrSubtitle();\r\n }\r\n\r\n addVerseContentToChapter(token);\r\n cleanupVerse();\r\n };\r\n\r\n const completeSection = () => {\r\n if (expectingSectionHeading > 0) {\r\n if (verse) {\r\n addWordsToVerseOrSubtitle();\r\n verse.content.push({\r\n heading: sectionContent,\r\n });\r\n } else if (chapter) {\r\n chapter.content.push({\r\n type: 'heading',\r\n content: [sectionContent],\r\n });\r\n } else {\r\n root.content.push({\r\n type: 'heading',\r\n content: [sectionContent],\r\n });\r\n }\r\n sectionContent = '';\r\n expectingSectionHeading = 0;\r\n }\r\n };\r\n\r\n const addWordsToFootnote = () => {\r\n if (footnote && words.length > 0) {\r\n footnote.text += words.join(' ');\r\n words = [];\r\n }\r\n };\r\n\r\n for (let token of tokens) {\r\n if (token.kind === 'marker') {\r\n if (token.command === '\\\\c') {\r\n addWordsToVerseOrSubtitle();\r\n cleanupVerse();\r\n\r\n chapter = {\r\n type: 'chapter',\r\n number: NaN,\r\n content: [],\r\n footnotes: [],\r\n };\r\n verse = null;\r\n verseContent = [];\r\n\r\n root.content.push(chapter);\r\n } else if (token.command === '\\\\v') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a verse without chapter information!'\r\n );\r\n } else {\r\n completeSection();\r\n completeVerseOrSubtitle(token);\r\n\r\n lastVerse = verse;\r\n verse = {\r\n type: 'verse',\r\n number: NaN,\r\n content: [],\r\n };\r\n\r\n chapter.content.push(verse);\r\n }\r\n } else if (token.command === '\\\\d') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a hebrew subtitle without chapter information!'\r\n );\r\n } else {\r\n completeVerseOrSubtitle(token);\r\n\r\n subtitle = {\r\n type: 'hebrew_subtitle',\r\n content: [],\r\n };\r\n\r\n chapter.content.push(subtitle);\r\n }\r\n } else if (token.command === '\\\\b' || token.command === '\\\\p') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a line break without chapter information!'\r\n );\r\n } else {\r\n if (verse) {\r\n addWordsToVerseOrSubtitle();\r\n verse.content.push({\r\n lineBreak: true,\r\n });\r\n } else {\r\n completeVerseOrSubtitle(token);\r\n chapter.content.push({\r\n type: 'line_break',\r\n });\r\n }\r\n }\r\n } else if (token.command === '\\\\q') {\r\n addWordsToVerseOrSubtitle();\r\n this._poem = token.number;\r\n } else if (token.command === '\\\\p') {\r\n addWordsToVerseOrSubtitle();\r\n this._poem = null;\r\n } else if (token.command === '\\\\id') {\r\n expectingId = 1;\r\n } else if (token.command === '\\\\h') {\r\n expectingName = 1;\r\n root.header = undefined;\r\n } else if (\r\n token.command === '\\\\mt' ||\r\n token.command === '\\\\+mt'\r\n ) {\r\n expectingTitle = 1;\r\n } else if (token.command === '\\\\s') {\r\n expectingSectionHeading = 1;\r\n } else if (token.command === '\\\\r') {\r\n expectingReferenceText = 1;\r\n } else if (token.command === '\\\\f' && canParseFootnotes) {\r\n if (token.type === 'start') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start a footnote outside of a chapter!',\r\n true\r\n );\r\n } else {\r\n addWordsToVerseOrSubtitle();\r\n footnote = {\r\n noteId: currentFootnoteId,\r\n text: '',\r\n caller: null,\r\n };\r\n const ref: FootnoteReference = {\r\n noteId: footnote.noteId,\r\n };\r\n expectingFootnote = 1;\r\n\r\n chapter.footnotes.push(footnote);\r\n\r\n if (verse) {\r\n verse.content.push(ref);\r\n } else if (subtitle) {\r\n subtitle.content.push(ref);\r\n } else {\r\n verseContent.push(ref);\r\n }\r\n\r\n currentFootnoteId += 1;\r\n }\r\n } else {\r\n addWordsToFootnote();\r\n expectingFootnote = 0;\r\n expectingFootnoteText = 0;\r\n expectingFootnoteReference = 0;\r\n footnote = null;\r\n }\r\n } else if (token.command === '\\\\fr' && canParseFootnotes) {\r\n if (!footnote) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start a footnote reference outside of a footnote!',\r\n true\r\n );\r\n } else {\r\n expectingFootnoteReference = 1;\r\n }\r\n } else if (token.command === '\\\\ft' && canParseFootnotes) {\r\n if (!footnote) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start footnote text outside of a footnote!',\r\n true\r\n );\r\n } else {\r\n expectingFootnoteText = 1;\r\n }\r\n } else if (token.command === '\\\\w') {\r\n if (token.type === 'start') {\r\n expectingWordAttribute = 1;\r\n } else {\r\n expectingWordAttribute = 0;\r\n }\r\n } else if (token.command === '\\\\+w') {\r\n if (token.type === 'start') {\r\n expectingNestedWordAttribute = 1;\r\n } else {\r\n expectingNestedWordAttribute = 0;\r\n }\r\n } else if (\r\n token.command === '\\\\wj' ||\r\n token.command === '\\\\+wj'\r\n ) {\r\n if (token.type === 'start') {\r\n addWordsToVerseOrSubtitle();\r\n this._wordsOfJesus = true;\r\n } else {\r\n addWordsToVerseOrSubtitle();\r\n this._wordsOfJesus = false;\r\n }\r\n } else if (token.command === '\\\\ip') {\r\n expectingIntroParagraph = 1;\r\n canParseFootnotes = false;\r\n } else if (token.command === '\\\\x') {\r\n if (token.type === 'start') {\r\n expectingCrossReference = 1;\r\n } else {\r\n expectingCrossReference = 0;\r\n }\r\n } else if (token.command.indexOf('-') >= 0) {\r\n if (token.type === 'start') {\r\n expectingUnknownCommand = 1;\r\n }\r\n } else if (token.type === 'end') {\r\n expectingUnknownCommand = 0;\r\n }\r\n } else if (token.kind === 'word') {\r\n if (expectingId > 0) {\r\n if (expectingId === 1) {\r\n root.id = token.word;\r\n expectingId = 2;\r\n }\r\n } else if (expectingName > 0) {\r\n if (root.header) {\r\n root.header += ' ' + token.word;\r\n } else {\r\n root.header = token.word;\r\n }\r\n } else if (expectingTitle > 0) {\r\n if (root.title) {\r\n root.title += ' ' + token.word;\r\n } else {\r\n root.title = token.word;\r\n }\r\n } else if (expectingSectionHeading > 0) {\r\n if (sectionContent) {\r\n sectionContent += ' ' + token.word;\r\n } else {\r\n sectionContent = token.word;\r\n }\r\n } else if (expectingFootnoteReference > 0) {\r\n if ((expectingFootnoteReference = 1)) {\r\n const [chapter, verse] = token.word.split(/[\\.\\:]/);\r\n\r\n if (footnote) {\r\n footnote.reference = {\r\n chapter: parseInt(chapter),\r\n verse: parseInt(verse),\r\n };\r\n }\r\n\r\n expectingFootnoteReference = 0;\r\n }\r\n } else if (expectingFootnoteText > 0) {\r\n words.push(token.word);\r\n } else if (expectingFootnote > 0) {\r\n if (expectingFootnote === 1) {\r\n if (token.word) {\r\n if (footnote) {\r\n if (token.word === '+' || token.word !== '-') {\r\n footnote.caller = token.word;\r\n } else {\r\n footnote.caller = null;\r\n }\r\n }\r\n // this._throwError(input, token, 'Footnotes must use the \"+\" caller.');\r\n }\r\n expectingFootnote = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n } else if (expectingReferenceText > 0) {\r\n // Skip processing words for references\r\n // because references aren't included in the JSON format\r\n // (for now)\r\n } else if (expectingCrossReference > 0) {\r\n // Skip processing words for cross references\r\n } else if (chapter && isNaN(chapter.number)) {\r\n chapter.number = parseInt(token.word);\r\n if (isNaN(chapter.number)) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'The first word token after a chapter marker must be parsable to an integer!'\r\n );\r\n }\r\n } else if (verse && isNaN(verse.number)) {\r\n verse.number = parseInt(token.word);\r\n if (isNaN(verse.number)) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'The first word token after a verse marker must be parsable to an integer!'\r\n );\r\n }\r\n } else if (expectingWordAttribute > 0) {\r\n if (expectingWordAttribute === 1) {\r\n const firstVerticalBarIndex = token.word.indexOf('|');\r\n\r\n if (firstVerticalBarIndex >= 0) {\r\n const name = token.word.slice(\r\n 0,\r\n firstVerticalBarIndex\r\n );\r\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\r\n words.push(name);\r\n expectingWordAttribute = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n }\r\n } else if (expectingNestedWordAttribute > 0) {\r\n if (expectingNestedWordAttribute === 1) {\r\n const firstVerticalBarIndex = token.word.indexOf('|');\r\n\r\n if (firstVerticalBarIndex >= 0) {\r\n const name = token.word.slice(\r\n 0,\r\n firstVerticalBarIndex\r\n );\r\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\r\n words.push(name);\r\n expectingNestedWordAttribute = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n }\r\n } else if (expectingUnknownCommand > 0) {\r\n } else if (expectingIntroParagraph > 0) {\r\n // Skip processing words for intro paragraphs\r\n } else {\r\n words.push(token.word);\r\n }\r\n } else if (token.kind === 'whitespace') {\r\n if (expectingId > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingId = 0;\r\n }\r\n } else if (expectingName > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingName = 0;\r\n }\r\n } else if (expectingTitle > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingTitle = 0;\r\n }\r\n } else if (expectingSectionHeading > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n completeSection();\r\n }\r\n } else if (expectingReferenceText > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingReferenceText = 0;\r\n }\r\n } else if (expectingIntroParagraph > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingIntroParagraph = 0;\r\n canParseFootnotes = true;\r\n }\r\n } else if (\r\n expectingId > 0 ||\r\n expectingName > 0 ||\r\n expectingTitle > 0 ||\r\n expectingSectionHeading > 0 ||\r\n expectingFootnote > 0 ||\r\n expectingFootnoteReference > 0 ||\r\n expectingFootnoteText > 0 ||\r\n expectingReferenceText > 0 ||\r\n expectingCrossReference > 0 ||\r\n expectingWordAttribute > 0 ||\r\n expectingNestedWordAttribute > 0\r\n ) {\r\n // Skip\r\n } else if (expectingUnknownCommand > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingUnknownCommand = 0;\r\n }\r\n } else if (words.length > 0) {\r\n let lastWord = words[words.length - 1];\r\n if (lastWord !== ' ') {\r\n words.push(' ');\r\n }\r\n }\r\n }\r\n }\r\n\r\n completeVerseOrSubtitle(null);\r\n\r\n return root;\r\n }\r\n\r\n renderMarkdown(tree: ParseTree): string {\r\n let md = '';\r\n\r\n if (tree.header) {\r\n md += `# ${tree.header}\\n`;\r\n }\r\n\r\n for (let c of tree.content) {\r\n if (c.type === 'heading') {\r\n md += `## ${c.content.join(' ')}\\n`;\r\n } else if (c.type === 'chapter') {\r\n md += `### ${c.number}\\n`;\r\n\r\n for (let content of c.content) {\r\n if (content.type === 'heading') {\r\n md += `#### ${content.content.join(' ')}\\n`;\r\n } else if (content.type === 'line_break') {\r\n md += '\\n\\n';\r\n } else if (content.type === 'verse') {\r\n md += `<em>${content.number}</em>`;\r\n for (let v of content.content) {\r\n if (typeof v === 'string') {\r\n md += v + ' ';\r\n } else if ('text' in v) {\r\n md += v.text + ' ';\r\n }\r\n }\r\n md += '\\n';\r\n }\r\n }\r\n }\r\n }\r\n\r\n return md;\r\n }\r\n\r\n private _hasAttribute() {\r\n return this._poem !== null || this._wordsOfJesus;\r\n }\r\n\r\n private _text(text: string): Text | string {\r\n if (!this._hasAttribute()) {\r\n return text;\r\n }\r\n const t: Text = {\r\n text,\r\n };\r\n\r\n if (this._poem !== null) {\r\n t.poem = this._poem;\r\n }\r\n\r\n if (this._wordsOfJesus) {\r\n t.wordsOfJesus = true;\r\n }\r\n\r\n return t;\r\n }\r\n\r\n private _throwError(\r\n source: string,\r\n token: Token | null,\r\n message: string,\r\n warn: boolean = false\r\n ): void {\r\n const logger = getLogger();\r\n if (token) {\r\n let line = 1;\r\n let column = 1;\r\n\r\n let start = token.loc.start;\r\n\r\n for (let i = 0; i < start; i++) {\r\n let char = source[i];\r\n if (char === '\\n') {\r\n line += 1;\r\n column = 1;\r\n } else {\r\n column += 1;\r\n }\r\n }\r\n\r\n let tokenDebug = '';\r\n if (token.kind === 'word') {\r\n tokenDebug = ', word';\r\n } else if (token.kind === 'marker') {\r\n tokenDebug = ', ' + token.command;\r\n } else {\r\n tokenDebug = '';\r\n }\r\n\r\n if (warn) {\r\n logger.warn(`(${line}, ${column}${tokenDebug}) ${message}`);\r\n } else {\r\n throw new Error(`(${line}, ${column}${tokenDebug}) ${message}`);\r\n }\r\n } else {\r\n if (warn) {\r\n logger.warn(message);\r\n } else {\r\n throw new Error(message);\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Determines if the given character is a digit.\r\n * @param char The character.\r\n */\r\nexport function isDigit(char: string): boolean {\r\n return char.length === 1 && char >= '0' && char <= '9';\r\n}\r\n\r\n/**\r\n * Determines if the given character is considered whitespace.\r\n * @param char The character.\r\n */\r\nexport function isWhitespace(char: string): boolean {\r\n return char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\r\n}\r\n\r\nexport function t(loc: SourceLocation, kind: T): SimpleToken {\r\n return {\r\n loc,\r\n kind,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new source location.\r\n * @param start The start of the location.\r\n * @param end The end of the location.\r\n */\r\nexport function loc(start: number, end: number): SourceLocation {\r\n return {\r\n start,\r\n end,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new marker token.\r\n * @param loc The location for the token.\r\n * @param command The command that the token contains.\r\n * @param number The number that the marker contains.\r\n * @param type The type of the marker.\r\n */\r\nexport function marker(\r\n loc: SourceLocation,\r\n command: string,\r\n number: number | null = null,\r\n type: MarkerToken['type'] = 'start'\r\n): MarkerToken {\r\n return {\r\n kind: 'marker',\r\n loc,\r\n command,\r\n number,\r\n type,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new word token.\r\n * @param loc The location for the token.\r\n * @param word The word contained by the token.\r\n */\r\nexport function word(loc: SourceLocation, word: string): WordToken {\r\n return {\r\n kind: 'word',\r\n loc,\r\n word,\r\n };\r\n}\r\n\r\nexport function whitespace(\r\n loc: SourceLocation,\r\n whitespace: string\r\n): WhitespaceToken {\r\n return {\r\n kind: 'whitespace',\r\n loc,\r\n whitespace,\r\n };\r\n}\r\n\r\nexport type T = Token['kind'];\r\n\r\n/**\r\n * Defines a simple token.\r\n */\r\nexport interface SimpleToken {\r\n kind: T;\r\n loc: SourceLocation;\r\n}\r\n\r\nexport type Token = MarkerToken | WordToken | WhitespaceToken;\r\n\r\n/**\r\n * Defines an interface for a USFM marker node.\r\n * That is, the syntax for a marker.\r\n */\r\nexport interface MarkerToken {\r\n kind: 'marker';\r\n\r\n /**\r\n * The command that the marker represents.\r\n * This is generally the name of the marker (like \"p\" or \"v\" for paragraph and verse markers)\r\n */\r\n command: string;\r\n\r\n /**\r\n * The number that the marker contains.\r\n * Null if no number was specified.\r\n */\r\n number: number | null;\r\n\r\n /**\r\n * Whether the marker represents a start or an end.\r\n */\r\n type: 'start' | 'end';\r\n\r\n /**\r\n * The location of the node.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * Defines an interface for a Whitespace node.\r\n */\r\nexport interface WhitespaceToken {\r\n kind: 'whitespace';\r\n\r\n /**\r\n * The whitespace contained by the node.\r\n */\r\n whitespace: string;\r\n\r\n /**\r\n * The location of the node.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * Defines an interface for a word token.\r\n */\r\nexport interface WordToken {\r\n kind: 'word';\r\n\r\n /**\r\n * The word contained by the token.\r\n */\r\n word: string;\r\n\r\n /**\r\n * The location of the word.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * The source location of the node.\r\n */\r\nexport interface SourceLocation {\r\n start: number;\r\n end: number;\r\n}\r\n"],
|
|
4
|
+
"sourcesContent": ["import { findLast } from 'es-toolkit/compat';\r\nimport {\r\n ParseTree,\r\n Chapter,\r\n Verse,\r\n HebrewSubtitle,\r\n FootnoteReference,\r\n Footnote,\r\n Text,\r\n} from './types.js';\r\nimport { getLogger } from '../log.js';\r\n\r\n/**\r\n * Defines a class that can tokenize a stream of characters into tokens.\r\n */\r\nexport class UsfmTokenizer {\r\n private _input: string = '';\r\n private _index: number = 0;\r\n private _start: number = 0;\r\n\r\n private get _tokenLength() {\r\n return this._index - this._start;\r\n }\r\n\r\n /**\r\n * Converts the given input into a list of tokens.\r\n * @param input The input that should be tokenized.\r\n */\r\n tokenize(input: string): SimpleToken[] {\r\n this._input = input;\r\n this._index = 0;\r\n\r\n return this._parseTokens();\r\n }\r\n\r\n private _parseTokens() {\r\n let tokens: SimpleToken[] = [];\r\n let token = this._parseToken();\r\n while (token) {\r\n tokens.push(token);\r\n token = this._parseToken();\r\n }\r\n\r\n return tokens;\r\n }\r\n\r\n private _parseToken(): SimpleToken | null {\r\n let state:\r\n | 'none'\r\n | 'marker_start'\r\n | 'marker_number'\r\n | 'whitespace'\r\n | 'word' = 'none';\r\n let kind: T | null = null;\r\n this._start = this._index;\r\n\r\n while (this._index < this._input.length) {\r\n const codePointNumber = this._input.codePointAt(this._index);\r\n\r\n if (typeof codePointNumber === 'undefined') {\r\n throw new Error('Unable to get code point!');\r\n }\r\n\r\n const codePoint = String.fromCodePoint(codePointNumber);\r\n\r\n if (state === 'none') {\r\n if (codePoint === '\\\\') {\r\n state = 'marker_start';\r\n } else if (isWhitespace(codePoint)) {\r\n state = 'whitespace';\r\n } else {\r\n state = 'word';\r\n }\r\n } else if (state === 'marker_start') {\r\n if (isDigit(codePoint)) {\r\n if (this._tokenLength === 0) {\r\n throw new Error(\r\n 'Invalid Marker: Markers must not contain only digits.'\r\n );\r\n }\r\n state = 'marker_number';\r\n } else if (codePoint === '*') {\r\n this._index += codePoint.length;\r\n kind = 'marker';\r\n break;\r\n } else if (isWhitespace(codePoint)) {\r\n kind = 'marker';\r\n break;\r\n }\r\n } else if (state === 'marker_number') {\r\n if (codePoint === '*') {\r\n this._index += codePoint.length;\r\n kind = 'marker';\r\n break;\r\n } else if (!isDigit(codePoint)) {\r\n kind = 'marker';\r\n break;\r\n }\r\n } else if (state === 'whitespace') {\r\n if (!isWhitespace(codePoint)) {\r\n kind = 'whitespace';\r\n break;\r\n }\r\n } else if (state === 'word') {\r\n if (isWhitespace(codePoint) || codePoint === '\\\\') {\r\n kind = 'word';\r\n break;\r\n }\r\n }\r\n\r\n this._index += codePoint.length;\r\n }\r\n\r\n if (!kind) {\r\n if (this._index >= this._input.length) {\r\n if (state == 'marker_start' || state === 'marker_number') {\r\n kind = 'marker';\r\n } else if (state === 'word') {\r\n kind = 'word';\r\n } else if (state === 'whitespace') {\r\n kind = 'whitespace';\r\n }\r\n }\r\n }\r\n\r\n if (kind) {\r\n return t(loc(this._start, this._index), kind);\r\n }\r\n\r\n return null;\r\n }\r\n}\r\n\r\nexport interface UsfmParseOptions {\r\n paragraphs: Set<string>;\r\n}\r\n\r\n/**\r\n * Defines a USFM Parser.\r\n */\r\nexport class UsfmParser {\r\n private _poem: number | null = null;\r\n private _wordsOfJesus: boolean = false;\r\n\r\n tokenize(input: string): Token[] {\r\n const simpleTokens = new UsfmTokenizer().tokenize(input);\r\n let tokens: Token[] = [];\r\n\r\n for (let t of simpleTokens) {\r\n if (t.kind === 'marker') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n const isEnd = source.endsWith('*');\r\n\r\n if (isEnd) {\r\n source = source.substring(0, source.length - 1);\r\n }\r\n\r\n let numberIndex = -1;\r\n for (let i = 0; i < source.length; i++) {\r\n if (isDigit(source[i])) {\r\n numberIndex = i;\r\n break;\r\n }\r\n }\r\n\r\n let number: number | null = null;\r\n if (numberIndex === 1) {\r\n throw new Error(\r\n 'Markers must not be made only of numbers!'\r\n );\r\n }\r\n if (numberIndex > 0) {\r\n number = parseInt(source.substring(numberIndex));\r\n source = source.substring(0, numberIndex);\r\n }\r\n\r\n if (source.length === 1) {\r\n if (isEnd) {\r\n // Ending marker does not have a command.\r\n // We should look for a matching start marker.\r\n const startMarker = findLast(\r\n tokens,\r\n (t) => t.kind === 'marker' && t.type === 'start'\r\n ) as MarkerToken;\r\n if (startMarker) {\r\n source = startMarker.command;\r\n }\r\n }\r\n\r\n if (source.length === 1) {\r\n throw new Error(\r\n `Markers must have a command! Token: ${t.loc.start}-${t.loc.end}`\r\n );\r\n }\r\n }\r\n\r\n tokens.push(\r\n marker(t.loc, source, number, isEnd ? 'end' : 'start')\r\n );\r\n } else if (t.kind === 'whitespace') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n tokens.push(whitespace(t.loc, source));\r\n } else if (t.kind === 'word') {\r\n let source = input.substring(t.loc.start, t.loc.end);\r\n tokens.push(word(t.loc, source));\r\n }\r\n }\r\n\r\n return tokens;\r\n }\r\n\r\n parse(input: string): ParseTree {\r\n let root: ParseTree = {\r\n type: 'root',\r\n content: [],\r\n };\r\n\r\n const tokens = this.tokenize(input);\r\n\r\n let expectingId = 0;\r\n let expectingName = 0;\r\n let expectingTitle = 0;\r\n let expectingSectionHeading = 0;\r\n let expectingFootnote = 0;\r\n let expectingFootnoteReference = 0;\r\n let expectingFootnoteText = 0;\r\n let expectingReferenceText = 0;\r\n let expectingWordAttribute = 0;\r\n let expectingNestedWordAttribute = 0;\r\n let expectingWordsOfJesus = 0;\r\n let expectingIntroParagraph = 0;\r\n let expectingCrossReference = 0;\r\n let expectingUnknownCommand = 0;\r\n\r\n let canParseFootnotes = true;\r\n let chapter: Chapter | null = null;\r\n let lastVerse: Verse | null = null;\r\n let verse: Verse | null = null;\r\n let subtitle: HebrewSubtitle | null = null;\r\n let words: string[] = [];\r\n let verseContent: (Text | FootnoteReference | string)[] = [];\r\n let sectionContent: string = '';\r\n let currentFootnoteId = 0;\r\n let footnote: Footnote | null = null;\r\n\r\n this._poem = null;\r\n\r\n const addWordsToVerseOrSubtitle = () => {\r\n if (words.length > 0) {\r\n const text = this._text(words.join('').trimEnd());\r\n if (verse) {\r\n verse.content.push(text);\r\n } else if (subtitle) {\r\n subtitle.content.push(text);\r\n } else {\r\n verseContent.push(text);\r\n }\r\n words = [];\r\n }\r\n };\r\n\r\n const addVerseContentToChapter = (token: Token | null) => {\r\n if (!chapter) {\r\n return;\r\n }\r\n if (verseContent.length > 0) {\r\n if (chapter.content.some((c) => c.type === 'verse')) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot infer first verse after other verses have been added to the chapter!'\r\n );\r\n }\r\n // Implicit first verse\r\n verse = {\r\n type: 'verse',\r\n number: 1,\r\n content: verseContent,\r\n };\r\n chapter.content.push(verse);\r\n verseContent = [];\r\n }\r\n };\r\n\r\n const cleanupVerse = () => {\r\n if (!verse || !chapter) {\r\n return;\r\n }\r\n let chapterContent: Chapter['content'] = [];\r\n for (let i = verse.content.length - 1; i >= 0; i--) {\r\n let content = verse.content[i];\r\n if (typeof content === 'object' && 'heading' in content) {\r\n // move headings that occur at the end of a verse to the chapter\r\n chapterContent.unshift({\r\n type: 'heading',\r\n content: [content.heading],\r\n });\r\n verse.content.splice(i, 1);\r\n } else if (\r\n typeof content === 'object' &&\r\n 'lineBreak' in content &&\r\n content.lineBreak\r\n ) {\r\n // move line breaks that occur at the end of a verse to the chapter\r\n chapterContent.unshift({\r\n type: 'line_break',\r\n });\r\n verse.content.splice(i, 1);\r\n } else {\r\n break;\r\n }\r\n }\r\n\r\n for (let content of chapterContent) {\r\n chapter.content.push(content);\r\n }\r\n };\r\n\r\n const completeVerseOrSubtitle = (token: Token | null) => {\r\n if (verse && isNaN(verse.number)) {\r\n // Verse is invalid for some reason.\r\n const index = chapter!.content.indexOf(verse);\r\n if (index >= 0) {\r\n chapter!.content.splice(index, 1);\r\n }\r\n verse = null;\r\n }\r\n if (verse || subtitle) {\r\n addWordsToVerseOrSubtitle();\r\n }\r\n\r\n addVerseContentToChapter(token);\r\n cleanupVerse();\r\n };\r\n\r\n const completeSection = () => {\r\n if (expectingSectionHeading > 0) {\r\n if (verse) {\r\n addWordsToVerseOrSubtitle();\r\n verse.content.push({\r\n heading: sectionContent,\r\n });\r\n } else if (chapter) {\r\n chapter.content.push({\r\n type: 'heading',\r\n content: [sectionContent],\r\n });\r\n } else {\r\n root.content.push({\r\n type: 'heading',\r\n content: [sectionContent],\r\n });\r\n }\r\n sectionContent = '';\r\n expectingSectionHeading = 0;\r\n }\r\n };\r\n\r\n const addWordsToFootnote = () => {\r\n if (footnote && words.length > 0) {\r\n footnote.text += words.join(' ');\r\n words = [];\r\n }\r\n };\r\n\r\n for (let token of tokens) {\r\n if (token.kind === 'marker') {\r\n if (token.command === '\\\\c') {\r\n addWordsToVerseOrSubtitle();\r\n cleanupVerse();\r\n\r\n chapter = {\r\n type: 'chapter',\r\n number: NaN,\r\n content: [],\r\n footnotes: [],\r\n };\r\n verse = null;\r\n verseContent = [];\r\n\r\n root.content.push(chapter);\r\n } else if (token.command === '\\\\v') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a verse without chapter information!'\r\n );\r\n } else {\r\n completeSection();\r\n completeVerseOrSubtitle(token);\r\n\r\n lastVerse = verse;\r\n verse = {\r\n type: 'verse',\r\n number: NaN,\r\n content: [],\r\n };\r\n\r\n chapter.content.push(verse);\r\n }\r\n } else if (token.command === '\\\\d') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a hebrew subtitle without chapter information!'\r\n );\r\n } else {\r\n completeVerseOrSubtitle(token);\r\n\r\n subtitle = {\r\n type: 'hebrew_subtitle',\r\n content: [],\r\n };\r\n\r\n chapter.content.push(subtitle);\r\n }\r\n } else if (token.command === '\\\\b' || token.command === '\\\\p') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot parse a line break without chapter information!'\r\n );\r\n } else {\r\n if (verse) {\r\n addWordsToVerseOrSubtitle();\r\n verse.content.push({\r\n lineBreak: true,\r\n });\r\n } else {\r\n completeVerseOrSubtitle(token);\r\n chapter.content.push({\r\n type: 'line_break',\r\n });\r\n }\r\n }\r\n } else if (token.command === '\\\\q') {\r\n addWordsToVerseOrSubtitle();\r\n this._poem = token.number;\r\n } else if (token.command === '\\\\p') {\r\n addWordsToVerseOrSubtitle();\r\n this._poem = null;\r\n } else if (token.command === '\\\\id') {\r\n expectingId = 1;\r\n } else if (token.command === '\\\\h') {\r\n expectingName = 1;\r\n root.header = undefined;\r\n } else if (\r\n token.command === '\\\\mt' ||\r\n token.command === '\\\\+mt'\r\n ) {\r\n expectingTitle = 1;\r\n } else if (token.command === '\\\\s') {\r\n expectingSectionHeading = 1;\r\n } else if (token.command === '\\\\r') {\r\n expectingReferenceText = 1;\r\n } else if (token.command === '\\\\f' && canParseFootnotes) {\r\n if (token.type === 'start') {\r\n if (!chapter) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start a footnote outside of a chapter!',\r\n true\r\n );\r\n } else {\r\n addWordsToVerseOrSubtitle();\r\n footnote = {\r\n noteId: currentFootnoteId,\r\n text: '',\r\n caller: null,\r\n };\r\n const ref: FootnoteReference = {\r\n noteId: footnote.noteId,\r\n };\r\n expectingFootnote = 1;\r\n\r\n chapter.footnotes.push(footnote);\r\n\r\n if (verse) {\r\n verse.content.push(ref);\r\n } else if (subtitle) {\r\n subtitle.content.push(ref);\r\n } else {\r\n verseContent.push(ref);\r\n }\r\n\r\n currentFootnoteId += 1;\r\n }\r\n } else {\r\n addWordsToFootnote();\r\n expectingFootnote = 0;\r\n expectingFootnoteText = 0;\r\n expectingFootnoteReference = 0;\r\n footnote = null;\r\n }\r\n } else if (token.command === '\\\\fr' && canParseFootnotes) {\r\n if (!footnote) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start a footnote reference outside of a footnote!',\r\n true\r\n );\r\n } else {\r\n expectingFootnoteReference = 1;\r\n }\r\n } else if (token.command === '\\\\ft' && canParseFootnotes) {\r\n if (!footnote) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'Cannot start footnote text outside of a footnote!',\r\n true\r\n );\r\n } else {\r\n expectingFootnoteText = 1;\r\n }\r\n } else if (token.command === '\\\\w') {\r\n if (token.type === 'start') {\r\n expectingWordAttribute = 1;\r\n } else {\r\n expectingWordAttribute = 0;\r\n }\r\n } else if (token.command === '\\\\+w') {\r\n if (token.type === 'start') {\r\n expectingNestedWordAttribute = 1;\r\n } else {\r\n expectingNestedWordAttribute = 0;\r\n }\r\n } else if (\r\n token.command === '\\\\wj' ||\r\n token.command === '\\\\+wj'\r\n ) {\r\n if (token.type === 'start') {\r\n addWordsToVerseOrSubtitle();\r\n this._wordsOfJesus = true;\r\n } else {\r\n addWordsToVerseOrSubtitle();\r\n this._wordsOfJesus = false;\r\n }\r\n } else if (token.command === '\\\\ip') {\r\n expectingIntroParagraph = 1;\r\n canParseFootnotes = false;\r\n } else if (token.command === '\\\\x') {\r\n if (token.type === 'start') {\r\n expectingCrossReference = 1;\r\n } else {\r\n expectingCrossReference = 0;\r\n }\r\n } else if (token.command.indexOf('-') >= 0) {\r\n if (token.type === 'start') {\r\n expectingUnknownCommand = 1;\r\n }\r\n } else if (token.type === 'end') {\r\n expectingUnknownCommand = 0;\r\n }\r\n } else if (token.kind === 'word') {\r\n if (expectingId > 0) {\r\n if (expectingId === 1) {\r\n root.id = token.word;\r\n expectingId = 2;\r\n }\r\n } else if (expectingName > 0) {\r\n if (root.header) {\r\n root.header += ' ' + token.word;\r\n } else {\r\n root.header = token.word;\r\n }\r\n } else if (expectingTitle > 0) {\r\n if (root.title) {\r\n root.title += ' ' + token.word;\r\n } else {\r\n root.title = token.word;\r\n }\r\n } else if (expectingSectionHeading > 0) {\r\n if (sectionContent) {\r\n sectionContent += ' ' + token.word;\r\n } else {\r\n sectionContent = token.word;\r\n }\r\n } else if (expectingFootnoteReference > 0) {\r\n if ((expectingFootnoteReference = 1)) {\r\n const [chapter, verse] = token.word.split(/[\\.\\:]/);\r\n\r\n if (footnote) {\r\n footnote.reference = {\r\n chapter: parseInt(chapter),\r\n verse: parseInt(verse),\r\n };\r\n }\r\n\r\n expectingFootnoteReference = 0;\r\n }\r\n } else if (expectingFootnoteText > 0) {\r\n words.push(token.word);\r\n } else if (expectingFootnote > 0) {\r\n if (expectingFootnote === 1) {\r\n if (token.word) {\r\n if (footnote) {\r\n if (token.word === '+' || token.word !== '-') {\r\n footnote.caller = token.word;\r\n } else {\r\n footnote.caller = null;\r\n }\r\n }\r\n // this._throwError(input, token, 'Footnotes must use the \"+\" caller.');\r\n }\r\n expectingFootnote = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n } else if (expectingReferenceText > 0) {\r\n // Skip processing words for references\r\n // because references aren't included in the JSON format\r\n // (for now)\r\n } else if (expectingCrossReference > 0) {\r\n // Skip processing words for cross references\r\n } else if (chapter && isNaN(chapter.number)) {\r\n chapter.number = parseInt(token.word);\r\n if (isNaN(chapter.number)) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'The first word token after a chapter marker must be parsable to an integer!'\r\n );\r\n }\r\n } else if (verse && isNaN(verse.number)) {\r\n verse.number = parseInt(token.word);\r\n if (isNaN(verse.number)) {\r\n this._throwError(\r\n input,\r\n token,\r\n 'The first word token after a verse marker must be parsable to an integer!'\r\n );\r\n }\r\n } else if (expectingWordAttribute > 0) {\r\n if (expectingWordAttribute === 1) {\r\n const firstVerticalBarIndex = token.word.indexOf('|');\r\n\r\n if (firstVerticalBarIndex >= 0) {\r\n const name = token.word.slice(\r\n 0,\r\n firstVerticalBarIndex\r\n );\r\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\r\n words.push(name);\r\n expectingWordAttribute = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n }\r\n } else if (expectingNestedWordAttribute > 0) {\r\n if (expectingNestedWordAttribute === 1) {\r\n const firstVerticalBarIndex = token.word.indexOf('|');\r\n\r\n if (firstVerticalBarIndex >= 0) {\r\n const name = token.word.slice(\r\n 0,\r\n firstVerticalBarIndex\r\n );\r\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\r\n words.push(name);\r\n expectingNestedWordAttribute = 2;\r\n } else {\r\n words.push(token.word);\r\n }\r\n }\r\n } else if (expectingUnknownCommand > 0) {\r\n } else if (expectingIntroParagraph > 0) {\r\n // Skip processing words for intro paragraphs\r\n } else {\r\n words.push(token.word);\r\n }\r\n } else if (token.kind === 'whitespace') {\r\n if (expectingId > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingId = 0;\r\n }\r\n } else if (expectingName > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingName = 0;\r\n }\r\n } else if (expectingTitle > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingTitle = 0;\r\n }\r\n } else if (expectingSectionHeading > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n completeSection();\r\n }\r\n } else if (expectingReferenceText > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingReferenceText = 0;\r\n }\r\n } else if (expectingIntroParagraph > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingIntroParagraph = 0;\r\n canParseFootnotes = true;\r\n }\r\n } else if (\r\n expectingId > 0 ||\r\n expectingName > 0 ||\r\n expectingTitle > 0 ||\r\n expectingSectionHeading > 0 ||\r\n expectingFootnote > 0 ||\r\n expectingFootnoteReference > 0 ||\r\n expectingFootnoteText > 0 ||\r\n expectingReferenceText > 0 ||\r\n expectingCrossReference > 0 ||\r\n expectingWordAttribute > 0 ||\r\n expectingNestedWordAttribute > 0\r\n ) {\r\n // Skip\r\n } else if (expectingUnknownCommand > 0) {\r\n if (token.whitespace.includes('\\n')) {\r\n expectingUnknownCommand = 0;\r\n }\r\n } else if (words.length > 0) {\r\n let lastWord = words[words.length - 1];\r\n if (lastWord !== ' ') {\r\n words.push(' ');\r\n }\r\n }\r\n }\r\n }\r\n\r\n completeVerseOrSubtitle(null);\r\n\r\n return root;\r\n }\r\n\r\n renderMarkdown(tree: ParseTree): string {\r\n let md = '';\r\n\r\n if (tree.header) {\r\n md += `# ${tree.header}\\n`;\r\n }\r\n\r\n for (let c of tree.content) {\r\n if (c.type === 'heading') {\r\n md += `## ${c.content.join(' ')}\\n`;\r\n } else if (c.type === 'chapter') {\r\n md += `### ${c.number}\\n`;\r\n\r\n for (let content of c.content) {\r\n if (content.type === 'heading') {\r\n md += `#### ${content.content.join(' ')}\\n`;\r\n } else if (content.type === 'line_break') {\r\n md += '\\n\\n';\r\n } else if (content.type === 'verse') {\r\n md += `<em>${content.number}</em>`;\r\n for (let v of content.content) {\r\n if (typeof v === 'string') {\r\n md += v + ' ';\r\n } else if ('text' in v) {\r\n md += v.text + ' ';\r\n }\r\n }\r\n md += '\\n';\r\n }\r\n }\r\n }\r\n }\r\n\r\n return md;\r\n }\r\n\r\n private _hasAttribute() {\r\n return this._poem !== null || this._wordsOfJesus;\r\n }\r\n\r\n private _text(text: string): Text | string {\r\n if (!this._hasAttribute()) {\r\n return text;\r\n }\r\n const t: Text = {\r\n text,\r\n };\r\n\r\n if (this._poem !== null) {\r\n t.poem = this._poem;\r\n }\r\n\r\n if (this._wordsOfJesus) {\r\n t.wordsOfJesus = true;\r\n }\r\n\r\n return t;\r\n }\r\n\r\n private _throwError(\r\n source: string,\r\n token: Token | null,\r\n message: string,\r\n warn: boolean = false\r\n ): void {\r\n const logger = getLogger();\r\n if (token) {\r\n let line = 1;\r\n let column = 1;\r\n\r\n let start = token.loc.start;\r\n\r\n for (let i = 0; i < start; i++) {\r\n let char = source[i];\r\n if (char === '\\n') {\r\n line += 1;\r\n column = 1;\r\n } else {\r\n column += 1;\r\n }\r\n }\r\n\r\n let tokenDebug = '';\r\n if (token.kind === 'word') {\r\n tokenDebug = ', word';\r\n } else if (token.kind === 'marker') {\r\n tokenDebug = ', ' + token.command;\r\n } else {\r\n tokenDebug = '';\r\n }\r\n\r\n if (warn) {\r\n logger.warn(`(${line}, ${column}${tokenDebug}) ${message}`);\r\n } else {\r\n throw new Error(`(${line}, ${column}${tokenDebug}) ${message}`);\r\n }\r\n } else {\r\n if (warn) {\r\n logger.warn(message);\r\n } else {\r\n throw new Error(message);\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Determines if the given character is a digit.\r\n * @param char The character.\r\n */\r\nexport function isDigit(char: string): boolean {\r\n return char.length === 1 && char >= '0' && char <= '9';\r\n}\r\n\r\n/**\r\n * Determines if the given character is considered whitespace.\r\n * @param char The character.\r\n */\r\nexport function isWhitespace(char: string): boolean {\r\n return char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\r\n}\r\n\r\nexport function t(loc: SourceLocation, kind: T): SimpleToken {\r\n return {\r\n loc,\r\n kind,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new source location.\r\n * @param start The start of the location.\r\n * @param end The end of the location.\r\n */\r\nexport function loc(start: number, end: number): SourceLocation {\r\n return {\r\n start,\r\n end,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new marker token.\r\n * @param loc The location for the token.\r\n * @param command The command that the token contains.\r\n * @param number The number that the marker contains.\r\n * @param type The type of the marker.\r\n */\r\nexport function marker(\r\n loc: SourceLocation,\r\n command: string,\r\n number: number | null = null,\r\n type: MarkerToken['type'] = 'start'\r\n): MarkerToken {\r\n return {\r\n kind: 'marker',\r\n loc,\r\n command,\r\n number,\r\n type,\r\n };\r\n}\r\n\r\n/**\r\n * Creates a new word token.\r\n * @param loc The location for the token.\r\n * @param word The word contained by the token.\r\n */\r\nexport function word(loc: SourceLocation, word: string): WordToken {\r\n return {\r\n kind: 'word',\r\n loc,\r\n word,\r\n };\r\n}\r\n\r\nexport function whitespace(\r\n loc: SourceLocation,\r\n whitespace: string\r\n): WhitespaceToken {\r\n return {\r\n kind: 'whitespace',\r\n loc,\r\n whitespace,\r\n };\r\n}\r\n\r\nexport type T = Token['kind'];\r\n\r\n/**\r\n * Defines a simple token.\r\n */\r\nexport interface SimpleToken {\r\n kind: T;\r\n loc: SourceLocation;\r\n}\r\n\r\nexport type Token = MarkerToken | WordToken | WhitespaceToken;\r\n\r\n/**\r\n * Defines an interface for a USFM marker node.\r\n * That is, the syntax for a marker.\r\n */\r\nexport interface MarkerToken {\r\n kind: 'marker';\r\n\r\n /**\r\n * The command that the marker represents.\r\n * This is generally the name of the marker (like \"p\" or \"v\" for paragraph and verse markers)\r\n */\r\n command: string;\r\n\r\n /**\r\n * The number that the marker contains.\r\n * Null if no number was specified.\r\n */\r\n number: number | null;\r\n\r\n /**\r\n * Whether the marker represents a start or an end.\r\n */\r\n type: 'start' | 'end';\r\n\r\n /**\r\n * The location of the node.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * Defines an interface for a Whitespace node.\r\n */\r\nexport interface WhitespaceToken {\r\n kind: 'whitespace';\r\n\r\n /**\r\n * The whitespace contained by the node.\r\n */\r\n whitespace: string;\r\n\r\n /**\r\n * The location of the node.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * Defines an interface for a word token.\r\n */\r\nexport interface WordToken {\r\n kind: 'word';\r\n\r\n /**\r\n * The word contained by the token.\r\n */\r\n word: string;\r\n\r\n /**\r\n * The location of the word.\r\n */\r\n loc: SourceLocation;\r\n}\r\n\r\n/**\r\n * The source location of the node.\r\n */\r\nexport interface SourceLocation {\r\n start: number;\r\n end: number;\r\n}\r\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AAUzB,iBAA0B;AAKnB,MAAM,cAAc;AAAA,EACf,SAAiB;AAAA,EACjB,SAAiB;AAAA,EACjB,SAAiB;AAAA,EAEzB,IAAY,eAAe;AACvB,WAAO,KAAK,SAAS,KAAK;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS,OAA8B;AACnC,SAAK,SAAS;AACd,SAAK,SAAS;AAEd,WAAO,KAAK,aAAa;AAAA,EAC7B;AAAA,EAEQ,eAAe;AACnB,QAAI,SAAwB,CAAC;AAC7B,QAAI,QAAQ,KAAK,YAAY;AAC7B,WAAO,OAAO;AACV,aAAO,KAAK,KAAK;AACjB,cAAQ,KAAK,YAAY;AAAA,IAC7B;AAEA,WAAO;AAAA,EACX;AAAA,EAEQ,cAAkC;AACtC,QAAI,QAKW;AACf,QAAI,OAAiB;AACrB,SAAK,SAAS,KAAK;AAEnB,WAAO,KAAK,SAAS,KAAK,OAAO,QAAQ;AACrC,YAAM,kBAAkB,KAAK,OAAO,YAAY,KAAK,MAAM;AAE3D,UAA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