tim-hub / obsidian-bible-reference

Take Bible Study notes easily in the popular note-taking app Obsidian, with automatic verse and reference suggestions.
https://antioch.tech/obsidian-bible-reference/
MIT License
221 stars 41 forks source link

[Enhancement] {KJV} Remove extraneous line breaks #187

Closed abbasou closed 3 months ago

abbasou commented 3 months ago

Describe the bug Most likely an issue with the source data, but there are extraneous line breaks in the middle of many verses in the KJV causing terrible formatting

To Reproduce Steps to reproduce the behavior:

  1. Insert any of the very many affected verses from the KJV

Expected behavior Extraneous line breaks should be removed when inserting text, and then, if necessary, add a line break at the end of each verse (depending on Paragraph or Single Line option).

What Device Do You Use(please complete the following information):

Solution:

/**
   * To get the content of the bible verses
   */
  get allFormattedContent() {
    var _a;
    if (!((_a = this.verses) == null ? void 0 : _a.length)) {
      console.error("No verses found");
    }
    return [this.head, this.bodyContent, this.bottom].join("\n");
  }
  get bodyContent() {
    var _a, _b;
    if (!((_a = this.verses) == null ? void 0 : _a.length)) {
      return "";
    }
    let text = "";
    if (((_b = this.settings) == null ? void 0 : _b.verseFormatting) === "Paragraph" /* Paragraph */) {
      text = "> ";
    } else {
      text = "";
    }
    this.verses.forEach((verse) => {
      var _a2;
      const verseNumberFormatted = this.formatVerseNumber(verse.verse);
      if (((_a2 = this.settings) == null ? void 0 : _a2.verseFormatting) === "Paragraph" /* Paragraph */) {
        text += " " + verseNumberFormatted + verse.text.trim().replaceAll("\n", " ");
      } else {
        text += "> " + verseNumberFormatted + verse.text.trim() + "\n";
      }
    });

Change text += "> " + verseNumberFormatted + verse.text.trim() + "\n"; under the final else to text += "> " + verseNumberFormatted + verse.text.replace(/\r\n|\n|\r/g, " ") + "\n"; Since the line breaks are not at the beginning or end of the string, the .trim() method will not catch and remove them. Use the .replace() method instead.

tim-hub commented 3 months ago

Thanks for the PR and patience.