As already noted on the Zotero forums, the modified version of
Scaffold for Zotero 2.0 (
http://bitbucket.org/rmzelle/scaffold/)
doesn't indent the JSON metadata when writing the translator to file.
I traced the issue to the Zotero.Translators.save function, where
nsIJSON is used to encode the metadata (
https://www.zotero.org/trac/
browser/extension/trunk/chrome/content/zotero/xpcom/translate.js?
rev=5895#L181). Apparently nsIJSON doesn't indent JSON: one-line JSON
strings can also be found in translators pushed to Zotero clients via
auto-update (you can check this for the recently updated NCBI
PubMed.js translator: the copy in the SVN repository has indented
JSON, while the copy in my local Zotero folder has a one-line JSON
string).
Firefox 3.5.4 introduced JSON.stringify(), which has indentation
support (via the 'space' parameter, see
https://developer.mozilla.org/en/Using_native_JSON).
But using this function is problematic since Zotero 2.0.2 is
compatible with Firefox 3.0, right?
What would be the best thing to do here? Maybe we could add an
optional boolean parameter to the Zotero.Translators.save function,
'embeddedMetadata'? Then Scaffold could use JSON.stringify() to
convert the 'metadata' JavaScript object to an indented JSON string
(requiring Firefox 3.5.4 for Scaffold 2.0 obviously wouldn't be a
problem), prepend the indented string to the 'code' string, and
deliver the 'metadata' JavaScript object and 'code' string (with
embedded metadata JSON string) to Zotero.Translators.save, e.g. via
Zotero.Translators.save(metadata, code, "true"). With a value of
"true", Zotero.Translators.save should then skip the internal JSON
encoding of the metadata object with nsIJSON.
Rintze
--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To post to this group, send email to
zoter...@googlegroups.com.
To unsubscribe from this group, send email to
zotero-dev+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/zotero-dev?hl=en.