Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Books with single chapter are incorrectly parsed, breaks output of content to html #1

Open
JMNofziger opened this issue Jan 14, 2025 · 1 comment

Comments

@JMNofziger
Copy link

Seems there's a bug with the parsing/handling of single chapter books - the result I noticed is a failure to output the books contents when generating html from the source material. This affects all language translations/bible versions. You can see examples of the outcome of the parsing failures in any of the single chapter books, I've included a link to obadiah and 2 john here as examples:

The issue seems to trace back to that result returned from the xml2js parseString

In books containing more than one chapter, the dictionary for the book contains a "chapter" key with a list value. Each value within that "chapter" list structure represents one chapter of the book and is structured as a dictionary. However in the books which have only a single chapter, the "chapter" key within the book dictionary contains the chapter dictionary without the enclosing list structure. I imagine that getting your parser to enclose those chapters as expected would resolve the bug.

parser call and my debug line to log result

    if (srcExt === '.xml') {

        handled = true;
        var parse = require('xml2js').parseString;
        parse(srcFiles, options, function(err, result) {
          if (err) {
            grunt.fail.warn('File ' + f.dest.cyan + ' parsing errors: ' + err);
          }
          grunt.log.ok(JSON.stringify(result, null, 2))

Book (jude) with single chapter example of parse output:

>>         },
>>         {
>>           "type": "book",
>>           "osisID": "Jude",
>>           "chapter": {
>>             "osisID": "Jude.1",
>>             "title": "The children of your elect sister greet you.",
>>             "verse": [
>>               {
>>                 "_": "Jude, a servant of Jesus Christ and brother of James,  To those who are called, beloved in God the Father and kept for Jesus Christ:",
>>                 "osisID": "Jude.1.1"
>>               },
>>               {
>>                 ...
>>                 ...
>>                 ...

compared to a book with many chapters (revelations)

>>         },
>>         {
>>           "type": "book",
>>           "osisID": "Rev",
>>           "chapter": [
>>             {
>>               "osisID": "Rev.1",
>>               "title": "I hope to see you soon, and we will talk together face to face. [ (III John 1:15) Peace be to you. The friends greet you. Greet the friends, every one of them. ]",
>>               "verse": [
>>                 {
>>                   "_": "The revelation of Jesus Christ, which God gave him to show to his servants what must soon take place; and he made it known by sending his angel to his servant John,",
>>                   "osisID": "Rev.1.1"
>>                 },
>>                 {
@JMNofziger
Copy link
Author

Created a quick fix for simple restructuring of the parsed object in this specific condition: 7c4ff61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant