csl-editor icon indicating copy to clipboard operation
csl-editor copied to clipboard

Put xmlns attribute first

Open rmzelle opened this issue 8 years ago • 4 comments

I know that JavaScript object attributes officially don’t have an order, but I prefer to keep the xmlns attribute at the start of the style element, and this code works for me (in Chrome).

See https://github.com/citation-style-language/styles/commit/33ab94fe27856d8f14a8bcd0bbd02ca5a1ea389c#diff-6a52dc4de6b126dc7e28e0902fe7f752 for an example of where we reorder this attribute with my Python script.

I got it to work by deep-cloning the object (http://stackoverflow.com/a/4591639/1712389), deleting all attributes except xmlns (http://stackoverflow.com/questions/19316857/removing-all-properties-from-a-object), and then repopulating the object with the deleted attributes.

rmzelle avatar Feb 05 '17 19:02 rmzelle

To test, load a repository style in the Visual Editor from disk, change the value of "default-locale" under Global Formatting Options, and switch to the Code Editor. With this PR, "xmlns" no longer gets appended to the end of the attribute list on <style/>.

rmzelle avatar Feb 05 '17 19:02 rmzelle

And if this can be simplified, I'm all ears. (for comparison, I put the "rel" attribute on <link/> elements last via a similar approach in the Python script at https://github.com/citation-style-language/utilities/blob/d6bc1f23f560c1d92d8b5772dece7aba37c6bb55/csl-reindenting-and-info-reordering.py#L122)

rmzelle avatar Feb 05 '17 19:02 rmzelle

I've seen this, and while I haven't tested it I'm convinced it will work, but am worried about performance. How often does this run? Only on save and switching to the code editor?

adam3smith avatar Jul 04 '17 12:07 adam3smith

The inner workings of the editor are a bit of a mystery to me, but I doubt performance is a concern here. The new code itself is rather light-weight, and I'm pretty sure it doesn't run often. processNodeProperties is only called within Schema.js in a schema initialization routine (https://github.com/citation-style-language/csl-editor/search?utf8=%E2%9C%93&q=processNodeProperties&type=).

rmzelle avatar Jul 04 '17 14:07 rmzelle