Skip to content

Put xmlns attribute first#208

Open
rmzelle wants to merge 1 commit intomasterfrom
reorder-xmlns
Open

Put xmlns attribute first#208
rmzelle wants to merge 1 commit intomasterfrom
reorder-xmlns

Conversation

@rmzelle
Copy link
Copy Markdown
Member

@rmzelle rmzelle commented Feb 5, 2017

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 citation-style-language/styles@33ab94f#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
Copy link
Copy Markdown
Member Author

rmzelle commented Feb 5, 2017

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
Copy link
Copy Markdown
Member Author

rmzelle commented Feb 5, 2017

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)

@adam3smith
Copy link
Copy Markdown
Member

adam3smith commented Jul 4, 2017

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?

@rmzelle
Copy link
Copy Markdown
Member Author

rmzelle commented Jul 4, 2017

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=).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants