mirror of
https://github.com/zotero/zotero.git
synced 2026-10-07 02:58:09 +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 since 0f2690eb75 in 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/
This commit is contained in:
parent
b4f1deb998
commit
4a8a88dd41
2 changed files with 31 additions and 2 deletions
|
|
@ -839,8 +839,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();
|
||||
|
|
|
|||
|
|
@ -248,4 +248,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