Skip to content

Commit

Permalink
Corrected literatureCited serialization in ProjectModel
Browse files Browse the repository at this point in the history
Now if there are multiple bibtex elements, they will all be serialized

Relates to issue #994
  • Loading branch information
robyngit committed Jul 25, 2019
1 parent 1fe5fe6 commit b645d8f
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/js/models/project/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ define(["jquery",
/* ==== Serialize literature cited ==== */
// Assumes the value of literatureCited is a block of bibtex text

// var bibtex = $(projectNode).children("literatureCited").children("bibtex");
// if (bibtex.length > 0) {
// modelJSON.literatureCited = this.parseTextNode(projectNode, "literatureCited");
// }

// Remove node if it exists already
$(xmlDoc).find("literatureCited").remove();

Expand All @@ -540,16 +545,26 @@ define(["jquery",
// Don't serialize falsey values
if(litCit){

// Make new element
// <bibxtex> is a subelement of <literatureCited>
// If there's only one element in litCited, it will be a string
// turn it into an array so that we can use _.each
if(typeof litCit == "string"){
litCit = [litCit]
}

// Make new <literatureCited> element
var litCitSerialized = $(xmlDoc.createElement("literatureCited"));
var bibtexSerialized = $(xmlDoc.createElement("bibtex"));

// Wrap in literature cited in cdata tags
var cdataLitCit = xmlDoc.createCDATASection(litCit);
_.each(litCit, function(bibtex){

$(bibtexSerialized).append(cdataLitCit);
$(litCitSerialized).append(bibtexSerialized);
// Wrap in literature cited in cdata tags
var cdataLitCit = xmlDoc.createCDATASection(bibtex);
var bibtexSerialized = $(xmlDoc.createElement("bibtex"));
// wrap in CDATA tags so that bibtex characters aren't escaped
$(bibtexSerialized).append(cdataLitCit);
// <bibxtex> is a subelement of <literatureCited>
$(litCitSerialized).append(bibtexSerialized);

});

// Insert new element at correct position
var insertAfter = this.getXMLPosition(projectNode, "literatureCited");
Expand Down

0 comments on commit b645d8f

Please sign in to comment.