Skip to content
On this page

Parsers

The Parsers in BibleKit are specialized tools designed to parse text and identify Bible passages within that text. They help developers separate and identify Bible passages within larger bodies of text or rich editor content. The primary functions in this category include:

  • parseTextWithPassages
  • transformQuillContentWithPassages

parseTextWithPassages

The parseTextWithPassages function aids in parsing text and identifying Bible passages within the text. This function takes a string as an argument and returns an array of substrings, each represented as an object with properties specifying the substring's index, length, type, and value.

ts
const substrings = parseTextWithPassages(
      'You can open Gen. 1:1; Ex. 2:3; Josh. 8:9-2,10,23-29 default verse Gen. 1:2 it is necessary to learn whole chapter Gen. 1.',
    );

The returned array consists of objects. Each object represents a substring from the original input text.

js
[
  {
    "index": 0,
    "length": 13,
    "type": "text",
    "value": "You can open ",
  },
  {
    "index": 13,
    "length": 8,
    "type": "passage",
    "value": "Gen. 1:1; Ex. 2:3; Josh. 8:9-2,10,23-29",
  },
  {
    "index": 52,
    "length": 15,
    "type": "text",
    "value": " default verse ",
  },
  {
    "index": 67,
    "length": 8,
    "type": "passage",
    "value": "Gen. 1:2",
  },
  {
    "index": 75,
    "length": 40,
    "type": "text",
    "value": " it is necessary to learn whole chapter ",
  },
  {
    "index": 115,
    "length": 6,
    "type": "passage",
    "value": "Gen. 1",
  },
  {
    "index": 121,
    "length": 1,
    "type": "text",
    "value": ".",
  },
]

The properties of each object in the array are as follows:

  • index: The starting position of the substring in the original text.
  • length: The length of the substring.
  • type: The type of the substring, which can be either text or passage. text indicates a substring that is not a Bible passage, while passage indicates a substring that is a Bible passage.
  • value: The actual content of the substring.

This function is designed to help developers parse Bible passages and separate them from the rest of the text in a convenient format, providing a more manageable way to interact with Bible passages embedded within larger bodies of text.

transformQuillContentWithPassages

The transformQuillContentWithPassages function, is designed to parse the content of Quill, a popular rich text editor, and identify and transform Bible passages within the content. The function takes a Quill Delta object as an input and returns a new Delta object where Bible passages are encapsulated as Delta inserts.

ts
const contents = transformQuillContentWithPassages({
      ops: [
        {
          insert: 'You can open Gen. 1:1; Ex. 2:3 default verse Gen. 1:2 it is necessary to learn whole chapter Gen. 1.',
        },
      ],
    });

The returned object is a new Quill Delta where Bible passages are identified as separate insert operations.

ts
{
  "ops": [
    {
      "insert": "You can open ",
    },
    {
      "insert": {
        "passage": {
          "index": 13,
          "length": 8,
          "value": "Gen. 1:1; Ex. 2:3",
        },
      },
    },
    {
      "insert": " default verse ",
    },
    {
      "insert": {
        "passage": {
          "index": 45,
          "length": 8,
          "value": "Gen. 1:2",
        },
      },
    },
    {
      "insert": " it is necessary to learn whole chapter ",
    },
    {
      "insert": {
        "passage": {
          "index": 93,
          "length": 6,
          "value": "Gen. 1",
        },
      },
    },
    {
      "insert": ".",
    },
  ],
}

Each passage insert has properties index, length, and value. The index property denotes the position of the passage in the original content, length is the length of the passage, and value contains the actual Bible passage text.

This function provides a powerful and convenient way for developers to interact with and process Bible passages within rich text content.