@helloao/cli 0.0.20 → 0.1.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/cli.cjs CHANGED
@@ -12366,6 +12366,10 @@ var CodexParser = class {
12366
12366
  // */
12367
12367
  // preserveMarkdown: boolean = true;
12368
12368
  _noteCounter = 0;
12369
+ _parser;
12370
+ constructor(parser) {
12371
+ this._parser = parser;
12372
+ }
12369
12373
  /**
12370
12374
  * Parses the specified codex content.
12371
12375
  *
@@ -12381,7 +12385,7 @@ var CodexParser = class {
12381
12385
  };
12382
12386
  let chapters = /* @__PURE__ */ new Map();
12383
12387
  let lastChapter = null;
12384
- function addChapterContent(chapterNumber, content) {
12388
+ function ensureChapter(chapterNumber) {
12385
12389
  let chapter = chapters.get(chapterNumber);
12386
12390
  if (!chapter) {
12387
12391
  chapter = {
@@ -12393,8 +12397,23 @@ var CodexParser = class {
12393
12397
  lastChapter = chapter;
12394
12398
  chapters.set(chapterNumber, chapter);
12395
12399
  }
12400
+ return chapter;
12401
+ }
12402
+ function getDocumentContent(doc) {
12403
+ let content = "";
12404
+ for (let element of doc.childNodes) {
12405
+ content += element.textContent;
12406
+ }
12407
+ return content;
12408
+ }
12409
+ function addChapterContent(chapterNumber, content) {
12410
+ const chapter = ensureChapter(chapterNumber);
12396
12411
  chapter.content.push(...content);
12397
12412
  }
12413
+ function addChapterFootnote(chapterNumber, footnote) {
12414
+ const chapter = ensureChapter(chapterNumber);
12415
+ chapter.footnotes.push(footnote);
12416
+ }
12398
12417
  function addReference(ref2, content) {
12399
12418
  addChapterContent(ref2.chapter, [
12400
12419
  {
@@ -12416,8 +12435,12 @@ var CodexParser = class {
12416
12435
  function addLineBreaks(lines2) {
12417
12436
  return lines2.reduce(
12418
12437
  (prev, current) => {
12419
- if (prev.length === 0) return [current];
12420
- else
12438
+ if (typeof current === "string" && current.trim() === "") {
12439
+ return prev;
12440
+ }
12441
+ if (prev.length === 0) {
12442
+ return [current];
12443
+ } else {
12421
12444
  return [
12422
12445
  ...prev,
12423
12446
  {
@@ -12425,6 +12448,7 @@ var CodexParser = class {
12425
12448
  },
12426
12449
  current
12427
12450
  ];
12451
+ }
12428
12452
  },
12429
12453
  []
12430
12454
  );
@@ -12490,13 +12514,49 @@ var CodexParser = class {
12490
12514
  }
12491
12515
  previousReference = reference;
12492
12516
  if (!root.id) root.id = reference.book;
12493
- const content = stripHTML(cell.value);
12494
- const newLines = content.split("\n");
12495
- lines.push(...newLines);
12517
+ const doc = this._parser.parseFromString(
12518
+ cell.value,
12519
+ "text/html"
12520
+ );
12521
+ for (let element of doc.children) {
12522
+ const allFootnotes = element.querySelectorAll(
12523
+ "sup.footnote-marker[data-footnote]"
12524
+ );
12525
+ for (const footnote of allFootnotes) {
12526
+ const footnoteData = footnote.getAttribute("data-footnote");
12527
+ if (footnoteData) {
12528
+ const footnoteDoc = this._parser.parseFromString(
12529
+ footnoteData,
12530
+ "text/html"
12531
+ );
12532
+ const footnoteText = getDocumentContent(footnoteDoc);
12533
+ if (footnoteText) {
12534
+ addChapterFootnote(reference.chapter, {
12535
+ noteId: this._noteCounter++,
12536
+ text: footnoteText,
12537
+ caller: null
12538
+ });
12539
+ }
12540
+ }
12541
+ footnote.remove();
12542
+ }
12543
+ }
12544
+ const content = getDocumentContent(doc);
12545
+ if (content) {
12546
+ const newLines = content.split("\n");
12547
+ lines.push(...newLines);
12548
+ }
12496
12549
  } else if (metadata.type === "paratext") {
12497
12550
  const reference = parseVerseReference(`${metadata.id}:1`);
12498
12551
  if (reference) {
12499
- const content = stripHTML(cell.value);
12552
+ const doc = this._parser.parseFromString(
12553
+ cell.value,
12554
+ "text/html"
12555
+ );
12556
+ const content = getDocumentContent(doc);
12557
+ if (!content) {
12558
+ continue;
12559
+ }
12500
12560
  const lines2 = content.split("\n").reduce((prev, current) => {
12501
12561
  if (prev.length === 0)
12502
12562
  return [toHeading(current)];
@@ -12513,8 +12573,12 @@ var CodexParser = class {
12513
12573
  (line) => addChapterContent(reference.chapter, [line])
12514
12574
  );
12515
12575
  } else {
12516
- const content = stripHTML(cell.value);
12517
- if (!cell.metadata) {
12576
+ const doc = this._parser.parseFromString(
12577
+ cell.value,
12578
+ "text/html"
12579
+ );
12580
+ const content = getDocumentContent(doc);
12581
+ if (content && !cell.metadata) {
12518
12582
  if (lastChapter) {
12519
12583
  lastChapter.footnotes.push({
12520
12584
  noteId: this._noteCounter++,
@@ -12828,7 +12892,7 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
12828
12892
  };
12829
12893
  let usfmParser = new UsfmParser();
12830
12894
  let usxParser = new USXParser(parser);
12831
- let codexParser = new CodexParser();
12895
+ let codexParser = new CodexParser(parser);
12832
12896
  let csvCommentaryParser = new CommentaryCsvParser();
12833
12897
  let tyndaleXmlParser = new TyndaleXmlParser(parser);
12834
12898
  let parsedTranslations = /* @__PURE__ */ new Map();
@@ -11814,6 +11814,10 @@ var CodexParser = class {
11814
11814
  // */
11815
11815
  // preserveMarkdown: boolean = true;
11816
11816
  _noteCounter = 0;
11817
+ _parser;
11818
+ constructor(parser) {
11819
+ this._parser = parser;
11820
+ }
11817
11821
  /**
11818
11822
  * Parses the specified codex content.
11819
11823
  *
@@ -11829,7 +11833,7 @@ var CodexParser = class {
11829
11833
  };
11830
11834
  let chapters = /* @__PURE__ */ new Map();
11831
11835
  let lastChapter = null;
11832
- function addChapterContent(chapterNumber, content) {
11836
+ function ensureChapter(chapterNumber) {
11833
11837
  let chapter = chapters.get(chapterNumber);
11834
11838
  if (!chapter) {
11835
11839
  chapter = {
@@ -11841,8 +11845,23 @@ var CodexParser = class {
11841
11845
  lastChapter = chapter;
11842
11846
  chapters.set(chapterNumber, chapter);
11843
11847
  }
11848
+ return chapter;
11849
+ }
11850
+ function getDocumentContent(doc) {
11851
+ let content = "";
11852
+ for (let element of doc.childNodes) {
11853
+ content += element.textContent;
11854
+ }
11855
+ return content;
11856
+ }
11857
+ function addChapterContent(chapterNumber, content) {
11858
+ const chapter = ensureChapter(chapterNumber);
11844
11859
  chapter.content.push(...content);
11845
11860
  }
11861
+ function addChapterFootnote(chapterNumber, footnote) {
11862
+ const chapter = ensureChapter(chapterNumber);
11863
+ chapter.footnotes.push(footnote);
11864
+ }
11846
11865
  function addReference(ref2, content) {
11847
11866
  addChapterContent(ref2.chapter, [
11848
11867
  {
@@ -11864,8 +11883,12 @@ var CodexParser = class {
11864
11883
  function addLineBreaks(lines2) {
11865
11884
  return lines2.reduce(
11866
11885
  (prev, current) => {
11867
- if (prev.length === 0) return [current];
11868
- else
11886
+ if (typeof current === "string" && current.trim() === "") {
11887
+ return prev;
11888
+ }
11889
+ if (prev.length === 0) {
11890
+ return [current];
11891
+ } else {
11869
11892
  return [
11870
11893
  ...prev,
11871
11894
  {
@@ -11873,6 +11896,7 @@ var CodexParser = class {
11873
11896
  },
11874
11897
  current
11875
11898
  ];
11899
+ }
11876
11900
  },
11877
11901
  []
11878
11902
  );
@@ -11938,13 +11962,49 @@ var CodexParser = class {
11938
11962
  }
11939
11963
  previousReference = reference;
11940
11964
  if (!root.id) root.id = reference.book;
11941
- const content = stripHTML(cell.value);
11942
- const newLines = content.split("\n");
11943
- lines.push(...newLines);
11965
+ const doc = this._parser.parseFromString(
11966
+ cell.value,
11967
+ "text/html"
11968
+ );
11969
+ for (let element of doc.children) {
11970
+ const allFootnotes = element.querySelectorAll(
11971
+ "sup.footnote-marker[data-footnote]"
11972
+ );
11973
+ for (const footnote of allFootnotes) {
11974
+ const footnoteData = footnote.getAttribute("data-footnote");
11975
+ if (footnoteData) {
11976
+ const footnoteDoc = this._parser.parseFromString(
11977
+ footnoteData,
11978
+ "text/html"
11979
+ );
11980
+ const footnoteText = getDocumentContent(footnoteDoc);
11981
+ if (footnoteText) {
11982
+ addChapterFootnote(reference.chapter, {
11983
+ noteId: this._noteCounter++,
11984
+ text: footnoteText,
11985
+ caller: null
11986
+ });
11987
+ }
11988
+ }
11989
+ footnote.remove();
11990
+ }
11991
+ }
11992
+ const content = getDocumentContent(doc);
11993
+ if (content) {
11994
+ const newLines = content.split("\n");
11995
+ lines.push(...newLines);
11996
+ }
11944
11997
  } else if (metadata.type === "paratext") {
11945
11998
  const reference = parseVerseReference(`${metadata.id}:1`);
11946
11999
  if (reference) {
11947
- const content = stripHTML(cell.value);
12000
+ const doc = this._parser.parseFromString(
12001
+ cell.value,
12002
+ "text/html"
12003
+ );
12004
+ const content = getDocumentContent(doc);
12005
+ if (!content) {
12006
+ continue;
12007
+ }
11948
12008
  const lines2 = content.split("\n").reduce((prev, current) => {
11949
12009
  if (prev.length === 0)
11950
12010
  return [toHeading(current)];
@@ -11961,8 +12021,12 @@ var CodexParser = class {
11961
12021
  (line) => addChapterContent(reference.chapter, [line])
11962
12022
  );
11963
12023
  } else {
11964
- const content = stripHTML(cell.value);
11965
- if (!cell.metadata) {
12024
+ const doc = this._parser.parseFromString(
12025
+ cell.value,
12026
+ "text/html"
12027
+ );
12028
+ const content = getDocumentContent(doc);
12029
+ if (content && !cell.metadata) {
11966
12030
  if (lastChapter) {
11967
12031
  lastChapter.footnotes.push({
11968
12032
  noteId: this._noteCounter++,
@@ -12276,7 +12340,7 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
12276
12340
  };
12277
12341
  let usfmParser = new UsfmParser();
12278
12342
  let usxParser = new USXParser(parser);
12279
- let codexParser = new CodexParser();
12343
+ let codexParser = new CodexParser(parser);
12280
12344
  let csvCommentaryParser = new CommentaryCsvParser();
12281
12345
  let tyndaleXmlParser = new TyndaleXmlParser(parser);
12282
12346
  let parsedTranslations = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helloao/cli",
3
- "version": "0.0.20",
3
+ "version": "0.1.0",
4
4
  "description": "A CLI and related tools for managing HelloAO's Free Bible API",
5
5
  "main": "./dist/cjs/index.cjs",
6
6
  "module": "./dist/esm/index.js",
@@ -43,7 +43,7 @@
43
43
  "all-iso-language-codes": "1.0.17",
44
44
  "papaparse": "5.4.1",
45
45
  "luxon": "3.5.0",
46
- "@helloao/tools": "0.0.20"
46
+ "@helloao/tools": "0.1.0"
47
47
  },
48
48
  "files": [
49
49
  "/README.md",