@helloao/tools 0.0.5 → 0.0.6-alpha

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.
Files changed (107) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +98 -98
  3. package/dist/cjs/generation/api.cjs +240 -0
  4. package/dist/cjs/generation/api.cjs.map +7 -0
  5. package/dist/cjs/generation/audio.cjs +83 -0
  6. package/dist/cjs/generation/audio.cjs.map +7 -0
  7. package/dist/cjs/generation/book-order.cjs +508 -0
  8. package/dist/cjs/generation/book-order.cjs.map +7 -0
  9. package/dist/cjs/generation/common-types.cjs +17 -0
  10. package/dist/cjs/generation/common-types.cjs.map +7 -0
  11. package/dist/cjs/generation/dataset.cjs +158 -0
  12. package/dist/cjs/generation/dataset.cjs.map +7 -0
  13. package/dist/cjs/generation/index.cjs +51 -0
  14. package/dist/cjs/generation/index.cjs.map +7 -0
  15. package/dist/cjs/index.cjs +45 -0
  16. package/dist/cjs/index.cjs.map +7 -0
  17. package/dist/cjs/parser/codex-parser.cjs +176 -0
  18. package/dist/cjs/parser/codex-parser.cjs.map +7 -0
  19. package/dist/cjs/parser/index.cjs +48 -0
  20. package/dist/cjs/parser/index.cjs.map +7 -0
  21. package/dist/cjs/parser/iterators.cjs +204 -0
  22. package/dist/cjs/parser/iterators.cjs.map +7 -0
  23. package/dist/cjs/parser/types.cjs +17 -0
  24. package/dist/cjs/parser/types.cjs.map +7 -0
  25. package/dist/cjs/parser/usfm-parser.cjs +791 -0
  26. package/dist/cjs/parser/usfm-parser.cjs.map +7 -0
  27. package/dist/cjs/parser/usx-parser.cjs +471 -0
  28. package/dist/cjs/parser/usx-parser.cjs.map +7 -0
  29. package/dist/cjs/utils.cjs +85 -0
  30. package/dist/cjs/utils.cjs.map +7 -0
  31. package/dist/esm/generation/api.js +198 -0
  32. package/dist/esm/generation/api.js.map +7 -0
  33. package/dist/esm/generation/audio.js +53 -0
  34. package/dist/esm/generation/audio.js.map +7 -0
  35. package/dist/esm/generation/book-order.js +478 -0
  36. package/dist/esm/generation/book-order.js.map +7 -0
  37. package/dist/esm/generation/common-types.js +2 -0
  38. package/dist/esm/generation/common-types.js.map +7 -0
  39. package/dist/esm/generation/dataset.js +132 -0
  40. package/dist/esm/generation/dataset.js.map +7 -0
  41. package/dist/esm/generation/index.js +8 -0
  42. package/dist/esm/generation/index.js.map +7 -0
  43. package/dist/esm/index.js +6 -0
  44. package/dist/esm/index.js.map +7 -0
  45. package/dist/esm/parser/codex-parser.js +144 -0
  46. package/dist/esm/parser/codex-parser.js.map +7 -0
  47. package/dist/esm/parser/index.js +8 -0
  48. package/dist/esm/parser/index.js.map +7 -0
  49. package/dist/esm/parser/iterators.js +152 -0
  50. package/dist/esm/parser/iterators.js.map +7 -0
  51. package/dist/esm/parser/types.js +2 -0
  52. package/dist/esm/parser/types.js.map +7 -0
  53. package/dist/esm/parser/usfm-parser.js +749 -0
  54. package/dist/esm/parser/usfm-parser.js.map +7 -0
  55. package/dist/esm/parser/usx-parser.js +447 -0
  56. package/dist/esm/parser/usx-parser.js.map +7 -0
  57. package/dist/esm/utils.js +51 -0
  58. package/dist/esm/utils.js.map +7 -0
  59. package/{generation → dist/types/generation}/api.d.ts +14 -2
  60. package/{generation → dist/types/generation}/audio.d.ts +1 -1
  61. package/{generation → dist/types/generation}/dataset.d.ts +1 -1
  62. package/dist/types/generation/index.d.ts +7 -0
  63. package/dist/types/index.d.ts +5 -0
  64. package/{parser → dist/types/parser}/codex-parser.d.ts +1 -1
  65. package/dist/types/parser/index.d.ts +7 -0
  66. package/{parser → dist/types/parser}/usfm-parser.d.ts +1 -1
  67. package/{parser → dist/types/parser}/usx-parser.d.ts +2 -2
  68. package/package.json +25 -4
  69. package/typings/types.d.ts +13 -13
  70. package/generation/api.js +0 -179
  71. package/generation/api.spec.d.ts +0 -2
  72. package/generation/api.spec.js +0 -656
  73. package/generation/audio.js +0 -60
  74. package/generation/audio.spec.d.ts +0 -2
  75. package/generation/audio.spec.js +0 -36
  76. package/generation/book-order.js +0 -494
  77. package/generation/book-order.spec.d.ts +0 -2
  78. package/generation/book-order.spec.js +0 -8
  79. package/generation/common-types.js +0 -2
  80. package/generation/dataset.js +0 -106
  81. package/generation/index.d.ts +0 -7
  82. package/generation/index.js +0 -38
  83. package/index.d.ts +0 -5
  84. package/index.js +0 -32
  85. package/parser/codex-parser.js +0 -160
  86. package/parser/codex-parser.spec.d.ts +0 -2
  87. package/parser/codex-parser.spec.js +0 -645
  88. package/parser/index.d.ts +0 -7
  89. package/parser/index.js +0 -35
  90. package/parser/iterators.js +0 -222
  91. package/parser/iterators.spec.d.ts +0 -2
  92. package/parser/iterators.spec.js +0 -174
  93. package/parser/types.js +0 -2
  94. package/parser/usfm-parser.js +0 -840
  95. package/parser/usfm-parser.spec.d.ts +0 -2
  96. package/parser/usfm-parser.spec.js +0 -1593
  97. package/parser/usx-parser.js +0 -425
  98. package/parser/usx-parser.spec.d.ts +0 -2
  99. package/parser/usx-parser.spec.js +0 -1260
  100. package/utils.js +0 -73
  101. package/utils.spec.d.ts +0 -2
  102. package/utils.spec.js +0 -42
  103. /package/{generation → dist/types/generation}/book-order.d.ts +0 -0
  104. /package/{generation → dist/types/generation}/common-types.d.ts +0 -0
  105. /package/{parser → dist/types/parser}/iterators.d.ts +0 -0
  106. /package/{parser → dist/types/parser}/types.d.ts +0 -0
  107. /package/{utils.d.ts → dist/types/utils.d.ts} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../parser/usfm-parser.ts"],
4
+ "sourcesContent": ["import { findLast } from 'lodash';\nimport {\n ParseTree,\n Chapter,\n Verse,\n HebrewSubtitle,\n FootnoteReference,\n Footnote,\n Text,\n} from './types.js';\n\n/**\n * Defines a class that can tokenize a stream of characters into tokens.\n */\nexport class UsfmTokenizer {\n private _input: string = '';\n private _index: number = 0;\n private _start: number = 0;\n\n private get _tokenLength() {\n return this._index - this._start;\n }\n\n /**\n * Converts the given input into a list of tokens.\n * @param input The input that should be tokenized.\n */\n tokenize(input: string): SimpleToken[] {\n this._input = input;\n this._index = 0;\n\n return this._parseTokens();\n }\n\n private _parseTokens() {\n let tokens: SimpleToken[] = [];\n let token = this._parseToken();\n while (token) {\n tokens.push(token);\n token = this._parseToken();\n }\n\n return tokens;\n }\n\n private _parseToken(): SimpleToken | null {\n let state:\n | 'none'\n | 'marker_start'\n | 'marker_number'\n | 'whitespace'\n | 'word' = 'none';\n let kind: T | null = null;\n this._start = this._index;\n\n while (this._index < this._input.length) {\n const codePointNumber = this._input.codePointAt(this._index);\n\n if (typeof codePointNumber === 'undefined') {\n throw new Error('Unable to get code point!');\n }\n\n const codePoint = String.fromCodePoint(codePointNumber);\n\n if (state === 'none') {\n if (codePoint === '\\\\') {\n state = 'marker_start';\n } else if (isWhitespace(codePoint)) {\n state = 'whitespace';\n } else {\n state = 'word';\n }\n } else if (state === 'marker_start') {\n if (isDigit(codePoint)) {\n if (this._tokenLength === 0) {\n throw new Error(\n 'Invalid Marker: Markers must not contain only digits.'\n );\n }\n state = 'marker_number';\n } else if (codePoint === '*') {\n this._index += codePoint.length;\n kind = 'marker';\n break;\n } else if (isWhitespace(codePoint)) {\n kind = 'marker';\n break;\n }\n } else if (state === 'marker_number') {\n if (codePoint === '*') {\n this._index += codePoint.length;\n kind = 'marker';\n break;\n } else if (!isDigit(codePoint)) {\n kind = 'marker';\n break;\n }\n } else if (state === 'whitespace') {\n if (!isWhitespace(codePoint)) {\n kind = 'whitespace';\n break;\n }\n } else if (state === 'word') {\n if (isWhitespace(codePoint) || codePoint === '\\\\') {\n kind = 'word';\n break;\n }\n }\n\n this._index += codePoint.length;\n }\n\n if (!kind) {\n if (this._index >= this._input.length) {\n if (state == 'marker_start' || state === 'marker_number') {\n kind = 'marker';\n } else if (state === 'word') {\n kind = 'word';\n } else if (state === 'whitespace') {\n kind = 'whitespace';\n }\n }\n }\n\n if (kind) {\n return t(loc(this._start, this._index), kind);\n }\n\n return null;\n }\n}\n\nexport interface UsfmParseOptions {\n paragraphs: Set<string>;\n}\n\n/**\n * Defines a USFM Parser.\n */\nexport class UsfmParser {\n private _poem: number | null = null;\n private _wordsOfJesus: boolean = false;\n\n tokenize(input: string): Token[] {\n const simpleTokens = new UsfmTokenizer().tokenize(input);\n let tokens: Token[] = [];\n\n for (let t of simpleTokens) {\n if (t.kind === 'marker') {\n let source = input.substring(t.loc.start, t.loc.end);\n const isEnd = source.endsWith('*');\n\n if (isEnd) {\n source = source.substring(0, source.length - 1);\n }\n\n let numberIndex = -1;\n for (let i = 0; i < source.length; i++) {\n if (isDigit(source[i])) {\n numberIndex = i;\n break;\n }\n }\n\n let number: number | null = null;\n if (numberIndex === 1) {\n throw new Error(\n 'Markers must not be made only of numbers!'\n );\n }\n if (numberIndex > 0) {\n number = parseInt(source.substring(numberIndex));\n source = source.substring(0, numberIndex);\n }\n\n if (source.length === 1) {\n if (isEnd) {\n // Ending marker does not have a command.\n // We should look for a matching start marker.\n const startMarker = findLast(\n tokens,\n (t) => t.kind === 'marker' && t.type === 'start'\n ) as MarkerToken;\n if (startMarker) {\n source = startMarker.command;\n }\n }\n\n if (source.length === 1) {\n throw new Error(\n `Markers must have a command! Token: ${t.loc.start}-${t.loc.end}`\n );\n }\n }\n\n tokens.push(\n marker(t.loc, source, number, isEnd ? 'end' : 'start')\n );\n } else if (t.kind === 'whitespace') {\n let source = input.substring(t.loc.start, t.loc.end);\n tokens.push(whitespace(t.loc, source));\n } else if (t.kind === 'word') {\n let source = input.substring(t.loc.start, t.loc.end);\n tokens.push(word(t.loc, source));\n }\n }\n\n return tokens;\n }\n\n parse(input: string): ParseTree {\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n const tokens = this.tokenize(input);\n\n let expectingId = 0;\n let expectingName = 0;\n let expectingTitle = 0;\n let expectingSectionHeading = 0;\n let expectingFootnote = 0;\n let expectingFootnoteReference = 0;\n let expectingFootnoteText = 0;\n let expectingReferenceText = 0;\n let expectingWordAttribute = 0;\n let expectingNestedWordAttribute = 0;\n let expectingWordsOfJesus = 0;\n let expectingIntroParagraph = 0;\n let expectingCrossReference = 0;\n let expectingUnknownCommand = 0;\n\n let canParseFootnotes = true;\n let chapter: Chapter | null = null;\n let lastVerse: Verse | null = null;\n let verse: Verse | null = null;\n let subtitle: HebrewSubtitle | null = null;\n let words: string[] = [];\n let verseContent: (Text | FootnoteReference | string)[] = [];\n let sectionContent: string = '';\n let currentFootnoteId = 0;\n let footnote: Footnote | null = null;\n\n this._poem = null;\n\n const addWordsToVerseOrSubtitle = () => {\n if (words.length > 0) {\n const text = this._text(words.join('').trimEnd());\n if (verse) {\n verse.content.push(text);\n } else if (subtitle) {\n subtitle.content.push(text);\n } else {\n verseContent.push(text);\n }\n words = [];\n }\n };\n\n const addVerseContentToChapter = (token: Token | null) => {\n if (!chapter) {\n return;\n }\n if (verseContent.length > 0) {\n if (chapter.content.some((c) => c.type === 'verse')) {\n this._throwError(\n input,\n token,\n 'Cannot infer first verse after other verses have been added to the chapter!'\n );\n }\n // Implicit first verse\n verse = {\n type: 'verse',\n number: 1,\n content: verseContent,\n };\n chapter.content.push(verse);\n verseContent = [];\n }\n };\n\n const cleanupVerse = () => {\n if (!verse || !chapter) {\n return;\n }\n let chapterContent: Chapter['content'] = [];\n for (let i = verse.content.length - 1; i >= 0; i--) {\n let content = verse.content[i];\n if (typeof content === 'object' && 'heading' in content) {\n // move headings that occur at the end of a verse to the chapter\n chapterContent.unshift({\n type: 'heading',\n content: [content.heading],\n });\n verse.content.splice(i, 1);\n } else if (\n typeof content === 'object' &&\n 'lineBreak' in content &&\n content.lineBreak\n ) {\n // move line breaks that occur at the end of a verse to the chapter\n chapterContent.unshift({\n type: 'line_break',\n });\n verse.content.splice(i, 1);\n } else {\n break;\n }\n }\n\n for (let content of chapterContent) {\n chapter.content.push(content);\n }\n };\n\n const completeVerseOrSubtitle = (token: Token | null) => {\n if (verse && isNaN(verse.number)) {\n // Verse is invalid for some reason.\n const index = chapter!.content.indexOf(verse);\n if (index >= 0) {\n chapter!.content.splice(index, 1);\n }\n verse = null;\n }\n if (verse || subtitle) {\n addWordsToVerseOrSubtitle();\n }\n\n addVerseContentToChapter(token);\n cleanupVerse();\n };\n\n const completeSection = () => {\n if (expectingSectionHeading > 0) {\n if (verse) {\n addWordsToVerseOrSubtitle();\n verse.content.push({\n heading: sectionContent,\n });\n } else if (chapter) {\n chapter.content.push({\n type: 'heading',\n content: [sectionContent],\n });\n } else {\n root.content.push({\n type: 'heading',\n content: [sectionContent],\n });\n }\n sectionContent = '';\n expectingSectionHeading = 0;\n }\n };\n\n const addWordsToFootnote = () => {\n if (footnote && words.length > 0) {\n footnote.text += words.join(' ');\n words = [];\n }\n };\n\n for (let token of tokens) {\n if (token.kind === 'marker') {\n if (token.command === '\\\\c') {\n addWordsToVerseOrSubtitle();\n cleanupVerse();\n\n chapter = {\n type: 'chapter',\n number: NaN,\n content: [],\n footnotes: [],\n };\n verse = null;\n verseContent = [];\n\n root.content.push(chapter);\n } else if (token.command === '\\\\v') {\n if (!chapter) {\n this._throwError(\n input,\n token,\n 'Cannot parse a verse without chapter information!'\n );\n } else {\n completeSection();\n completeVerseOrSubtitle(token);\n\n lastVerse = verse;\n verse = {\n type: 'verse',\n number: NaN,\n content: [],\n };\n\n chapter.content.push(verse);\n }\n } else if (token.command === '\\\\d') {\n if (!chapter) {\n this._throwError(\n input,\n token,\n 'Cannot parse a hebrew subtitle without chapter information!'\n );\n } else {\n completeVerseOrSubtitle(token);\n\n subtitle = {\n type: 'hebrew_subtitle',\n content: [],\n };\n\n chapter.content.push(subtitle);\n }\n } else if (token.command === '\\\\b' || token.command === '\\\\p') {\n if (!chapter) {\n this._throwError(\n input,\n token,\n 'Cannot parse a line break without chapter information!'\n );\n } else {\n if (verse) {\n addWordsToVerseOrSubtitle();\n verse.content.push({\n lineBreak: true,\n });\n } else {\n completeVerseOrSubtitle(token);\n chapter.content.push({\n type: 'line_break',\n });\n }\n }\n } else if (token.command === '\\\\q') {\n addWordsToVerseOrSubtitle();\n this._poem = token.number;\n } else if (token.command === '\\\\p') {\n addWordsToVerseOrSubtitle();\n this._poem = null;\n } else if (token.command === '\\\\id') {\n expectingId = 1;\n } else if (token.command === '\\\\h') {\n expectingName = 1;\n root.header = undefined;\n } else if (\n token.command === '\\\\mt' ||\n token.command === '\\\\+mt'\n ) {\n expectingTitle = 1;\n } else if (token.command === '\\\\s') {\n expectingSectionHeading = 1;\n } else if (token.command === '\\\\r') {\n expectingReferenceText = 1;\n } else if (token.command === '\\\\f' && canParseFootnotes) {\n if (token.type === 'start') {\n if (!chapter) {\n this._throwError(\n input,\n token,\n 'Cannot start a footnote outside of a chapter!',\n true\n );\n } else {\n addWordsToVerseOrSubtitle();\n footnote = {\n noteId: currentFootnoteId,\n text: '',\n caller: null,\n };\n const ref: FootnoteReference = {\n noteId: footnote.noteId,\n };\n expectingFootnote = 1;\n\n chapter.footnotes.push(footnote);\n\n if (verse) {\n verse.content.push(ref);\n } else if (subtitle) {\n subtitle.content.push(ref);\n } else {\n verseContent.push(ref);\n }\n\n currentFootnoteId += 1;\n }\n } else {\n addWordsToFootnote();\n expectingFootnote = 0;\n expectingFootnoteText = 0;\n expectingFootnoteReference = 0;\n footnote = null;\n }\n } else if (token.command === '\\\\fr' && canParseFootnotes) {\n if (!footnote) {\n this._throwError(\n input,\n token,\n 'Cannot start a footnote reference outside of a footnote!',\n true\n );\n } else {\n expectingFootnoteReference = 1;\n }\n } else if (token.command === '\\\\ft' && canParseFootnotes) {\n if (!footnote) {\n this._throwError(\n input,\n token,\n 'Cannot start footnote text outside of a footnote!',\n true\n );\n } else {\n expectingFootnoteText = 1;\n }\n } else if (token.command === '\\\\w') {\n if (token.type === 'start') {\n expectingWordAttribute = 1;\n } else {\n expectingWordAttribute = 0;\n }\n } else if (token.command === '\\\\+w') {\n if (token.type === 'start') {\n expectingNestedWordAttribute = 1;\n } else {\n expectingNestedWordAttribute = 0;\n }\n } else if (\n token.command === '\\\\wj' ||\n token.command === '\\\\+wj'\n ) {\n if (token.type === 'start') {\n addWordsToVerseOrSubtitle();\n this._wordsOfJesus = true;\n } else {\n addWordsToVerseOrSubtitle();\n this._wordsOfJesus = false;\n }\n } else if (token.command === '\\\\ip') {\n expectingIntroParagraph = 1;\n canParseFootnotes = false;\n } else if (token.command === '\\\\x') {\n if (token.type === 'start') {\n expectingCrossReference = 1;\n } else {\n expectingCrossReference = 0;\n }\n } else if (token.command.indexOf('-') >= 0) {\n if (token.type === 'start') {\n expectingUnknownCommand = 1;\n }\n } else if (token.type === 'end') {\n expectingUnknownCommand = 0;\n }\n } else if (token.kind === 'word') {\n if (expectingId > 0) {\n if (expectingId === 1) {\n root.id = token.word;\n expectingId = 2;\n }\n } else if (expectingName > 0) {\n if (root.header) {\n root.header += ' ' + token.word;\n } else {\n root.header = token.word;\n }\n } else if (expectingTitle > 0) {\n if (root.title) {\n root.title += ' ' + token.word;\n } else {\n root.title = token.word;\n }\n } else if (expectingSectionHeading > 0) {\n if (sectionContent) {\n sectionContent += ' ' + token.word;\n } else {\n sectionContent = token.word;\n }\n } else if (expectingFootnoteReference > 0) {\n if ((expectingFootnoteReference = 1)) {\n const [chapter, verse] = token.word.split(/[\\.\\:]/);\n\n if (footnote) {\n footnote.reference = {\n chapter: parseInt(chapter),\n verse: parseInt(verse),\n };\n }\n\n expectingFootnoteReference = 0;\n }\n } else if (expectingFootnoteText > 0) {\n words.push(token.word);\n } else if (expectingFootnote > 0) {\n if (expectingFootnote === 1) {\n if (token.word) {\n if (footnote) {\n if (token.word === '+' || token.word !== '-') {\n footnote.caller = token.word;\n } else {\n footnote.caller = null;\n }\n }\n // this._throwError(input, token, 'Footnotes must use the \"+\" caller.');\n }\n expectingFootnote = 2;\n } else {\n words.push(token.word);\n }\n } else if (expectingReferenceText > 0) {\n // Skip processing words for references\n // because references aren't included in the JSON format\n // (for now)\n } else if (expectingCrossReference > 0) {\n // Skip processing words for cross references\n } else if (chapter && isNaN(chapter.number)) {\n chapter.number = parseInt(token.word);\n if (isNaN(chapter.number)) {\n this._throwError(\n input,\n token,\n 'The first word token after a chapter marker must be parsable to an integer!'\n );\n }\n } else if (verse && isNaN(verse.number)) {\n verse.number = parseInt(token.word);\n if (isNaN(verse.number)) {\n this._throwError(\n input,\n token,\n 'The first word token after a verse marker must be parsable to an integer!'\n );\n }\n } else if (expectingWordAttribute > 0) {\n if (expectingWordAttribute === 1) {\n const firstVerticalBarIndex = token.word.indexOf('|');\n\n if (firstVerticalBarIndex >= 0) {\n const name = token.word.slice(\n 0,\n firstVerticalBarIndex\n );\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\n words.push(name);\n expectingWordAttribute = 2;\n } else {\n words.push(token.word);\n }\n }\n } else if (expectingNestedWordAttribute > 0) {\n if (expectingNestedWordAttribute === 1) {\n const firstVerticalBarIndex = token.word.indexOf('|');\n\n if (firstVerticalBarIndex >= 0) {\n const name = token.word.slice(\n 0,\n firstVerticalBarIndex\n );\n // const rest = token.word.slice(firstVerticalBarIndex + '|'.length);\n words.push(name);\n expectingNestedWordAttribute = 2;\n } else {\n words.push(token.word);\n }\n }\n } else if (expectingUnknownCommand > 0) {\n } else if (expectingIntroParagraph > 0) {\n // Skip processing words for intro paragraphs\n } else {\n words.push(token.word);\n }\n } else if (token.kind === 'whitespace') {\n if (expectingId > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingId = 0;\n }\n } else if (expectingName > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingName = 0;\n }\n } else if (expectingTitle > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingTitle = 0;\n }\n } else if (expectingSectionHeading > 0) {\n if (token.whitespace.includes('\\n')) {\n completeSection();\n }\n } else if (expectingReferenceText > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingReferenceText = 0;\n }\n } else if (expectingIntroParagraph > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingIntroParagraph = 0;\n canParseFootnotes = true;\n }\n } else if (\n expectingId > 0 ||\n expectingName > 0 ||\n expectingTitle > 0 ||\n expectingSectionHeading > 0 ||\n expectingFootnote > 0 ||\n expectingFootnoteReference > 0 ||\n expectingFootnoteText > 0 ||\n expectingReferenceText > 0 ||\n expectingCrossReference > 0 ||\n expectingWordAttribute > 0 ||\n expectingNestedWordAttribute > 0\n ) {\n // Skip\n } else if (expectingUnknownCommand > 0) {\n if (token.whitespace.includes('\\n')) {\n expectingUnknownCommand = 0;\n }\n } else if (words.length > 0) {\n let lastWord = words[words.length - 1];\n if (lastWord !== ' ') {\n words.push(' ');\n }\n }\n }\n }\n\n completeVerseOrSubtitle(null);\n\n return root;\n }\n\n renderMarkdown(tree: ParseTree): string {\n let md = '';\n\n if (tree.header) {\n md += `# ${tree.header}\\n`;\n }\n\n for (let c of tree.content) {\n if (c.type === 'heading') {\n md += `## ${c.content.join(' ')}\\n`;\n } else if (c.type === 'chapter') {\n md += `### ${c.number}\\n`;\n\n for (let content of c.content) {\n if (content.type === 'heading') {\n md += `#### ${content.content.join(' ')}\\n`;\n } else if (content.type === 'line_break') {\n md += '\\n\\n';\n } else if (content.type === 'verse') {\n md += `<em>${content.number}</em>`;\n for (let v of content.content) {\n if (typeof v === 'string') {\n md += v + ' ';\n } else if ('text' in v) {\n md += v.text + ' ';\n }\n }\n md += '\\n';\n }\n }\n }\n }\n\n return md;\n }\n\n private _hasAttribute() {\n return this._poem !== null || this._wordsOfJesus;\n }\n\n private _text(text: string): Text | string {\n if (!this._hasAttribute()) {\n return text;\n }\n const t: Text = {\n text,\n };\n\n if (this._poem !== null) {\n t.poem = this._poem;\n }\n\n if (this._wordsOfJesus) {\n t.wordsOfJesus = true;\n }\n\n return t;\n }\n\n private _throwError(\n source: string,\n token: Token | null,\n message: string,\n warn: boolean = false\n ): void {\n if (token) {\n let line = 1;\n let column = 1;\n\n let start = token.loc.start;\n\n for (let i = 0; i < start; i++) {\n let char = source[i];\n if (char === '\\n') {\n line += 1;\n column = 1;\n } else {\n column += 1;\n }\n }\n\n let tokenDebug = '';\n if (token.kind === 'word') {\n tokenDebug = ', word';\n } else if (token.kind === 'marker') {\n tokenDebug = ', ' + token.command;\n } else {\n tokenDebug = '';\n }\n\n if (warn) {\n console.warn(`(${line}, ${column}${tokenDebug}) ${message}`);\n } else {\n throw new Error(`(${line}, ${column}${tokenDebug}) ${message}`);\n }\n } else {\n if (warn) {\n console.warn(message);\n } else {\n throw new Error(message);\n }\n }\n }\n}\n\n/**\n * Determines if the given character is a digit.\n * @param char The character.\n */\nexport function isDigit(char: string): boolean {\n return char.length === 1 && char >= '0' && char <= '9';\n}\n\n/**\n * Determines if the given character is considered whitespace.\n * @param char The character.\n */\nexport function isWhitespace(char: string): boolean {\n return char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\n}\n\nexport function t(loc: SourceLocation, kind: T): SimpleToken {\n return {\n loc,\n kind,\n };\n}\n\n/**\n * Creates a new source location.\n * @param start The start of the location.\n * @param end The end of the location.\n */\nexport function loc(start: number, end: number): SourceLocation {\n return {\n start,\n end,\n };\n}\n\n/**\n * Creates a new marker token.\n * @param loc The location for the token.\n * @param command The command that the token contains.\n * @param number The number that the marker contains.\n * @param type The type of the marker.\n */\nexport function marker(\n loc: SourceLocation,\n command: string,\n number: number | null = null,\n type: MarkerToken['type'] = 'start'\n): MarkerToken {\n return {\n kind: 'marker',\n loc,\n command,\n number,\n type,\n };\n}\n\n/**\n * Creates a new word token.\n * @param loc The location for the token.\n * @param word The word contained by the token.\n */\nexport function word(loc: SourceLocation, word: string): WordToken {\n return {\n kind: 'word',\n loc,\n word,\n };\n}\n\nexport function whitespace(\n loc: SourceLocation,\n whitespace: string\n): WhitespaceToken {\n return {\n kind: 'whitespace',\n loc,\n whitespace,\n };\n}\n\nexport type T = Token['kind'];\n\n/**\n * Defines a simple token.\n */\nexport interface SimpleToken {\n kind: T;\n loc: SourceLocation;\n}\n\nexport type Token = MarkerToken | WordToken | WhitespaceToken;\n\n/**\n * Defines an interface for a USFM marker node.\n * That is, the syntax for a marker.\n */\nexport interface MarkerToken {\n kind: 'marker';\n\n /**\n * The command that the marker represents.\n * This is generally the name of the marker (like \"p\" or \"v\" for paragraph and verse markers)\n */\n command: string;\n\n /**\n * The number that the marker contains.\n * Null if no number was specified.\n */\n number: number | null;\n\n /**\n * Whether the marker represents a start or an end.\n */\n type: 'start' | 'end';\n\n /**\n * The location of the node.\n */\n loc: SourceLocation;\n}\n\n/**\n * Defines an interface for a Whitespace node.\n */\nexport interface WhitespaceToken {\n kind: 'whitespace';\n\n /**\n * The whitespace contained by the node.\n */\n whitespace: string;\n\n /**\n * The location of the node.\n */\n loc: SourceLocation;\n}\n\n/**\n * Defines an interface for a word token.\n */\nexport interface WordToken {\n kind: 'word';\n\n /**\n * The word contained by the token.\n */\n word: string;\n\n /**\n * The location of the word.\n */\n loc: SourceLocation;\n}\n\n/**\n * The source location of the node.\n */\nexport interface SourceLocation {\n start: number;\n end: number;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AAclB,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,SAA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,OAAO,EAAE;AAAA,MAC/D,OAAO;AACH,cAAM,IAAI,MAAM,IAAI,IAAI,KAAK,MAAM,GAAG,UAAU,KAAK,OAAO,EAAE;AAAA,MAClE;AAAA,IACJ,OAAO;AACH,UAAI,MAAM;AACN,gBAAQ,KAAK,OAAO;AAAA,MACxB,OAAO;AACH,cAAM,IAAI,MAAM,OAAO;AAAA,MAC3B;AAAA,IACJ;AAAA,EACJ;AACJ;AAMO,SAAS,QAAQ,MAAuB;AAC3C,SAAO,KAAK,WAAW,KAAK,QAAQ,OAAO,QAAQ;AACvD;AAMO,SAAS,aAAa,MAAuB;AAChD,SAAO,SAAS,OAAO,SAAS,OAAQ,SAAS,QAAQ,SAAS;AACtE;AAEO,SAAS,EAAEG,MAAqB,MAAsB;AACzD,SAAO;AAAA,IACH,KAAAA;AAAA,IACA;AAAA,EACJ;AACJ;AAOO,SAAS,IAAI,OAAe,KAA6B;AAC5D,SAAO;AAAA,IACH;AAAA,IACA;AAAA,EACJ;AACJ;AASO,SAAS,OACZA,MACA,SACA,SAAwB,MACxB,OAA4B,SACjB;AACX,SAAO;AAAA,IACH,MAAM;AAAA,IACN,KAAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;AAOO,SAAS,KAAKA,MAAqBC,OAAyB;AAC/D,SAAO;AAAA,IACH,MAAM;AAAA,IACN,KAAAD;AAAA,IACA,MAAAC;AAAA,EACJ;AACJ;AAEO,SAAS,WACZD,MACAE,aACe;AACf,SAAO;AAAA,IACH,MAAM;AAAA,IACN,KAAAF;AAAA,IACA,YAAAE;AAAA,EACJ;AACJ;",
6
+ "names": ["t", "chapter", "verse", "loc", "word", "whitespace"]
7
+ }
@@ -0,0 +1,471 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var usx_parser_exports = {};
20
+ __export(usx_parser_exports, {
21
+ PARSER_VERSION: () => PARSER_VERSION,
22
+ USXParser: () => USXParser
23
+ });
24
+ module.exports = __toCommonJS(usx_parser_exports);
25
+ var import_iterators = require("./iterators.js");
26
+ var NodeType = /* @__PURE__ */ ((NodeType2) => {
27
+ NodeType2[NodeType2["Text"] = 3] = "Text";
28
+ return NodeType2;
29
+ })(NodeType || {});
30
+ const PARSER_VERSION = "1";
31
+ class USXParser {
32
+ _domParser;
33
+ _noteCounter = 0;
34
+ constructor(domParser) {
35
+ this._domParser = domParser;
36
+ }
37
+ /**
38
+ * Parses the specified USX content.
39
+ *
40
+ * @param usx The USX content to parse.
41
+ * @returns The parse tree that was generated.
42
+ */
43
+ parse(usx) {
44
+ const parser = this._domParser;
45
+ const doc = parser.parseFromString(usx, "application/xml");
46
+ const usxElement = doc.documentElement;
47
+ let root = {
48
+ type: "root",
49
+ content: []
50
+ };
51
+ const bookElement = usxElement.querySelector("book[code]");
52
+ if (!bookElement) {
53
+ throw new Error("The USX content does not contain a book element.");
54
+ }
55
+ const bookCode = bookElement.getAttribute("code") || "";
56
+ if (!bookCode) {
57
+ throw new Error(
58
+ "The book element does not contain a code attribute."
59
+ );
60
+ }
61
+ root.id = bookCode;
62
+ const header = usxElement.querySelector('para[style="h"]');
63
+ if (header) {
64
+ root.header = header.textContent || "";
65
+ }
66
+ const titles = usxElement.querySelectorAll(
67
+ 'para[style="mt1"], para[style="mt2"], para[style="mt3"]'
68
+ );
69
+ if (titles.length > 0) {
70
+ root.title = [...titles].map((t) => t.textContent).filter((t) => t).join(" ");
71
+ }
72
+ for (let content of this.iterateRootContent(usxElement)) {
73
+ root.content.push(content);
74
+ }
75
+ return root;
76
+ }
77
+ *iterateRootContent(usxElement) {
78
+ const iterator = (0, import_iterators.iterateAll)(usxElement);
79
+ while (true) {
80
+ const { done, value: child } = iterator.next();
81
+ if (done) {
82
+ break;
83
+ }
84
+ if (!(child instanceof Element)) {
85
+ continue;
86
+ }
87
+ if (child.nodeName === "chapter") {
88
+ if (child.hasAttribute("eid")) {
89
+ continue;
90
+ }
91
+ const chapter = {
92
+ type: "chapter",
93
+ number: parseInt(child.getAttribute("number") || "0", 10),
94
+ content: [],
95
+ footnotes: []
96
+ };
97
+ for (let content of this.iterateChapterContent(
98
+ chapter,
99
+ iterator
100
+ )) {
101
+ chapter.content.push(content);
102
+ }
103
+ yield chapter;
104
+ } else if (child.nodeName === "para") {
105
+ const style = child.getAttribute("style");
106
+ if (style === "s1" || style === "s2" || style === "s3" || style === "s4") {
107
+ yield {
108
+ type: "heading",
109
+ content: child.textContent ? [child.textContent] : []
110
+ };
111
+ }
112
+ }
113
+ }
114
+ }
115
+ *iterateChapterContent(chapter, nodes) {
116
+ while (true) {
117
+ const { done, value: element } = nodes.next();
118
+ if (done) {
119
+ break;
120
+ }
121
+ if (!(element instanceof Element)) {
122
+ continue;
123
+ }
124
+ if (element.nodeName === "chapter") {
125
+ break;
126
+ } else if (element.nodeName === "para") {
127
+ const style = element.getAttribute("style");
128
+ if (style === "s1" || style === "s2" || style === "s3" || style === "s4") {
129
+ yield {
130
+ type: "heading",
131
+ content: element.textContent ? [element.textContent] : []
132
+ };
133
+ } else if (style === "b") {
134
+ yield {
135
+ type: "line_break"
136
+ };
137
+ } else if (style === "d") {
138
+ yield* this.parseHebrewSubtitle(element, chapter, nodes);
139
+ }
140
+ } else if (element.nodeName === "verse") {
141
+ if (element.hasAttribute("eid")) {
142
+ continue;
143
+ }
144
+ yield this.parseVerse(element, chapter, nodes);
145
+ }
146
+ }
147
+ }
148
+ *iterateVerseContent(chapter, verse, nodes) {
149
+ while (true) {
150
+ const { done, value: node } = nodes.next();
151
+ if (done) {
152
+ break;
153
+ }
154
+ if (node.nodeName === "verse") {
155
+ break;
156
+ }
157
+ const parent = node.parentElement;
158
+ let poem = null;
159
+ let descriptive = null;
160
+ if (parent.nodeName === "para") {
161
+ const style = parent.getAttribute("style");
162
+ if (style === "q1" || style === "q2" || style === "q3" || style === "q4") {
163
+ poem = style === "q1" ? 1 : style === "q2" ? 2 : style === "q3" ? 3 : 4;
164
+ } else if (style === "d") {
165
+ descriptive = true;
166
+ }
167
+ }
168
+ for (let content of this.iterateNodeTextContent(
169
+ nodes,
170
+ node,
171
+ chapter,
172
+ verse
173
+ )) {
174
+ if (poem !== null || descriptive !== null) {
175
+ if (typeof content === "string") {
176
+ let text = {
177
+ text: content
178
+ };
179
+ if (poem !== null) {
180
+ text.poem = poem;
181
+ }
182
+ if (descriptive !== null) {
183
+ text.descriptive = true;
184
+ }
185
+ yield text;
186
+ } else {
187
+ let text = {
188
+ ...content
189
+ };
190
+ if ("text" in text) {
191
+ if (poem !== null) {
192
+ text.poem = poem;
193
+ }
194
+ if (descriptive !== null) {
195
+ text.descriptive = true;
196
+ }
197
+ }
198
+ yield text;
199
+ }
200
+ } else {
201
+ yield content;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ parseVerse(element, chapter, nodes) {
207
+ const verse = {
208
+ type: "verse",
209
+ number: parseInt(element.getAttribute("number") || "0", 10),
210
+ content: []
211
+ };
212
+ for (let content of this.iterateVerseContent(chapter, verse, nodes)) {
213
+ addOrJoin(verse.content, content);
214
+ }
215
+ trimContent(verse.content);
216
+ return verse;
217
+ }
218
+ *parseHebrewSubtitle(para, chapter, nodes) {
219
+ const subtitle = {
220
+ type: "hebrew_subtitle",
221
+ content: []
222
+ };
223
+ for (let content of this.iterateHebrewSubtitleContent(
224
+ para,
225
+ chapter,
226
+ nodes
227
+ )) {
228
+ if (typeof content === "object" && "number" in content) {
229
+ yield content;
230
+ continue;
231
+ }
232
+ addOrJoin(subtitle.content, content);
233
+ }
234
+ trimContent(subtitle.content);
235
+ if (subtitle.content.length > 0) {
236
+ yield subtitle;
237
+ }
238
+ }
239
+ *iterateHebrewSubtitleContent(element, chapter, nodes) {
240
+ while (true) {
241
+ const { done, value: node } = nodes.next();
242
+ if (done) {
243
+ break;
244
+ }
245
+ if (!(0, import_iterators.isParent)(node, element)) {
246
+ nodes.rewind(1);
247
+ break;
248
+ }
249
+ if (node instanceof Element && node.nodeName === "verse") {
250
+ yield this.parseVerse(node, chapter, nodes);
251
+ } else {
252
+ yield* this.iterateNodeTextContent(nodes, node, chapter);
253
+ }
254
+ }
255
+ }
256
+ *iterateNodeTextContent(nodes, node, chapter, verse) {
257
+ if (node instanceof Element && node.nodeName === "note") {
258
+ yield* this.iterateNote(nodes, node, chapter, verse);
259
+ } else if (node instanceof Element && node.nodeName === "char") {
260
+ yield* this.iterateChar(nodes, node);
261
+ } else if (node instanceof Element && node.nodeName === "para" && node.getAttribute("style") === "b") {
262
+ for (let _ of (0, import_iterators.children)(nodes, node)) {
263
+ }
264
+ yield {
265
+ lineBreak: true
266
+ };
267
+ } else if (node.nodeType === 3 /* Text */) {
268
+ yield node.textContent || "";
269
+ }
270
+ }
271
+ *iterateCharContent(char) {
272
+ const style = char.getAttribute("style");
273
+ const text = trimText(char.textContent || "");
274
+ if (style === "wj") {
275
+ yield {
276
+ text,
277
+ wordsOfJesus: true
278
+ };
279
+ } else {
280
+ yield text;
281
+ }
282
+ }
283
+ *iterateNote(nodes, node, chapter, verse) {
284
+ const style = node.getAttribute("style");
285
+ if (style === "f") {
286
+ const verseReferenceRegex = /^[0-9]{1,3}:[0-9]{1,3}/;
287
+ let text = "";
288
+ for (let child of (0, import_iterators.children)(nodes, node)) {
289
+ if (child.nodeType === 3 /* Text */) {
290
+ text += child.textContent || "";
291
+ }
292
+ }
293
+ text = text.trim();
294
+ if (verseReferenceRegex.test(text)) {
295
+ text = text.replace(verseReferenceRegex, "").trim();
296
+ }
297
+ const note = {
298
+ noteId: this._noteCounter++,
299
+ caller: node.getAttribute("caller") || null,
300
+ text,
301
+ reference: {
302
+ chapter: chapter.number,
303
+ verse: verse?.number ?? 0
304
+ }
305
+ };
306
+ chapter.footnotes.push(note);
307
+ yield {
308
+ noteId: note.noteId
309
+ };
310
+ } else {
311
+ for (let _ of (0, import_iterators.children)(nodes, node)) {
312
+ }
313
+ }
314
+ }
315
+ *iterateChar(nodes, node) {
316
+ const style = node.getAttribute("style");
317
+ let text = "";
318
+ for (let char of (0, import_iterators.children)(nodes, node)) {
319
+ if (char.nodeType === 3 /* Text */) {
320
+ text += char.textContent || "";
321
+ }
322
+ }
323
+ if (style === "wj") {
324
+ yield {
325
+ text,
326
+ wordsOfJesus: true
327
+ };
328
+ } else {
329
+ yield text;
330
+ }
331
+ }
332
+ }
333
+ const ignoredParaStyles = /* @__PURE__ */ new Set([
334
+ // <para> Identification [exclude all] - Running headings & table of contents
335
+ "ide",
336
+ // See https://github.com/schierlm/BibleMultiConverter/issues/67
337
+ "rem",
338
+ // Remarks (valid in schema though missed in docs)
339
+ "h",
340
+ "h1",
341
+ "h2",
342
+ "h3",
343
+ "h4",
344
+ "toc1",
345
+ "toc2",
346
+ "toc3",
347
+ "toca1",
348
+ "toca2",
349
+ "toca3",
350
+ /* <para> Introductions [exclude all] - Introductionary (non-biblical) content
351
+ Which might be helpful in a printed book, but intro material in apps is usually bad UX,
352
+ and users that really care can research a translations methodology themselves
353
+ */
354
+ "imt",
355
+ "imt1",
356
+ "imt2",
357
+ "imt3",
358
+ "imt4",
359
+ "is",
360
+ "is1",
361
+ "is2",
362
+ "is3",
363
+ "is4",
364
+ "ip",
365
+ "ipi",
366
+ "im",
367
+ "imi",
368
+ "ipq",
369
+ "imq",
370
+ "ipr",
371
+ "iq",
372
+ "iq1",
373
+ "iq2",
374
+ "iq3",
375
+ "iq4",
376
+ "ib",
377
+ "ili",
378
+ "ili1",
379
+ "ili2",
380
+ "ili3",
381
+ "ili4",
382
+ "iot",
383
+ "io",
384
+ "io1",
385
+ "io2",
386
+ "io3",
387
+ "io4",
388
+ "iex",
389
+ "imte",
390
+ "ie",
391
+ /* <para> Headings [exclude some] - Exclude book & chapter headings but keep section headings
392
+ Not excluded: ms# | mr | s# | sr | d | sp | sd#
393
+ */
394
+ "mt",
395
+ "mt1",
396
+ "mt2",
397
+ "mt3",
398
+ "mt4",
399
+ "mte",
400
+ "mte1",
401
+ "mte2",
402
+ "mte3",
403
+ "mte4",
404
+ "cl",
405
+ "cd",
406
+ // Non-biblical chapter summary, more than heading
407
+ "r"
408
+ // Parallels to be provided by external data
409
+ ]);
410
+ function* iterateCharContent(char) {
411
+ const style = char.getAttribute("style");
412
+ const text = trimText(char.textContent || "");
413
+ if (style === "wj") {
414
+ yield {
415
+ text,
416
+ wordsOfJesus: true
417
+ };
418
+ } else {
419
+ yield text;
420
+ }
421
+ }
422
+ function trimText(text) {
423
+ return text.replace(/\s+/g, " ");
424
+ }
425
+ function trimContent(content) {
426
+ for (let i = 0; i < content.length; i++) {
427
+ const value = content[i];
428
+ if (typeof value === "string") {
429
+ content[i] = trimText(value).trim();
430
+ if (content[i] === "") {
431
+ content.splice(i, 1);
432
+ i--;
433
+ continue;
434
+ }
435
+ } else if (isVerseText(value)) {
436
+ value.text = trimText(value.text).trim();
437
+ if (value.text === "") {
438
+ content.splice(i, 1);
439
+ i--;
440
+ continue;
441
+ }
442
+ }
443
+ }
444
+ return content;
445
+ }
446
+ function addOrJoin(array, value) {
447
+ if (array.length === 0) {
448
+ array.push(value);
449
+ } else {
450
+ const last = array[array.length - 1];
451
+ if (typeof last === "string" && typeof value === "string") {
452
+ array[array.length - 1] = last + value;
453
+ } else if (isVerseText(last) && isVerseText(value) && hasSameFormatting(last, value)) {
454
+ last.text += value.text;
455
+ } else {
456
+ array.push(value);
457
+ }
458
+ }
459
+ }
460
+ function isVerseText(value) {
461
+ return typeof value === "object" && value !== null && "text" in value;
462
+ }
463
+ function hasSameFormatting(a, b) {
464
+ return a.poem === b.poem && a.wordsOfJesus === b.wordsOfJesus;
465
+ }
466
+ // Annotate the CommonJS export names for ESM import in node:
467
+ 0 && (module.exports = {
468
+ PARSER_VERSION,
469
+ USXParser
470
+ });
471
+ //# sourceMappingURL=usx-parser.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../parser/usx-parser.ts"],
4
+ "sourcesContent": ["import {\n Chapter,\n ChapterContent,\n Footnote,\n FootnoteReference,\n ParseTree,\n Verse,\n Text,\n HebrewSubtitle,\n InlineLineBreak,\n InlineHeading,\n} from './types.js';\nimport {\n iterateAll,\n children,\n RewindableIterator,\n isParent,\n} from './iterators.js';\n\nenum NodeType {\n Text = 3,\n}\n\n/**\n * The version of the parser.\n * Used to determine whether input files need to be re-parsed.\n */\nexport const PARSER_VERSION = '1';\n\n/**\n * Defines a class that is able to parse USX content.\n */\nexport class USXParser {\n private _domParser: DOMParser;\n private _noteCounter: number = 0;\n\n constructor(domParser: DOMParser) {\n this._domParser = domParser;\n }\n\n /**\n * Parses the specified USX content.\n *\n * @param usx The USX content to parse.\n * @returns The parse tree that was generated.\n */\n public parse(usx: string): ParseTree {\n const parser = this._domParser;\n const doc = parser.parseFromString(usx, 'application/xml');\n const usxElement = doc.documentElement;\n\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n const bookElement = usxElement.querySelector('book[code]');\n\n if (!bookElement) {\n throw new Error('The USX content does not contain a book element.');\n }\n\n const bookCode = bookElement.getAttribute('code') || '';\n\n if (!bookCode) {\n throw new Error(\n 'The book element does not contain a code attribute.'\n );\n }\n\n root.id = bookCode;\n\n const header = usxElement.querySelector('para[style=\"h\"]');\n if (header) {\n root.header = header.textContent || '';\n }\n\n const titles = usxElement.querySelectorAll(\n 'para[style=\"mt1\"], para[style=\"mt2\"], para[style=\"mt3\"]'\n );\n // const title2 = usxElement.querySelector('para[style=\"mt2\"]');\n // const title3 = usxElement.querySelector('para[style=\"mt3\"]');\n\n if (titles.length > 0) {\n root.title = [...titles]\n .map((t) => t.textContent)\n .filter((t) => t)\n .join(' ');\n }\n\n for (let content of this.iterateRootContent(usxElement)) {\n root.content.push(content);\n }\n\n return root;\n }\n\n *iterateRootContent(\n usxElement: Element\n ): Generator<ParseTree['content'][0]> {\n const iterator = iterateAll(usxElement);\n while (true) {\n const { done, value: child } = iterator.next();\n if (done) {\n break;\n }\n\n if (!(child instanceof Element)) {\n continue;\n }\n\n if (child.nodeName === 'chapter') {\n if (child.hasAttribute('eid')) {\n continue;\n }\n\n const chapter: Chapter = {\n type: 'chapter',\n number: parseInt(child.getAttribute('number') || '0', 10),\n content: [],\n footnotes: [],\n };\n\n for (let content of this.iterateChapterContent(\n chapter,\n iterator\n )) {\n chapter.content.push(content);\n }\n\n yield chapter;\n } else if (child.nodeName === 'para') {\n const style = child.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: child.textContent ? [child.textContent] : [],\n };\n }\n }\n }\n }\n\n *iterateChapterContent(\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<ChapterContent> {\n while (true) {\n const { done, value: element } = nodes.next();\n if (done) {\n break;\n }\n\n if (!(element instanceof Element)) {\n continue;\n }\n\n if (element.nodeName === 'chapter') {\n break;\n } else if (element.nodeName === 'para') {\n const style = element.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: element.textContent\n ? [element.textContent]\n : [],\n };\n } else if (style === 'b') {\n yield {\n type: 'line_break',\n };\n } else if (style === 'd') {\n yield* this.parseHebrewSubtitle(element, chapter, nodes);\n }\n } else if (element.nodeName === 'verse') {\n if (element.hasAttribute('eid')) {\n continue;\n }\n\n yield this.parseVerse(element, chapter, nodes);\n }\n }\n }\n\n *iterateVerseContent(\n chapter: Chapter,\n verse: Verse,\n nodes: RewindableIterator<Node>\n ): IterableIterator<string | FootnoteReference | Text | InlineLineBreak> {\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (node.nodeName === 'verse') {\n break;\n }\n\n const parent = node.parentElement!;\n let poem: number | null = null;\n let descriptive: boolean | null = null;\n\n if (parent.nodeName === 'para') {\n const style = parent.getAttribute('style');\n if (\n style === 'q1' ||\n style === 'q2' ||\n style === 'q3' ||\n style === 'q4'\n ) {\n poem =\n style === 'q1'\n ? 1\n : style === 'q2'\n ? 2\n : style === 'q3'\n ? 3\n : 4;\n } else if (style === 'd') {\n descriptive = true;\n }\n }\n\n for (let content of this.iterateNodeTextContent(\n nodes,\n node,\n chapter,\n verse\n )) {\n if (poem !== null || descriptive !== null) {\n if (typeof content === 'string') {\n let text: Text = {\n text: content,\n };\n\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n\n yield text;\n } else {\n let text:\n | InlineLineBreak\n | InlineHeading\n | FootnoteReference\n | Text = {\n ...content,\n };\n\n if ('text' in text) {\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n }\n yield text;\n }\n } else {\n yield content;\n }\n }\n }\n }\n\n parseVerse(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): Verse {\n const verse: Verse = {\n type: 'verse',\n number: parseInt(element.getAttribute('number') || '0', 10),\n content: [],\n };\n\n for (let content of this.iterateVerseContent(chapter, verse, nodes)) {\n addOrJoin(verse.content, content);\n }\n\n trimContent(verse.content);\n return verse;\n }\n\n *parseHebrewSubtitle(\n para: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<HebrewSubtitle | Verse> {\n const subtitle: HebrewSubtitle = {\n type: 'hebrew_subtitle',\n content: [],\n };\n\n for (let content of this.iterateHebrewSubtitleContent(\n para,\n chapter,\n nodes\n )) {\n if (typeof content === 'object' && 'number' in content) {\n yield content;\n continue;\n }\n addOrJoin(subtitle.content, content);\n }\n\n trimContent(subtitle.content);\n if (subtitle.content.length > 0) {\n yield subtitle;\n }\n }\n\n *iterateHebrewSubtitleContent(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<\n Verse | string | Text | FootnoteReference | InlineLineBreak\n > {\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (!isParent(node, element)) {\n nodes.rewind(1);\n break;\n }\n\n if (node instanceof Element && node.nodeName === 'verse') {\n yield this.parseVerse(node, chapter, nodes);\n } else {\n yield* this.iterateNodeTextContent(nodes, node, chapter);\n }\n }\n }\n\n *iterateNodeTextContent(\n nodes: RewindableIterator<Node>,\n node: Node,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<string | Text | FootnoteReference | InlineLineBreak> {\n if (node instanceof Element && node.nodeName === 'note') {\n yield* this.iterateNote(nodes, node, chapter, verse);\n } else if (node instanceof Element && node.nodeName === 'char') {\n yield* this.iterateChar(nodes, node);\n } else if (\n node instanceof Element &&\n node.nodeName === 'para' &&\n node.getAttribute('style') === 'b'\n ) {\n for (let _ of children(nodes, node)) {\n // iterate through all the children to prevent iterating over them multiple times\n }\n yield {\n lineBreak: true,\n };\n } else if (node.nodeType === NodeType.Text) {\n yield node.textContent || '';\n }\n }\n\n *iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n }\n\n *iterateNote(\n nodes: RewindableIterator<Node>,\n node: Element,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<FootnoteReference> {\n const style = node.getAttribute('style');\n if (style === 'f') {\n const verseReferenceRegex = /^[0-9]{1,3}:[0-9]{1,3}/;\n\n let text = '';\n for (let child of children(nodes, node)) {\n if (child.nodeType === NodeType.Text) {\n text += child.textContent || '';\n }\n }\n\n text = text.trim();\n if (verseReferenceRegex.test(text)) {\n text = text.replace(verseReferenceRegex, '').trim();\n }\n\n const note: Footnote = {\n noteId: this._noteCounter++,\n caller: node.getAttribute('caller') || null,\n text,\n reference: {\n chapter: chapter.number,\n verse: verse?.number ?? 0,\n },\n };\n\n chapter.footnotes.push(note);\n\n yield {\n noteId: note.noteId,\n };\n } else {\n for (let _ of children(nodes, node)) {\n // iterate through all the children\n // so that we don't end up with duplicates\n }\n }\n }\n\n *iterateChar(\n nodes: RewindableIterator<Node>,\n node: Element\n ): IterableIterator<string | Text> {\n const style = node.getAttribute('style');\n let text = '';\n\n for (let char of children(nodes, node)) {\n if (char.nodeType === NodeType.Text) {\n text += char.textContent || '';\n }\n }\n\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n\n // if (!parentChar(node) && !parentNote(node)) {\n // yield *iterateCharContent(node);\n // }\n }\n}\n\n// Taken from https://github.com/gracious-tech/fetch/blob/1576cc4eafb32bf347a09332094cf17c2231c90c/converters/usx-to-json/src/elements.ts#L16\nconst ignoredParaStyles = new Set([\n // <para> Identification [exclude all] - Running headings & table of contents\n 'ide', // See https://github.com/schierlm/BibleMultiConverter/issues/67\n 'rem', // Remarks (valid in schema though missed in docs)\n 'h',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'toc1',\n 'toc2',\n 'toc3',\n 'toca1',\n 'toca2',\n 'toca3',\n\n /* <para> Introductions [exclude all] - Introductionary (non-biblical) content\n Which might be helpful in a printed book, but intro material in apps is usually bad UX,\n and users that really care can research a translations methodology themselves\n */\n 'imt',\n 'imt1',\n 'imt2',\n 'imt3',\n 'imt4',\n 'is',\n 'is1',\n 'is2',\n 'is3',\n 'is4',\n 'ip',\n 'ipi',\n 'im',\n 'imi',\n 'ipq',\n 'imq',\n 'ipr',\n 'iq',\n 'iq1',\n 'iq2',\n 'iq3',\n 'iq4',\n 'ib',\n 'ili',\n 'ili1',\n 'ili2',\n 'ili3',\n 'ili4',\n 'iot',\n 'io',\n 'io1',\n 'io2',\n 'io3',\n 'io4',\n 'iex',\n 'imte',\n 'ie',\n\n /* <para> Headings [exclude some] - Exclude book & chapter headings but keep section headings\n Not excluded: ms# | mr | s# | sr | d | sp | sd#\n */\n 'mt',\n 'mt1',\n 'mt2',\n 'mt3',\n 'mt4',\n 'mte',\n 'mte1',\n 'mte2',\n 'mte3',\n 'mte4',\n 'cl',\n 'cd', // Non-biblical chapter summary, more than heading\n 'r', // Parallels to be provided by external data\n]);\n\nfunction* iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n}\n\nfunction trimText(text: string): string {\n return text.replace(/\\s+/g, ' ');\n}\n\nfunction trimContent<T extends string | unknown>(content: T[]): T[] {\n for (let i = 0; i < content.length; i++) {\n const value = content[i];\n if (typeof value === 'string') {\n content[i] = trimText(value as string).trim() as T;\n if (content[i] === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n } else if (isVerseText(value)) {\n value.text = trimText(value.text).trim();\n if (value.text === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n }\n }\n return content;\n}\n\nfunction addOrJoin(array: (string | unknown)[], value: string | unknown) {\n if (array.length === 0) {\n array.push(value);\n } else {\n const last = array[array.length - 1];\n if (typeof last === 'string' && typeof value === 'string') {\n array[array.length - 1] = last + value;\n } else if (\n isVerseText(last) &&\n isVerseText(value) &&\n hasSameFormatting(last, value)\n ) {\n last.text += value.text;\n } else {\n array.push(value);\n }\n }\n}\n\nfunction isVerseText(value: unknown): value is Text {\n return typeof value === 'object' && value !== null && 'text' in value;\n}\n\nfunction hasSameFormatting(a: Text, b: Text): boolean {\n return a.poem === b.poem && a.wordsOfJesus === b.wordsOfJesus;\n}\n"],
5
+ "mappings": ";;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