mirror of
https://github.com/zotero/zotero.git
synced 2026-09-10 22:41:08 +00:00
Fix error using a CSL 0.8 style
transformToDocument() needs a load group, which it takes from the source document or from the window that created the XSLTProcessor. Neither of those has existed since0f2690eb75in Zotero 8 stopped taking XSLTProcessor from the hidden window, so the CSL 0.8 → 1.0 upgrade threw NS_ERROR_FAILURE. In Word, this showed as "Zotero encountered an error while updating your document." https://forums.zotero.org/discussion/133543/ (cherry picked from commit4a8a88dd41)
This commit is contained in:
parent
501ecc895c
commit
36dc88ce08
2 changed files with 31 additions and 2 deletions
|
|
@ -845,8 +845,11 @@ Zotero.Style.prototype.getCiteProc = function (locale, format, options = {}) {
|
|||
let styleDOMXML = new DOMParser()
|
||||
.parseFromString(this.getXML(), "text/xml");
|
||||
|
||||
// apply XSLT and serialize output
|
||||
let newDOMXML = Zotero.Styles.xsltProcessor.transformToDocument(styleDOMXML);
|
||||
// apply XSLT and serialize output. transformToFragment() is used because
|
||||
// transformToDocument() needs a load group, which it takes from the source
|
||||
// document or from the window that created the processor, and there's
|
||||
// neither here.
|
||||
let newDOMXML = Zotero.Styles.xsltProcessor.transformToFragment(styleDOMXML, styleDOMXML);
|
||||
var xml = new XMLSerializer().serializeToString(newDOMXML);
|
||||
} else {
|
||||
var xml = this.getXML();
|
||||
|
|
|
|||
|
|
@ -253,4 +253,30 @@ describe("Zotero.Styles", function () {
|
|||
assert.equal(style.effectiveLocale, "en-US");
|
||||
});
|
||||
});
|
||||
|
||||
describe("CSL 0.8 styles", function () {
|
||||
var csl08Style = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" xml:lang="en">
|
||||
<info>
|
||||
<title>Test 0.8 Style</title>
|
||||
<id>http://www.zotero.org/styles/test-08</id>
|
||||
<updated>2010-01-01T00:00:00+00:00</updated>
|
||||
</info>
|
||||
<bibliography>
|
||||
<layout>
|
||||
<text variable="title"/>
|
||||
</layout>
|
||||
</bibliography>
|
||||
</style>
|
||||
`;
|
||||
|
||||
it("should upgrade a style to CSL 1.0 and format a bibliography", async function () {
|
||||
var item = await createDataObject('item', { title: 'Foo Bar' });
|
||||
var style = new Zotero.Style(csl08Style);
|
||||
assert.equal(style._version, "0.8");
|
||||
var cslEngine = style.getCiteProc('en-US', 'text');
|
||||
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
|
||||
assert.equal(text, 'Foo Bar\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue